Skip to content

Commit

Permalink
Add args to alejandra hook
Browse files Browse the repository at this point in the history
  • Loading branch information
totoroot committed Sep 10, 2023
1 parent 7e3517c commit 44117e5
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,48 @@ in
};
alejandra =
{
check =
mkOption {
type = types.bool;
description = lib.mdDoc "Check if the input is already formatted and disable writing in-place the modified content";
default = false;
example = true;
};
exclude =
mkOption {
type = types.listOf types.str;
description = lib.mdDoc "Files or directories to exclude from formatting.";
default = [ ];
example = [ "flake.nix" "./templates" ];
};
package =
mkOption {
type = types.package;
description = lib.mdDoc "The `alejandra` package to use.";
default = "${tools.alejandra}";
example = "pkgs.alejandra";
};
quiet =
mkOption {
type = types.bool;
description = lib.mdDoc "Hide informational messages.";
default = false;
example = true;
};
silent =
mkOption {
type = types.bool;
description = lib.mdDoc "Hide error messages.";
default = false;
example = true;
};
threads =
mkOption {
type = types.nullOr types.int;
description = lib.mdDoc "Number of formatting threads to spawn.";
default = null;
example = 8;
};
};
deadnix =
{
Expand Down Expand Up @@ -955,8 +990,18 @@ in
{
name = "alejandra";
description = "The Uncompromising Nix Code Formatter.";
entry = with settings.alejandra;
"${tools.alejandra}/bin/alejandra ${if (exclude != [ ]) then "-e ${lib.escapeShellArgs (lib.unique exclude)}" else ""}";
entry =
let
cmdArgs =
mkCmdArgs (with settings.alejandra; [
[ check " --check" ]
[ (exclude != [ ]) " --exclude ${lib.escapeShellArgs (lib.unique exclude)}" ]
[ (quiet && ! silent) " --quiet" ]
[ silent " -qq" ]
[ (threads != null) " --threads ${toString threads}" ]
]);
in
"${settings.alejandra.package}/bin/alejandra${cmdArgs}";
files = "\\.nix$";
};

Expand Down

0 comments on commit 44117e5

Please sign in to comment.