24 lines
788 B
Nix
24 lines
788 B
Nix
{ pkgs, nix_templater }:
|
|
{
|
|
# placeholder to be substituted with the content of a secret file
|
|
fileContents = file: {
|
|
outPath = "<${builtins.placeholder "nix_template"}${toString file}${builtins.placeholder "nix_template"}>";
|
|
file = file;
|
|
};
|
|
|
|
# make a template with placeholders
|
|
template_text = { name, text, outPath }:
|
|
pkgs.runCommand name {
|
|
textBeforeTemplate = text;
|
|
script = ''
|
|
#!/bin/sh
|
|
${nix_templater}/bin/nix_templater ${builtins.placeholder "out"}/template ${builtins.placeholder "nix_template"} "${outPath}"
|
|
'';
|
|
passAsFile = [ "script" "textBeforeTemplate" ];
|
|
} ''
|
|
mkdir -p $out/bin
|
|
cp $textBeforeTemplatePath $out/template
|
|
cp $scriptPath $out/bin/${name}
|
|
chmod +x $out/bin/${name}
|
|
'';
|
|
}
|