wip: templates
This commit is contained in:
parent
a30d051fdb
commit
38de3be241
2 changed files with 26 additions and 0 deletions
|
@ -60,6 +60,15 @@ let
|
|||
echo "All secrets for ${gen.name} are present"
|
||||
elif [ $all_files_missing = true ] ; then
|
||||
|
||||
# templates
|
||||
templates=$(mktemp -d)
|
||||
trap 'rm -rf $templates' EXIT
|
||||
export templates
|
||||
mkdir -p "$templates"
|
||||
${lib.concatMapStringsSep "\n" (file: ''
|
||||
cp "${file.template}" "$templates/${file.name}"
|
||||
'') (lib.filter (file: file.template != null) (lib.attrValues gen.files))}
|
||||
|
||||
# prompts
|
||||
prompts=$(mktemp -d)
|
||||
trap 'rm -rf $prompts' EXIT
|
||||
|
|
17
options.nix
17
options.nix
|
@ -119,6 +119,21 @@
|
|||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
placeholder = lib.mkOption {
|
||||
description = ''
|
||||
A placeholder that may be used to safely reference the variable in a template.
|
||||
'';
|
||||
readOnly = true;
|
||||
default = "<VARS:${builtins.hashString "sha256" "${generator.config.name}:${file.config.name}"}:PLACEHOLDER>";
|
||||
};
|
||||
template = lib.mkOption {
|
||||
description = ''
|
||||
A template file with placeholders from the generator's dependencies.
|
||||
These will be substituted.
|
||||
'';
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
})
|
||||
);
|
||||
|
@ -185,6 +200,8 @@
|
|||
- $in: The directory containing the output values of all declared dependencies
|
||||
- $out: The output directory to put the generated files
|
||||
- $prompts: The directory containing the prompted values as files
|
||||
- $templates: The template files, with placeholders - to be replaced in the script like
|
||||
cat $templates/foo | sed "s/''${config.vars.generators.bar.files.baz.placeholder}/$(cat "$in/bar/baz")/g" > "$out/foo"
|
||||
The script should produce the files specified in the 'files' attribute under $out.
|
||||
'';
|
||||
type = lib.types.either lib.types.str lib.types.path;
|
||||
|
|
Loading…
Add table
Reference in a new issue