From f7650ba3fc53869b39914daf2f83037fab9e47b5 Mon Sep 17 00:00:00 2001 From: NAHO <90870942+trueNAHO@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:57:34 +0200 Subject: [PATCH] latexindent: add hooks.latexindent.settings.disableExtraFiles option Add the hooks.latexindent.settings.disableExtraFiles option to prevent the creation of backup and log files. Upstream refuses adding an option to disable backup and log file creation to protect non-version-controlled users from data loss, despite it being considered unnecessary for those using version control. [1] [2] [3] Considering that Git is the standard in Nix and required for flakes, providing this option is reasonable. [1]: https://github.com/cmhughes/latexindent.pl/issues/145 [2]: https://github.com/cmhughes/latexindent.pl/issues/333 [3]: https://github.com/cmhughes/latexindent.pl/pull/354 Link: https://github.com/cachix/git-hooks.nix/pull/514 --- modules/hooks.nix | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/modules/hooks.nix b/modules/hooks.nix index b71c789a..2e1b4d1c 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -636,6 +636,13 @@ in type = types.submodule { imports = [ hookModule ]; options.settings = { + disableExtraFiles = + mkEnableOption + (throw "initial description should never be evaluated") + // { + description = "Whether to disable the creation of backup and log files."; + }; + 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`."; @@ -2773,21 +2780,41 @@ 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 ${ - lib.cli.toGNUCommandLineShell {} ( - { - local = true; - overwriteIfDifferent = true; - silent = true; - } - // hooks.latexindent.settings.extraConfig - ) + entry = "${pkgs.runtimeShell} -c ${ + lib.escapeShellArg '' + ${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 =