Skip to content

Commit

Permalink
fix #356: provide a way to access all packages for enabled hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Mar 20, 2024
1 parent 6184635 commit cf361f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Given the following `flake.nix` example:
};
devShell = nixpkgs.legacyPackages.${system}.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
buildInputs = self.checks.${system}.pre-commit-check.enabledPackages;
};
}
);
Expand Down Expand Up @@ -108,10 +109,13 @@ nix develop
3. Integrate hooks to prepare environment as part of `shell.nix`:

```nix
(import <nixpkgs> {}).mkShell {
shellHook = ''
${(import ./default.nix).pre-commit-check.shellHook}
let
pre-commit = import ./default.nix;
in (import <nixpkgs> {}).mkShell {
shellHook = ''
${pre-commit.pre-commit-check.shellHook}
'';
buildInputs = pre-commit.pre-commit-check.enabledPackages;
}
```

Expand Down
12 changes: 12 additions & 0 deletions modules/pre-commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ in
lib.literalExpression or literalExample ''pre-commit-hooks.nix-pkgs.callPackage tools-dot-nix { inherit (pkgs) system; }'';
};

enabledPackages = mkOption {
type = types.list;
description = lib.mdDoc
''
All packages provided by hooks that are enabled.
Useful for including into the developer environment.
'';

default = builtins.map (hook: hook.package) (lib.filter (hook: hook.enable) (builtins.attrValues config.hooks));
};

hooks =
mkOption {
type = types.submodule {
Expand Down

0 comments on commit cf361f5

Please sign in to comment.