Skip to content

Commit 2ac4dcb

Browse files
authored
Merge pull request #430 from 9999years/extra-packages
Add `extraPackages` to each hook and propagate them to `enabledPackages`
2 parents 6ebeece + bc5491d commit 2ac4dcb

File tree

3 files changed

+112
-74
lines changed

3 files changed

+112
-74
lines changed

modules/hook.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ in
5353
'';
5454
};
5555

56+
extraPackages = mkOption {
57+
type = types.listOf types.package;
58+
default = [ ];
59+
description = lib.mdDoc
60+
''
61+
Additional packages required to run the hook.
62+
63+
These are propagated to `enabledPackages` for constructing developer
64+
environments.
65+
'';
66+
};
67+
5668
entry = mkOption {
5769
type = types.str;
5870
description = lib.mdDoc

modules/hooks.nix

Lines changed: 92 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -171,36 +171,42 @@ in
171171
};
172172
clippy = mkOption {
173173
description = lib.mdDoc "clippy hook";
174-
type = types.submodule {
175-
imports = [ hookModule ];
176-
options.packageOverrides = {
177-
cargo = mkOption {
178-
type = types.package;
179-
description = lib.mdDoc "The cargo package to use";
180-
};
181-
clippy = mkOption {
182-
type = types.package;
183-
description = lib.mdDoc "The clippy package to use";
184-
};
185-
};
186-
options.settings = {
187-
denyWarnings = mkOption {
188-
type = types.bool;
189-
description = lib.mdDoc "Fail when warnings are present";
190-
default = false;
191-
};
192-
offline = mkOption {
193-
type = types.bool;
194-
description = lib.mdDoc "Run clippy offline";
195-
default = true;
174+
type = types.submodule
175+
({ config, ... }: {
176+
imports = [ hookModule ];
177+
options.packageOverrides = {
178+
cargo = mkOption {
179+
type = types.package;
180+
description = lib.mdDoc "The cargo package to use";
181+
};
182+
clippy = mkOption {
183+
type = types.package;
184+
description = lib.mdDoc "The clippy package to use";
185+
};
196186
};
197-
allFeatures = mkOption {
198-
type = types.bool;
199-
description = lib.mdDoc "Run clippy with --all-features";
200-
default = false;
187+
options.settings = {
188+
denyWarnings = mkOption {
189+
type = types.bool;
190+
description = lib.mdDoc "Fail when warnings are present";
191+
default = false;
192+
};
193+
offline = mkOption {
194+
type = types.bool;
195+
description = lib.mdDoc "Run clippy offline";
196+
default = true;
197+
};
198+
allFeatures = mkOption {
199+
type = types.bool;
200+
description = lib.mdDoc "Run clippy with --all-features";
201+
default = false;
202+
};
201203
};
202-
};
203-
};
204+
205+
config.extraPackages = [
206+
config.packageOverrides.cargo
207+
config.packageOverrides.clippy
208+
];
209+
});
204210
};
205211
cmake-format = mkOption {
206212
description = lib.mdDoc "cmake-format hook";
@@ -333,24 +339,27 @@ in
333339
};
334340
dune-fmt = mkOption {
335341
description = lib.mdDoc "dune-fmt hook";
336-
type = types.submodule {
337-
imports = [ hookModule ];
338-
options.settings = {
339-
auto-promote =
340-
mkOption {
341-
type = types.bool;
342-
description = lib.mdDoc "Whether to auto-promote the changes.";
343-
default = true;
344-
};
342+
type = types.submodule
343+
({ config, ... }: {
344+
imports = [ hookModule ];
345+
options.settings = {
346+
auto-promote =
347+
mkOption {
348+
type = types.bool;
349+
description = lib.mdDoc "Whether to auto-promote the changes.";
350+
default = true;
351+
};
352+
353+
extraRuntimeInputs =
354+
mkOption {
355+
type = types.listOf types.package;
356+
description = lib.mdDoc "Extra runtimeInputs to add to the environment, eg. `ocamlformat`.";
357+
default = [ ];
358+
};
359+
};
345360

346-
extraRuntimeInputs =
347-
mkOption {
348-
type = types.listOf types.package;
349-
description = lib.mdDoc "Extra runtimeInputs to add to the environment, eg. `ocamlformat`.";
350-
default = [ ];
351-
};
352-
};
353-
};
361+
config.extraPackages = config.settings.extraRuntimeInputs;
362+
});
354363
};
355364
eclint = mkOption {
356365
description = lib.mdDoc "eclint hook";
@@ -1324,19 +1333,25 @@ in
13241333
hooks.rustfmt.packageOverrides.rustfmt = pkgs.rustfmt;
13251334
```
13261335
'';
1327-
type = types.submodule {
1328-
imports = [ hookModule ];
1329-
options.packageOverrides = {
1330-
cargo = mkOption {
1331-
type = types.package;
1332-
description = lib.mdDoc "The cargo package to use.";
1333-
};
1334-
rustfmt = mkOption {
1335-
type = types.package;
1336-
description = lib.mdDoc "The rustfmt package to use.";
1336+
type = types.submodule
1337+
({ config, ... }: {
1338+
imports = [ hookModule ];
1339+
options.packageOverrides = {
1340+
cargo = mkOption {
1341+
type = types.package;
1342+
description = lib.mdDoc "The cargo package to use.";
1343+
};
1344+
rustfmt = mkOption {
1345+
type = types.package;
1346+
description = lib.mdDoc "The rustfmt package to use.";
1347+
};
13371348
};
1338-
};
1339-
};
1349+
1350+
config.extraPackages = [
1351+
config.packageOverrides.cargo
1352+
config.packageOverrides.rustfmt
1353+
];
1354+
});
13401355
};
13411356
statix = mkOption {
13421357
description = lib.mdDoc "statix hook";
@@ -1399,22 +1414,26 @@ in
13991414
hooks.treefmt.packageOverrides.treefmt = pkgs.treefmt;
14001415
```
14011416
'';
1402-
type = types.submodule {
1403-
imports = [ hookModule ];
1404-
options.packageOverrides = {
1405-
treefmt = mkOption {
1406-
type = types.package;
1407-
description = lib.mdDoc "The treefmt package to use";
1408-
};
1409-
};
1410-
options.settings = {
1411-
formatters = mkOption {
1412-
type = types.listOf types.package;
1413-
description = lib.mdDoc "The formatter packages configured by treefmt";
1414-
default = [ ];
1415-
};
1416-
};
1417-
};
1417+
type = types.submodule
1418+
({ config, ... }:
1419+
{
1420+
imports = [ hookModule ];
1421+
options.packageOverrides = {
1422+
treefmt = mkOption {
1423+
type = types.package;
1424+
description = lib.mdDoc "The treefmt package to use";
1425+
};
1426+
};
1427+
options.settings = {
1428+
formatters = mkOption {
1429+
type = types.listOf types.package;
1430+
description = lib.mdDoc "The formatter packages configured by treefmt";
1431+
default = [ ];
1432+
};
1433+
};
1434+
1435+
config.extraPackages = config.settings.formatters;
1436+
});
14181437
};
14191438
typos = mkOption {
14201439
description = lib.mdDoc "typos hook";

modules/pre-commit.nix

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ in
138138
Useful for including into the developer environment.
139139
'';
140140

141-
default = builtins.map (hook: hook.package) (lib.filter (hook: hook.enable && hook.package != null) (builtins.attrValues config.hooks));
141+
default = lib.pipe config.hooks [
142+
builtins.attrValues
143+
(lib.filter (hook: hook.enable))
144+
(builtins.concatMap (hook:
145+
(lib.optional (hook.package != null) hook.package)
146+
++ hook.extraPackages
147+
))
148+
];
142149
};
143150

144151
hooks =

0 commit comments

Comments
 (0)