From 1484798032e690c2f8e89ab90bd53b7144874fa7 Mon Sep 17 00:00:00 2001 From: NAHO <90870942+trueNAHO@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:39:26 +0200 Subject: [PATCH 1/3] latexindent: add hooks.latexindent.settings.extraConfig option Replace the hooks.latexindent.settings.flags option with hooks.latexindent.settings.extraConfig to support arbitrary upstream flags and allow users to override default values. Link: https://github.com/cachix/git-hooks.nix/pull/514 --- modules/hooks.nix | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/hooks.nix b/modules/hooks.nix index 63bcc1cb..aaf861eb 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -2,7 +2,7 @@ let inherit (config) hooks tools settings; cfg = config; - inherit (lib) flatten mapAttrs mapAttrsToList mkDefault mkOption mkRemovedOptionModule mkRenamedOptionModule types; + inherit (lib) flatten mapAttrs mapAttrsToList mkDefault mkEnableOption mkOption mkRemovedOptionModule mkRenamedOptionModule types; cargoManifestPathArg = lib.optionalString @@ -683,12 +683,17 @@ 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"; - }; + 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: ' '"; + } + ''; + }; }; }; }; @@ -2904,7 +2909,17 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol 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 = "${hooks.latexindent.package}/bin/latexindent ${ + lib.cli.toGNUCommandLineShell {} ( + { + local = true; + overwriteIfDifferent = true; + silent = true; + } + // hooks.latexindent.settings.extraConfig + ) + }"; }; lacheck = let From 750711be14163e647af083a476e486fb11cbd707 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 2/3] 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 | 51 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/modules/hooks.nix b/modules/hooks.nix index aaf861eb..7ea135d1 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -683,6 +683,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`."; @@ -2904,22 +2911,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 ${ - lib.cli.toGNUCommandLineShell {} ( - { - local = true; - overwriteIfDifferent = true; - silent = true; - } - // hooks.latexindent.settings.extraConfig - ) - }"; + 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 From 6c76c500cda943fc89518ec030962b081eebba62 Mon Sep 17 00:00:00 2001 From: NAHO <90870942+trueNAHO@users.noreply.github.com> Date: Fri, 11 Oct 2024 20:42:53 +0200 Subject: [PATCH 3/3] latexindent: enable settings.disableExtraFiles option by default Enable the hooks.latexindent.settings.disableExtraFiles option by default, aligning with the community consensus that this should be the standard when using version control. Link: https://github.com/cachix/git-hooks.nix/pull/514 --- modules/hooks.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/hooks.nix b/modules/hooks.nix index 7ea135d1..fa793071 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -2,7 +2,7 @@ let inherit (config) hooks tools settings; cfg = config; - inherit (lib) flatten mapAttrs mapAttrsToList mkDefault mkEnableOption mkOption mkRemovedOptionModule mkRenamedOptionModule types; + inherit (lib) flatten mapAttrs mapAttrsToList mkDefault mkOption mkRemovedOptionModule mkRenamedOptionModule types; cargoManifestPathArg = lib.optionalString @@ -683,12 +683,12 @@ 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."; - }; + 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;