2023-09-13 21:16:56 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2023-08-28 09:09:05 +00:00
|
|
|
{
|
2023-09-06 14:08:36 +00:00
|
|
|
options.clanCore.secretStore = lib.mkOption {
|
|
|
|
type = lib.types.enum [ "sops" "password-store" "custom" ];
|
|
|
|
default = "sops";
|
|
|
|
description = ''
|
|
|
|
method to store secrets
|
2023-09-14 12:15:51 +00:00
|
|
|
custom can be used to define a custom secret store.
|
|
|
|
one would have to define system.clan.generateSecrets and system.clan.uploadSecrets
|
2023-09-06 14:08:36 +00:00
|
|
|
'';
|
|
|
|
};
|
2023-08-30 13:24:33 +00:00
|
|
|
options.clanCore.secrets = lib.mkOption {
|
2023-09-13 21:16:56 +00:00
|
|
|
default = { };
|
2023-08-28 09:09:05 +00:00
|
|
|
type = lib.types.attrsOf
|
|
|
|
(lib.types.submodule (secret: {
|
|
|
|
options = {
|
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = secret.config._module.args.name;
|
|
|
|
description = ''
|
2023-09-19 19:48:39 +00:00
|
|
|
Namespace of the secret
|
2023-08-28 09:09:05 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
generator = lib.mkOption {
|
2023-09-19 19:48:39 +00:00
|
|
|
type = lib.types.str;
|
2023-08-28 09:09:05 +00:00
|
|
|
description = ''
|
2023-09-19 19:48:39 +00:00
|
|
|
Script to generate the secret.
|
|
|
|
The script will be called with the following variables:
|
|
|
|
- facts: path to a directory where facts can be stored
|
|
|
|
- secrets: path to a directory where secrets can be stored
|
|
|
|
The script is expected to generate all secrets and facts defined in the module.
|
2023-08-28 09:09:05 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
secrets = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf (lib.types.submodule (secret: {
|
|
|
|
options = {
|
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
name of the secret
|
|
|
|
'';
|
|
|
|
default = secret.config._module.args.name;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
description = ''
|
|
|
|
path where the secret is located in the filesystem
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
facts = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf (lib.types.submodule (fact: {
|
|
|
|
options = {
|
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
name of the fact
|
|
|
|
'';
|
|
|
|
default = fact.config._module.args.name;
|
|
|
|
};
|
|
|
|
path = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
path to a fact which is generated by the generator
|
|
|
|
'';
|
2023-09-14 13:22:13 +00:00
|
|
|
default = "machines/${config.clanCore.machineName}/facts/${fact.config._module.args.name}";
|
2023-08-28 09:09:05 +00:00
|
|
|
};
|
|
|
|
value = lib.mkOption {
|
2023-09-19 09:29:59 +00:00
|
|
|
defaultText = lib.literalExpression "\${config.clanCore.clanDir}/\${fact.config.path}";
|
2023-09-19 19:48:39 +00:00
|
|
|
default =
|
|
|
|
if builtins.pathExists "${config.clanCore.clanDir}/${fact.config.path}" then
|
|
|
|
builtins.readFile "${config.clanCore.clanDir}/${fact.config.path}"
|
|
|
|
else
|
|
|
|
"";
|
2023-08-28 09:09:05 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
};
|
2023-09-14 11:49:20 +00:00
|
|
|
config.system.build.generateUploadSecrets = pkgs.writeScript "generate_upload_secrets" ''
|
|
|
|
${config.system.clan.generateSecrets}
|
|
|
|
${config.system.clan.uploadSecrets}
|
2023-09-13 21:16:56 +00:00
|
|
|
'';
|
2023-08-28 09:09:05 +00:00
|
|
|
imports = [
|
2023-09-06 14:09:43 +00:00
|
|
|
./sops.nix
|
|
|
|
./password-store.nix
|
2023-08-28 09:09:05 +00:00
|
|
|
];
|
|
|
|
}
|