Skip to content

Commit cf361f5

Browse files
committed
fix #356: provide a way to access all packages for enabled hooks
1 parent 6184635 commit cf361f5

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Given the following `flake.nix` example:
4444
};
4545
devShell = nixpkgs.legacyPackages.${system}.mkShell {
4646
inherit (self.checks.${system}.pre-commit-check) shellHook;
47+
buildInputs = self.checks.${system}.pre-commit-check.enabledPackages;
4748
};
4849
}
4950
);
@@ -108,10 +109,13 @@ nix develop
108109
3. Integrate hooks to prepare environment as part of `shell.nix`:
109110

110111
```nix
111-
(import <nixpkgs> {}).mkShell {
112-
shellHook = ''
113-
${(import ./default.nix).pre-commit-check.shellHook}
112+
let
113+
pre-commit = import ./default.nix;
114+
in (import <nixpkgs> {}).mkShell {
115+
shellHook = ''
116+
${pre-commit.pre-commit-check.shellHook}
114117
'';
118+
buildInputs = pre-commit.pre-commit-check.enabledPackages;
115119
}
116120
```
117121

modules/pre-commit.nix

+12
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ in
131131
lib.literalExpression or literalExample ''pre-commit-hooks.nix-pkgs.callPackage tools-dot-nix { inherit (pkgs) system; }'';
132132
};
133133

134+
enabledPackages = mkOption {
135+
type = types.list;
136+
description = lib.mdDoc
137+
''
138+
All packages provided by hooks that are enabled.
139+
140+
Useful for including into the developer environment.
141+
'';
142+
143+
default = builtins.map (hook: hook.package) (lib.filter (hook: hook.enable) (builtins.attrValues config.hooks));
144+
};
145+
134146
hooks =
135147
mkOption {
136148
type = types.submodule {

0 commit comments

Comments
 (0)