Skip to content

Commit

Permalink
Add extraPackages option for packages propagated to enabledPackages
Browse files Browse the repository at this point in the history
This lets additional runtime packages like formatters for `treefmt` be
propagated to `enabledPackages` for use in a developer environment.
  • Loading branch information
9999years committed Apr 12, 2024
1 parent 40e6053 commit dc1ffda
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
12 changes: 12 additions & 0 deletions modules/hook.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ in
'';
};

extraPackages = mkOption {
type = types.listOf types.package;
default = [ ];
description = lib.mdDoc
''
Additional packages required to run the hook.
These are propagated to `enabledPackages` for constructing developer
environments.
'';
};

entry = mkOption {
type = types.str;
description = lib.mdDoc
Expand Down
36 changes: 20 additions & 16 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1399,22 +1399,26 @@ in
hooks.treefmt.packageOverrides.treefmt = pkgs.treefmt;
```
'';
type = types.submodule {
imports = [ hookModule ];
options.packageOverrides = {
treefmt = mkOption {
type = types.package;
description = lib.mdDoc "The treefmt package to use";
};
};
options.settings = {
formatters = mkOption {
type = types.listOf types.package;
description = lib.mdDoc "The formatter packages configured by treefmt";
default = [ ];
};
};
};
type = types.submodule
({ config, ... }:
{
imports = [ hookModule ];
options.packageOverrides = {
treefmt = mkOption {
type = types.package;
description = lib.mdDoc "The treefmt package to use";
};
};
options.settings = {
formatters = mkOption {
type = types.listOf types.package;
description = lib.mdDoc "The formatter packages configured by treefmt";
default = [ ];
};
};

config.extraPackages = config.settings.formatters;
});
};
typos = mkOption {
description = lib.mdDoc "typos hook";
Expand Down
9 changes: 8 additions & 1 deletion modules/pre-commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,14 @@ in
Useful for including into the developer environment.
'';

default = builtins.map (hook: hook.package) (lib.filter (hook: hook.enable && hook.package != null) (builtins.attrValues config.hooks));
default = lib.pipe config.hooks [
builtins.attrValues
(lib.filter (hook: hook.enable))
(builtins.concatMap (hook:
(lib.optional (hook.package != null) hook.package)
++ hook.extraPackages
))
];
};

hooks =
Expand Down

0 comments on commit dc1ffda

Please sign in to comment.