From 7dca34cf42b2edc9ee34f1228d7cd7fbf9d88f98 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 47dbaae3..db9fea6c 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 @@ -631,12 +631,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: ' '"; + } + ''; + }; }; }; }; @@ -2768,7 +2773,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 0593b68e5e627e4e761d39c11bca4f7db6bdd4bf 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 db9fea6c..a1b46550 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -631,6 +631,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`."; @@ -2768,22 +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 ${ - 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 31e108faff7bdb5956092b891839d25a2e969424 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 a1b46550..c08f0059 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 @@ -631,12 +631,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;