feat: add package to exclude gitignored hooks

tools like renovate can run soonix:update after updating stuff, but the
gitignored hooks cannot be committed anyways, so why bother building
them
This commit is contained in:
technofab 2026-01-01 15:56:25 +01:00
parent 56f281eea4
commit 87399d28fe
Signed by: technofab
SSH key fingerprint: SHA256:bV4h88OqS/AxjbPn66uUdvK9JsgIW4tv3vwJQ8tpMqQ
2 changed files with 116 additions and 78 deletions

View file

@ -153,9 +153,17 @@ in {
config = let config = let
hooks = config.hooks; hooks = config.hooks;
hookNames = builtins.attrNames hooks; # allow excluding gitignore since stuff like renovate can't use/commit it anyways
getHookNames = {includeGitignored ? true}:
if includeGitignored
then (builtins.attrNames hooks)
else
map
(hook: hook.name)
(builtins.filter (hook: !hook.hook.gitignore) (builtins.attrValues hooks));
runHooks = concatMapStringsSep "\n" (hookName: let runHooks = args:
concatMapStringsSep "\n" (hookName: let
hook = hooks.${hookName}; hook = hooks.${hookName};
modes = { modes = {
link = link =
@ -193,6 +201,7 @@ in {
'' ''
else ""; else "";
in in
builtins.addErrorContext "[soonix] while generating script for ${hookName}"
# sh # sh
'' ''
# Process hook: ${hookName} # Process hook: ${hookName}
@ -227,9 +236,10 @@ in {
_soonix_failed+=("${hookName}") _soonix_failed+=("${hookName}")
} }
'') '')
hookNames; (getHookNames args);
generatedShellHook = generateShellHook = args:
builtins.addErrorContext "[soonix] while generating shell hook"
# sh # sh
'' ''
_soonix_log() { _soonix_log() {
@ -265,7 +275,7 @@ in {
_soonix_failed=() _soonix_failed=()
_soonix_uptodate=() _soonix_uptodate=()
${runHooks} ${runHooks args}
local output=$'\E[msoonix:\E[38;5;8m' local output=$'\E[msoonix:\E[38;5;8m'
local status=0 local status=0
@ -297,8 +307,8 @@ in {
in rec { in rec {
# nothing to do if no hooks exist # nothing to do if no hooks exist
shellHook = shellHook =
if (builtins.length hookNames > 0) if (builtins.length (builtins.attrNames config.hooks) > 0)
then generatedShellHook then generateShellHook {}
else ""; else "";
shellHookFile = pkgs.writeShellScript "shellHook" shellHook; shellHookFile = pkgs.writeShellScript "shellHook" shellHook;
devshellModule = { devshellModule = {
@ -307,11 +317,17 @@ in {
}; };
finalFiles = buildAllFiles allFiles; finalFiles = buildAllFiles allFiles;
# make it simpler to update the hooks without any devshell # make it simpler to update the hooks without any devshell
packages."soonix:update" = pkgs.writeShellScriptBin "soonix:update" '' packages = let
mkPackage = args:
pkgs.writeShellScriptBin "soonix:update" ''
function _soonix() { function _soonix() {
${shellHook} ${generateShellHook args}
} }
_soonix _soonix
''; '';
in {
"soonix:update" = mkPackage {};
"soonix:update:excludegitignore" = mkPackage {includeGitignored = false;};
};
}; };
} }

View file

@ -69,6 +69,28 @@ in {
assert_file_contains ${shellHook} "gomplate" assert_file_contains ${shellHook} "gomplate"
''; '';
} }
{
name = "packages";
type = "script";
script = let
conf = (soonix.make {inherit hooks;}).config;
baseBin = conf.packages."soonix:update" + "/bin/soonix:update";
exclBin = conf.packages."soonix:update:excludegitignore" + "/bin/soonix:update";
in
# sh
''
${ntlib.helpers.path [pkgs.gnugrep]}
${ntlib.helpers.scriptHelpers}
assert -f "${baseBin}" "should exist"
assert -f "${exclBin}" "should exist"
assert_file_contains "${baseBin}" "gotmpl"
assert_file_contains "${baseBin}" "test.json"
assert_file_not_contains "${exclBin}" "gotmpl"
assert_file_contains "${exclBin}" "test.json"
'';
}
]; ];
}; };
} }