diff --git a/modules/hooks.nix b/modules/hooks.nix index 08ad9ae3..b1eb9c86 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -80,6 +80,13 @@ 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; @@ -87,6 +94,34 @@ in 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 = { @@ -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$"; };