Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ in
Nixpkgs to use in the pre-commit [`settings`](#opt-perSystem.pre-commit.settings).
'';
default = pkgs;
defaultText = lib.literalMD "`pkgs` (module argument)";
defaultText = lib.literalExpression "`pkgs` (module argument)";
};
settings = mkOption {
type = types.submoduleWith {
Expand All @@ -49,16 +49,23 @@ in
The git-hooks.nix configuration.
'';
};
shellHook = mkOption {
type = types.str;
description = "A shell hook that installs up the git hooks in a development shell.";
default = cfg.settings.installationScript;
defaultText = lib.literalExpression "bash statements";
readOnly = true;
};
installationScript = mkOption {
type = types.str;
description = "A bash fragment that sets up [pre-commit](https://pre-commit.com/).";
description = "A bash snippet that sets up the git hooks in the current repository.";
default = cfg.settings.installationScript;
defaultText = lib.literalMD "bash statements";
defaultText = lib.literalExpression "bash statements";
readOnly = true;
};
devShell = mkOption {
type = types.package;
description = "A development shell with pre-commit installed and setup.";
description = "A development shell with the git hooks installed and all the packages made available.";
readOnly = true;
};
};
Expand All @@ -72,8 +79,8 @@ in
hooks.treefmt.package = lib.mkIf (options?treefmt) (lib.mkOverride 900 config.treefmt.build.wrapper);
};
pre-commit.devShell = pkgs.mkShell {
nativeBuildInputs = cfg.settings.enabledPackages ++ [ cfg.settings.package ];
shellHook = cfg.installationScript;
inherit (cfg.settings) shellHook;
nativeBuildInputs = cfg.settings.enabledPackages;
};
};
});
Expand Down
2 changes: 1 addition & 1 deletion modules/hook.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ in
name = mkOption {
type = types.str;
default = name;
defaultText = lib.literalMD "the attribute name the hook submodule is bound to, same as `id`";
defaultText = lib.literalExpression "the attribute name the hook submodule is bound to, same as `id`";
description =
''
The name of the hook. Shown during hook execution.
Expand Down
20 changes: 19 additions & 1 deletion modules/pre-commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,24 @@ in
defaultText = lib.literalExpression "<derivation>";
};

shellHook =
mkOption {
type = types.str;
description =
''
A shell hook that sets up the git hooks in a development shell.

Pass to `mkShell` as `shellHook` to use.
'';
readOnly = true;
};

installationScript =
mkOption {
type = types.str;
description =
''
A bash snippet that installs nix-pre-commit-hooks in the current directory
A bash snippet that installs the git hooks in the current repository.
'';
readOnly = true;
};
Expand Down Expand Up @@ -439,6 +451,12 @@ in
default_stages = cfg.default_stages;
};

shellHook =
''
${config.installationScript}
export PATH=${config.package}/bin:$PATH
'';

installationScript =
''
if ${boolToString cfg.install.enable}; then
Expand Down
4 changes: 1 addition & 3 deletions nix/run.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ let
}
] ++ imports;
};
inherit (project.config) installationScript;

in
project.config.run // {
inherit (project) config;
inherit (project.config) enabledPackages;
shellHook = installationScript;
inherit (project.config) enabledPackages shellHook;
}
2 changes: 1 addition & 1 deletion template/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# NOTE: You can also use `config.pre-commit.devShell`
devShells.default = pkgs.mkShell {
shellHook = ''
${config.pre-commit.installationScript}
${config.pre-commit.shellHook}
echo 1>&2 "Welcome to the development shell!"
'';

Expand Down