Chore: init settings submdule, move clanDir into settings submodule

This commit is contained in:
Johannes Kirschbauer
2024-12-31 14:08:25 +01:00
parent f823336cba
commit 315be52e34
31 changed files with 111 additions and 75 deletions

View File

@@ -140,12 +140,12 @@
path to a fact which is generated by the generator
'';
default =
config.clan.core.clanDir
config.clan.core.settings.directory
+ "/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}";
defaultText = lib.literalExpression "\${config.clan.core.settings.directory}/machines/\${config.clan.core.machineName}/facts/\${fact.config._module.args.name}";
};
value = lib.mkOption {
defaultText = lib.literalExpression "\${config.clan.core.clanDir}/\${fact.config.path}";
defaultText = lib.literalExpression "\${config.clan.core.settings.directory}/\${fact.config.path}";
type = lib.types.nullOr lib.types.str;
default =
if builtins.pathExists fact.config.path then lib.strings.fileContents fact.config.path else null;

View File

@@ -219,15 +219,16 @@
description = ''
path to a fact which is generated by the generator
'';
defaultText = lib.literalExpression "\${config.clan.core.clanDir}/machines/\${config.clan.core.machineName}/facts/\${fact.config.name}";
defaultText = lib.literalExpression "\${config.clan.core.settings.directory}/machines/\${config.clan.core.machineName}/facts/\${fact.config.name}";
default =
config.clan.core.clanDir + "/machines/${config.clan.core.machineName}/facts/${fact.config.name}";
config.clan.core.settings.directory
+ "/machines/${config.clan.core.machineName}/facts/${fact.config.name}";
};
value = lib.mkOption {
description = ''
The value of the public fact.
'';
defaultText = lib.literalExpression "\${config.clan.core.clanDir}/\${fact.config.path}";
defaultText = lib.literalExpression "\${config.clan.core.settings.directory}/\${fact.config.path}";
type = lib.types.nullOr lib.types.str;
default =
if builtins.pathExists fact.config.path then lib.strings.fileContents fact.config.path else null;

View File

@@ -5,8 +5,8 @@
...
}:
let
secretsDir = config.clan.core.clanDir + "/sops/secrets";
groupsDir = config.clan.core.clanDir + "/sops/groups";
secretsDir = config.clan.core.settings.directory + "/sops/secrets";
groupsDir = config.clan.core.settings.directory + "/sops/groups";
# My symlink is in the nixos module detected as a directory also it works in the repl. Is this because of pure evaluation?
containsSymlink =
@@ -42,7 +42,7 @@ in
clan.core.facts.secretModule = "clan_cli.facts.secret_modules.sops";
clan.core.facts.secretUploadDirectory = lib.mkDefault "/var/lib/sops-nix";
sops.secrets = builtins.mapAttrs (name: _: {
sopsFile = config.clan.core.clanDir + "/sops/secrets/${name}/secret";
sopsFile = config.clan.core.settings.directory + "/sops/secrets/${name}/secret";
format = "binary";
}) secrets;
# To get proper error messages about missing secrets we need a dummy secret file that is always present
@@ -51,7 +51,7 @@ in
);
sops.age.keyFile = lib.mkIf (builtins.pathExists (
config.clan.core.clanDir + "/sops/secrets/${config.clan.core.machineName}-age.key/secret"
config.clan.core.settings.directory + "/sops/secrets/${config.clan.core.machineName}-age.key/secret"
)) (lib.mkDefault "/var/lib/sops-nix/key.txt");
};
}

View File

@@ -1,4 +1,7 @@
{ lib, pkgs, ... }:
let
inherit (lib) mkOption types;
in
{
imports = [
(lib.mkRemovedOptionModule [
@@ -11,8 +14,41 @@
"core"
"clanIcon"
] "clanIcon has been removed. Use clan.core.icon instead.")
(lib.mkRenamedOptionModule
[ "clan" "core" "clanDir" ]
[
"clan"
"core"
"settings"
"directory"
]
)
];
options.clan.core = {
settings = mkOption {
description = ''
Settings of the clan.
This is a read-only attribute-set available to the machines of the clan.
'';
type = types.submodule {
options = {
directory = lib.mkOption {
type = lib.types.path;
# documentation.nixos.extraModules = [
# ...
# clan-core.nixosModules.clanCore
# { clan.core.settings.directory = ./path/to/flake; }
# ];
description = ''
the location of the flake repo, used to calculate the location of facts and secrets
'';
};
};
};
};
name = lib.mkOption {
type = lib.types.str;
description = ''
@@ -43,17 +79,6 @@
the description of the machine
'';
};
clanDir = lib.mkOption {
type = lib.types.path;
# documentation.nixos.extraModules = [
# ...
# clan-core.nixosModules.clanCore
# { clan.core.clanDir = ./path/to/flake; }
# ];
description = ''
the location of the flake repo, used to calculate the location of facts and secrets
'';
};
machineName = lib.mkOption {
type = lib.types.str;
default = "nixos";

View File

@@ -1,6 +1,6 @@
{ lib, config, ... }:
let
directory = config.clan.core.clanDir;
directory = config.clan.core.settings.directory;
inherit (config.clan.core) machineName;
facterJson = "${directory}/machines/${machineName}/facter.json";
hwConfig = "${directory}/machines/${machineName}/hardware-configuration.nix";

View File

@@ -13,10 +13,13 @@ in
fileModule = file: {
path = mkIf (file.config.secret == false) (
if file.config.share then
(config.clan.core.clanDir + "/vars/shared/${file.config.generatorName}/${file.config.name}/value")
(
config.clan.core.settings.directory
+ "/vars/shared/${file.config.generatorName}/${file.config.name}/value"
)
else
(
config.clan.core.clanDir
config.clan.core.settings.directory
+ "/vars/per-machine/${config.clan.core.machineName}/${file.config.generatorName}/${file.config.name}/value"
)
);

View File

@@ -15,9 +15,9 @@ let
secretPath =
secret:
if secret.share then
config.clan.core.clanDir + "/vars/shared/${secret.generator}/${secret.name}/secret"
config.clan.core.settings.directory + "/vars/shared/${secret.generator}/${secret.name}/secret"
else
config.clan.core.clanDir
config.clan.core.settings.directory
+ "/vars/per-machine/${machineName}/${secret.generator}/${secret.name}/secret";
vars = collectFiles config.clan.core.vars;
@@ -53,7 +53,7 @@ in
lib.mkDefault (builtins.toString (pkgs.writeText "dummy.yaml" ""))
);
age.keyFile = lib.mkIf (builtins.pathExists (
config.clan.core.clanDir + "/sops/secrets/${machineName}-age.key/secret"
config.clan.core.settings.directory + "/sops/secrets/${machineName}-age.key/secret"
)) (lib.mkDefault "/var/lib/sops-nix/key.txt");
};
}