2024-07-02 09:36:31 +00:00
|
|
|
{ lib, pkgs, ... }:
|
2024-06-27 14:09:42 +00:00
|
|
|
let
|
|
|
|
eval =
|
|
|
|
module:
|
|
|
|
(lib.evalModules {
|
|
|
|
modules = [
|
2024-07-02 06:55:00 +00:00
|
|
|
../interface.nix
|
2024-06-27 14:09:42 +00:00
|
|
|
module
|
|
|
|
];
|
2024-07-02 09:36:31 +00:00
|
|
|
specialArgs.pkgs = pkgs;
|
2024-06-27 14:09:42 +00:00
|
|
|
}).config;
|
2024-07-02 08:38:24 +00:00
|
|
|
|
|
|
|
usage_simple = {
|
|
|
|
generators.my_secret = {
|
|
|
|
files.password = { };
|
|
|
|
files.username.secret = false;
|
|
|
|
prompts.prompt1 = { };
|
|
|
|
script = ''
|
|
|
|
cp $prompts/prompt1 $files/password
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2024-06-27 14:09:42 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
single_file_single_prompt =
|
|
|
|
let
|
2024-07-02 08:38:24 +00:00
|
|
|
config = eval usage_simple;
|
2024-06-27 14:09:42 +00:00
|
|
|
in
|
|
|
|
{
|
2024-07-02 08:38:24 +00:00
|
|
|
# files are always secret by default
|
2024-06-27 14:09:42 +00:00
|
|
|
test_file_secret_by_default = {
|
2024-07-02 06:55:00 +00:00
|
|
|
expr = config.generators.my_secret.files.password.secret;
|
2024-06-27 14:09:42 +00:00
|
|
|
expected = true;
|
|
|
|
};
|
2024-07-02 08:38:24 +00:00
|
|
|
# secret files must not provide a value
|
2024-06-27 14:09:42 +00:00
|
|
|
test_secret_value_access_raises_error = {
|
2024-07-02 06:55:00 +00:00
|
|
|
expr = config.generators.my_secret.files.password.value;
|
2024-06-27 14:09:42 +00:00
|
|
|
expectedError.type = "ThrownError";
|
|
|
|
expectedError.msg = "Cannot access value of secret file";
|
|
|
|
};
|
2024-07-02 08:38:24 +00:00
|
|
|
# public values must provide a value at eval time
|
2024-06-27 14:09:42 +00:00
|
|
|
test_public_value_access = {
|
2024-07-02 06:55:00 +00:00
|
|
|
expr = config.generators.my_secret.files.username ? value;
|
2024-06-27 14:09:42 +00:00
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
# both secret and public values must provide a path
|
|
|
|
test_secret_has_path = {
|
2024-07-02 06:55:00 +00:00
|
|
|
expr = config.generators.my_secret.files.password ? path;
|
2024-06-27 14:09:42 +00:00
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
test_public_var_has_path = {
|
2024-07-02 06:55:00 +00:00
|
|
|
expr = config.generators.my_secret.files.username ? path;
|
2024-06-27 14:09:42 +00:00
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
};
|
2024-07-02 08:38:24 +00:00
|
|
|
|
|
|
|
# Ensure that generators.imports works
|
|
|
|
# This allows importing generators from third party projects without providing
|
|
|
|
# them access to other settings.
|
|
|
|
test_generator_modules =
|
|
|
|
let
|
|
|
|
generator_module = {
|
|
|
|
my-generator.files.password = { };
|
|
|
|
};
|
|
|
|
config = eval { generators.imports = [ generator_module ]; };
|
|
|
|
in
|
|
|
|
{
|
2024-07-02 09:36:31 +00:00
|
|
|
expr = config.generators ? my-generator;
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
# script can be text
|
|
|
|
test_script_text =
|
|
|
|
let
|
|
|
|
config = eval {
|
|
|
|
# imports = [ usage_simple ];
|
|
|
|
generators.my_secret.script = ''
|
|
|
|
echo "Hello, world!"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
expr = config.generators.my_secret.script;
|
|
|
|
expected = "echo \"Hello, world!\"\n";
|
|
|
|
};
|
|
|
|
|
|
|
|
# script can be a derivation
|
|
|
|
test_script_writer =
|
|
|
|
let
|
|
|
|
config = eval {
|
|
|
|
# imports = [ usage_simple ];
|
|
|
|
generators.my_secret.script = derivation {
|
|
|
|
system = pkgs.system;
|
|
|
|
name = "my-script";
|
|
|
|
builder = "/bin/sh";
|
|
|
|
args = [
|
|
|
|
"-c"
|
|
|
|
''touch $out''
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
expr = lib.hasPrefix builtins.storeDir config.generators.my_secret.script;
|
2024-07-02 08:38:24 +00:00
|
|
|
expected = true;
|
|
|
|
};
|
2024-06-27 14:09:42 +00:00
|
|
|
}
|