diff --git a/flake-module.nix b/flake-module.nix index b4861df3..cb2e6cf9 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -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 { @@ -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; }; }; @@ -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; }; }; }); diff --git a/modules/hook.nix b/modules/hook.nix index 297a7cfc..45c52772 100644 --- a/modules/hook.nix +++ b/modules/hook.nix @@ -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. diff --git a/modules/pre-commit.nix b/modules/pre-commit.nix index d5ecc7be..99087d86 100644 --- a/modules/pre-commit.nix +++ b/modules/pre-commit.nix @@ -282,12 +282,24 @@ in defaultText = lib.literalExpression ""; }; + 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; }; @@ -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 diff --git a/nix/run.nix b/nix/run.nix index cb7990a5..53a0c5f5 100644 --- a/nix/run.nix +++ b/nix/run.nix @@ -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; } diff --git a/template/flake.nix b/template/flake.nix index 02080d66..274b4313 100644 --- a/template/flake.nix +++ b/template/flake.nix @@ -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!" '';