clan-core/nixosModules/clanCore/facts/compat.nix

174 lines
6.0 KiB
Nix
Raw Normal View History

{ config, lib, ... }:
2024-03-17 18:48:49 +00:00
{
imports = [
(lib.mkRemovedOptionModule [
2024-06-17 10:42:28 +00:00
"clan"
"core"
"secretsPrefix"
] "secretsPrefix was only used by the sops module and the code is now integrated in there")
(lib.mkRenamedOptionModule
[
2024-06-17 10:42:28 +00:00
"clan"
"core"
"secretStore"
]
[
2024-06-17 10:42:28 +00:00
"clan"
"core"
"facts"
"secretStore"
]
)
(lib.mkRemovedOptionModule [
2024-06-17 10:42:28 +00:00
"clan"
"core"
"secretsDirectory"
2024-06-17 10:42:28 +00:00
] "clan.core.secretsDirectory was removed. Use clan.core.facts.secretPathFunction instead")
(lib.mkRenamedOptionModule
[
2024-06-17 10:42:28 +00:00
"clan"
"core"
"secretsUploadDirectory"
]
[
2024-06-17 10:42:28 +00:00
"clan"
"core"
"facts"
"secretUploadDirectory"
]
)
];
2024-06-17 10:42:28 +00:00
options.clan.core.secrets = lib.mkOption {
visible = false;
default = { };
2024-03-17 18:48:49 +00:00
type = lib.types.attrsOf (
lib.types.submodule (service: {
options = {
name = lib.mkOption {
type = lib.types.str;
default = service.config._module.args.name;
description = ''
Namespace of the service
'';
};
generator = lib.mkOption {
2024-03-17 18:48:49 +00:00
type = lib.types.submodule (
{ ... }:
2024-03-17 18:48:49 +00:00
{
options = {
path = lib.mkOption {
type = lib.types.listOf (lib.types.either lib.types.path lib.types.package);
default = [ ];
description = ''
Extra paths to add to the PATH environment variable when running the generator.
'';
};
prompt = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
prompt text to ask for a value.
This value will be passed to the script as the environment variable $prompt_value.
'';
};
script = lib.mkOption {
type = lib.types.str;
description = ''
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.
'';
};
};
2024-03-17 18:48:49 +00:00
}
);
};
secrets = lib.mkOption {
default = { };
type = lib.types.attrsOf (
lib.types.submodule (secret: {
options =
2024-03-17 18:48:49 +00:00
{
name = lib.mkOption {
type = lib.types.str;
description = ''
name of the secret
'';
2024-04-12 11:23:52 +00:00
default = secret.config._module.args.name;
};
path = lib.mkOption {
type = lib.types.path;
description = ''
path to a secret which is generated by the generator
'';
2024-06-17 10:42:28 +00:00
default = config.clan.core.facts.secretPathFunction secret;
defaultText = lib.literalExpression "config.clan.core.facts.secretPathFunction secret";
};
2024-03-17 18:48:49 +00:00
}
2024-06-17 10:42:28 +00:00
// lib.optionalAttrs (config.clan.core.facts.secretStore == "sops") {
groups = lib.mkOption {
type = lib.types.listOf lib.types.str;
2024-06-17 10:42:28 +00:00
default = config.clan.core.sops.defaultGroups;
description = ''
Groups to decrypt the secret for. By default we always use the user's key.
'';
};
};
})
);
description = ''
path where the secret is located in the filesystem
'';
};
2024-03-17 18:48:49 +00:00
facts = lib.mkOption {
default = { };
type = lib.types.attrsOf (
lib.types.submodule (fact: {
options = {
name = lib.mkOption {
type = lib.types.str;
description = ''
2024-03-17 18:48:49 +00:00
name of the fact
'';
2024-03-17 18:48:49 +00:00
default = fact.config._module.args.name;
};
path = lib.mkOption {
2024-03-17 18:48:49 +00:00
type = lib.types.path;
description = ''
2024-03-17 18:48:49 +00:00
path to a fact which is generated by the generator
'';
2024-03-17 18:48:49 +00:00
default =
2024-06-17 10:42:28 +00:00
config.clan.core.clanDir
+ "/machines/${config.clan.core.machineName}/facts/${fact.config._module.args.name}";
defaultText = lib.literalExpression "\${config.clan.core.clanDir}/machines/\${config.clan.core.machineName}/facts/\${fact.config._module.args.name}";
};
2024-03-17 18:48:49 +00:00
value = lib.mkOption {
2024-06-17 10:42:28 +00:00
defaultText = lib.literalExpression "\${config.clan.core.clanDir}/\${fact.config.path}";
2024-03-17 18:48:49 +00:00
type = lib.types.nullOr lib.types.str;
default =
if builtins.pathExists fact.config.path then lib.strings.fileContents fact.config.path else null;
};
};
2024-03-17 18:48:49 +00:00
})
);
};
};
2024-03-17 18:48:49 +00:00
})
);
};
2024-06-17 10:42:28 +00:00
config = lib.mkIf (config.clan.core.secrets != { }) {
clan.core.facts.services = lib.mapAttrs' (
name: service:
2024-06-17 10:42:28 +00:00
lib.warn "clan.core.secrets.${name} is deprecated, use clan.core.facts.services.${name} instead" (
lib.nameValuePair name ({
secret = service.secrets;
public = service.facts;
generator = service.generator;
})
)
2024-06-17 10:42:28 +00:00
) config.clan.core.secrets;
};
}