Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extraPackages to each hook and propagate them to enabledPackages #430

Merged
merged 3 commits into from
Apr 22, 2024
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
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
165 changes: 92 additions & 73 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -171,36 +171,42 @@ in
};
clippy = mkOption {
description = lib.mdDoc "clippy hook";
type = types.submodule {
imports = [ hookModule ];
options.packageOverrides = {
cargo = mkOption {
type = types.package;
description = lib.mdDoc "The cargo package to use";
};
clippy = mkOption {
type = types.package;
description = lib.mdDoc "The clippy package to use";
};
};
options.settings = {
denyWarnings = mkOption {
type = types.bool;
description = lib.mdDoc "Fail when warnings are present";
default = false;
};
offline = mkOption {
type = types.bool;
description = lib.mdDoc "Run clippy offline";
default = true;
type = types.submodule
({ config, ... }: {
imports = [ hookModule ];
options.packageOverrides = {
cargo = mkOption {
type = types.package;
description = lib.mdDoc "The cargo package to use";
};
clippy = mkOption {
type = types.package;
description = lib.mdDoc "The clippy package to use";
};
};
allFeatures = mkOption {
type = types.bool;
description = lib.mdDoc "Run clippy with --all-features";
default = false;
options.settings = {
denyWarnings = mkOption {
type = types.bool;
description = lib.mdDoc "Fail when warnings are present";
default = false;
};
offline = mkOption {
type = types.bool;
description = lib.mdDoc "Run clippy offline";
default = true;
};
allFeatures = mkOption {
type = types.bool;
description = lib.mdDoc "Run clippy with --all-features";
default = false;
};
};
};
};

config.extraPackages = [
config.packageOverrides.cargo
config.packageOverrides.clippy
];
});
};
cmake-format = mkOption {
description = lib.mdDoc "cmake-format hook";
Expand Down Expand Up @@ -333,24 +339,27 @@ in
};
dune-fmt = mkOption {
description = lib.mdDoc "dune-fmt hook";
type = types.submodule {
imports = [ hookModule ];
options.settings = {
auto-promote =
mkOption {
type = types.bool;
description = lib.mdDoc "Whether to auto-promote the changes.";
default = true;
};
type = types.submodule
({ config, ... }: {
imports = [ hookModule ];
options.settings = {
auto-promote =
mkOption {
type = types.bool;
description = lib.mdDoc "Whether to auto-promote the changes.";
default = true;
};

extraRuntimeInputs =
mkOption {
type = types.listOf types.package;
description = lib.mdDoc "Extra runtimeInputs to add to the environment, eg. `ocamlformat`.";
default = [ ];
};
};

extraRuntimeInputs =
mkOption {
type = types.listOf types.package;
description = lib.mdDoc "Extra runtimeInputs to add to the environment, eg. `ocamlformat`.";
default = [ ];
};
};
};
config.extraPackages = config.settings.extraRuntimeInputs;
});
};
eclint = mkOption {
description = lib.mdDoc "eclint hook";
Expand Down Expand Up @@ -1324,19 +1333,25 @@ in
hooks.rustfmt.packageOverrides.rustfmt = pkgs.rustfmt;
```
'';
type = types.submodule {
imports = [ hookModule ];
options.packageOverrides = {
cargo = mkOption {
type = types.package;
description = lib.mdDoc "The cargo package to use.";
};
rustfmt = mkOption {
type = types.package;
description = lib.mdDoc "The rustfmt package to use.";
type = types.submodule
({ config, ... }: {
imports = [ hookModule ];
options.packageOverrides = {
cargo = mkOption {
type = types.package;
description = lib.mdDoc "The cargo package to use.";
};
rustfmt = mkOption {
type = types.package;
description = lib.mdDoc "The rustfmt package to use.";
};
};
};
};

config.extraPackages = [
config.packageOverrides.cargo
config.packageOverrides.rustfmt
];
});
};
statix = mkOption {
description = lib.mdDoc "statix hook";
Expand Down Expand Up @@ -1399,22 +1414,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
Loading