diff --git a/modules/hooks.nix b/modules/hooks.nix index 47dbaae3..c08f0059 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -631,12 +631,24 @@ in type = types.submodule { imports = [ hookModule ]; options.settings = { - flags = - mkOption { - type = types.str; - description = "Flags passed to latexindent. See available flags [here](https://latexindentpl.readthedocs.io/en/latest/sec-how-to-use.html#from-the-command-line)"; - default = "--local --silent --overwriteIfDifferent"; - }; + disableExtraFiles = mkOption { + default = true; + example = false; + description = "Whether to disable the creation of backup and log files."; + type = types.bool; + }; + + extraConfig = mkOption { + type = types.attrs; + description = "[latexindent command-line options](https://latexindentpl.readthedocs.io/en/latest/sec-how-to-use.html#from-the-command-line) converted through `lib.cli.toGNUCommandLine`."; + default = { }; + + example = lib.literalExpression '' + { + yaml = "defaultIndent: ' '"; + } + ''; + }; }; }; }; @@ -2763,12 +2775,46 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol ''; }; latexindent = + let + hook = hooks.latexindent; + in { name = "latexindent"; description = "Perl script to add indentation to LaTeX files."; types = [ "file" "tex" ]; package = tools.latexindent; - entry = "${hooks.latexindent.package}/bin/latexindent ${hooks.latexindent.settings.flags}"; + + entry = lib.getExe ( + pkgs.writeShellApplication { + name = "git-hooks-nix-hooks-latexindent-entry"; + + text = '' + ${hook.package}/bin/latexindent ${ + lib.optionalString + hook.settings.disableExtraFiles + ''--cruft "$(mktemp --directory)"'' + } ${ + lib.cli.toGNUCommandLineShell {} ( + lib.mergeAttrsList [ + { + local = true; + silent = true; + } + + ( + lib.optionalAttrs hook.settings.disableExtraFiles { + logfile = toString /dev/null; + overwriteIfDifferent = true; + } + ) + + hook.settings.extraConfig + ] + ) + } "$@" + ''; + } + ); }; lacheck = let