Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
38de3be241 | |||
a30d051fdb |
2 changed files with 53 additions and 7 deletions
|
@ -46,6 +46,12 @@ let
|
|||
fi
|
||||
'') (lib.attrValues gen.files)}
|
||||
|
||||
# outputs
|
||||
out=$(mktemp -d)
|
||||
trap 'rm -rf $out' EXIT
|
||||
export out
|
||||
mkdir -p "$out"
|
||||
|
||||
if [ $all_files_missing = false ] && [ $all_files_present = false ] ; then
|
||||
echo "Inconsistent state for generator: ${gen.name}"
|
||||
exit 1
|
||||
|
@ -54,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
|
||||
|
@ -80,12 +95,6 @@ let
|
|||
'') (lib.attrValues config.vars.generators.${input}.files)}
|
||||
'') gen.dependencies}
|
||||
|
||||
# outputs
|
||||
out=$(mktemp -d)
|
||||
trap 'rm -rf $out' EXIT
|
||||
export out
|
||||
mkdir -p "$out"
|
||||
|
||||
(
|
||||
# prepare PATH
|
||||
unset PATH
|
||||
|
@ -112,8 +121,15 @@ let
|
|||
mkdir -p "$(dirname "$OUT_FILE")"
|
||||
mv "$out"/${file.name} "$OUT_FILE"
|
||||
'') (lib.attrValues gen.files)}
|
||||
rm -rf "$out"
|
||||
fi
|
||||
|
||||
# move the files to the correct location
|
||||
${lib.concatMapStringsSep "\n" (file: ''
|
||||
OUT_FILE="$OUT_DIR"/${if file.secret then "secret" else "public"}/${file.generator}/${file.name}
|
||||
chown ${file.owner}:${file.group} "''${OUT_FILE}"
|
||||
chmod ${file.mode} "''${OUT_FILE}"
|
||||
'') (lib.attrValues gen.files)}
|
||||
rm -rf "$out"
|
||||
'') sortedGenerators}
|
||||
'';
|
||||
};
|
||||
|
|
30
options.nix
30
options.nix
|
@ -82,6 +82,19 @@
|
|||
default = generator.config.name;
|
||||
defaultText = "Name of the generator";
|
||||
};
|
||||
owner = lib.mkOption {
|
||||
description = "The user name or id that will own the file.";
|
||||
default = "root";
|
||||
};
|
||||
group = lib.mkOption {
|
||||
description = "The group name or id that will own the file.";
|
||||
default = "root";
|
||||
};
|
||||
mode = lib.mkOption {
|
||||
type = lib.types.strMatching "^[0-7]{4}$";
|
||||
description = "The unix file mode of the file. Must be a 4-digit octal number.";
|
||||
default = "0400";
|
||||
};
|
||||
deploy = lib.mkOption {
|
||||
description = ''
|
||||
Whether the file should be deployed to the target machine.
|
||||
|
@ -106,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;
|
||||
};
|
||||
};
|
||||
})
|
||||
);
|
||||
|
@ -172,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