From 9c5e683ff90ff6488b881d8df076d20aa05607b7 Mon Sep 17 00:00:00 2001 From: cinereal Date: Mon, 11 Aug 2025 15:21:46 +0200 Subject: [PATCH] set rights on templateFromFile --- lib.nix | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib.nix b/lib.nix index 2293207..d2137ca 100644 --- a/lib.nix +++ b/lib.nix @@ -22,7 +22,7 @@ rec { text, outPath, owner ? "root", - group ? "", + group ? owner, mode ? "0400", translations ? {}, }: @@ -31,24 +31,34 @@ rec { script = '' #!/bin/sh ${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" ]; } '' mkdir -p $out/bin cp $textBeforeTemplatePath $out/template cp $scriptPath $out/bin/${name} - chown ${owner}:${group} $out/bin/${name} - chmod ${mode} $out/bin/${name} chmod +x $out/bin/${name} ''; # 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 { inherit templateFile; script = '' #!/bin/sh ${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" ]; } ''