vars: new option prompts.<name>.createFile
This commit is contained in:
@@ -4,13 +4,32 @@
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib)
|
||||
attrNames
|
||||
concatMapStrings
|
||||
genAttrs
|
||||
filterAttrs
|
||||
makeBinPath
|
||||
mkOptionDefault
|
||||
optionalString
|
||||
;
|
||||
|
||||
promptToFile = name: ''
|
||||
cat "$prompts/${name}" > "$out/${name}"
|
||||
'';
|
||||
|
||||
promptsToFilesScript = concatMapStrings promptToFile;
|
||||
|
||||
filePromptNames = attrNames (filterAttrs (_name: prompt: prompt.createFile) config.prompts);
|
||||
in
|
||||
{
|
||||
finalScript = lib.mkOptionDefault ''
|
||||
finalScript = mkOptionDefault ''
|
||||
set -eu -o pipefail
|
||||
|
||||
export PATH="${lib.makeBinPath config.runtimeInputs}:${pkgs.coreutils}/bin"
|
||||
export PATH="${makeBinPath config.runtimeInputs}:${pkgs.coreutils}/bin"
|
||||
|
||||
${lib.optionalString (pkgs.stdenv.hostPlatform.isLinux) ''
|
||||
${optionalString (pkgs.stdenv.hostPlatform.isLinux) ''
|
||||
# prepare sandbox user on platforms where this is supported
|
||||
mkdir -p /etc
|
||||
|
||||
@@ -31,6 +50,9 @@
|
||||
::1 localhost
|
||||
EOF
|
||||
''}
|
||||
${promptsToFilesScript filePromptNames}
|
||||
${config.script}
|
||||
'';
|
||||
|
||||
files = genAttrs filePromptNames (_name: { });
|
||||
}
|
||||
|
||||
@@ -120,6 +120,21 @@ in
|
||||
type = attrsOf (
|
||||
submodule (prompt: {
|
||||
options = options {
|
||||
createFile = {
|
||||
description = ''
|
||||
Whether the prompted value should be stored in a file with the same name as the prompt.
|
||||
|
||||
If enabled, the behavior is equivalent to the following configuration:
|
||||
```nix
|
||||
{
|
||||
files.<name>.secret = true;
|
||||
script = "cp $prompts/<name> $out/<name>";
|
||||
}
|
||||
```
|
||||
'';
|
||||
type = bool;
|
||||
default = true;
|
||||
};
|
||||
description = {
|
||||
description = ''
|
||||
The description of the prompted value
|
||||
@@ -165,6 +180,7 @@ in
|
||||
The script should produce the files specified in the 'files' attribute under $out.
|
||||
'';
|
||||
type = either str path;
|
||||
default = "";
|
||||
};
|
||||
finalScript = {
|
||||
description = ''
|
||||
|
||||
Reference in New Issue
Block a user