Skip to content

Commit

Permalink
latexindent: add hooks.latexindent.settings.disableExtraFiles option
Browse files Browse the repository at this point in the history
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]: cmhughes/latexindent.pl#145
[2]: cmhughes/latexindent.pl#333
[3]: cmhughes/latexindent.pl#354

Link: cachix#514
  • Loading branch information
trueNAHO committed Oct 12, 2024
1 parent 6c51b09 commit f7650ba
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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`.";
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit f7650ba

Please sign in to comment.