set rights on templateFromFile

This commit is contained in:
Kiara Grouwstra 2025-08-11 15:21:46 +02:00
parent 666bfcb7bc
commit 9c5e683ff9
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU

18
lib.nix
View file

@ -22,7 +22,7 @@ rec {
text, text,
outPath, outPath,
owner ? "root", owner ? "root",
group ? "", group ? owner,
mode ? "0400", mode ? "0400",
translations ? {}, translations ? {},
}: }:
@ -31,24 +31,34 @@ rec {
script = '' script = ''
#!/bin/sh #!/bin/sh
${nix_templater}/bin/nix_templater ${builtins.placeholder "out"}/template ${builtins.placeholder "nix_template"} "${outPath}" '${lib.strings.toJSON translations}' ${nix_templater}/bin/nix_templater ${builtins.placeholder "out"}/template ${builtins.placeholder "nix_template"} "${outPath}" '${lib.strings.toJSON translations}'
chown ${owner}:${group} "${outPath}"
chmod ${mode} "${outPath}"
''; '';
passAsFile = [ "script" "textBeforeTemplate" ]; passAsFile = [ "script" "textBeforeTemplate" ];
} '' } ''
mkdir -p $out/bin mkdir -p $out/bin
cp $textBeforeTemplatePath $out/template cp $textBeforeTemplatePath $out/template
cp $scriptPath $out/bin/${name} cp $scriptPath $out/bin/${name}
chown ${owner}:${group} $out/bin/${name}
chmod ${mode} $out/bin/${name}
chmod +x $out/bin/${name} chmod +x $out/bin/${name}
''; '';
# make a template with placeholders from a file # make a template with placeholders from a file
templateFromFile = { name, templateFile, outPath, translations ? {} }: templateFromFile = {
name,
templateFile,
outPath,
owner ? "root",
group ? owner,
mode ? "0400",
translations ? {},
}:
pkgs.runCommand name { pkgs.runCommand name {
inherit templateFile; inherit templateFile;
script = '' script = ''
#!/bin/sh #!/bin/sh
${nix_templater}/bin/nix_templater ${builtins.placeholder "out"}/template ${builtins.placeholder "nix_template"} "${outPath}" '${lib.strings.toJSON translations}' ${nix_templater}/bin/nix_templater ${builtins.placeholder "out"}/template ${builtins.placeholder "nix_template"} "${outPath}" '${lib.strings.toJSON translations}'
chown ${owner}:${group} "${outPath}"
chmod ${mode} "${outPath}"
''; '';
passAsFile = [ "script" ]; passAsFile = [ "script" ];
} '' } ''