Chore:_migrate 'machineName' to 'settings.machine.name'

This commit is contained in:
Johannes Kirschbauer
2024-12-31 14:54:40 +01:00
parent 95fa227780
commit 2c41e9f0c6
30 changed files with 84 additions and 60 deletions

View File

@@ -16,7 +16,7 @@
}; };
} }
{ {
clan.core.machineName = "machine"; clan.core.settings.machine.name = "machine";
clan.core.settings.directory = ./.; clan.core.settings.directory = ./.;
clan.core.state.testState.folders = [ "/etc/state" ]; clan.core.state.testState.folders = [ "/etc/state" ];
environment.etc.state.text = "hello world"; environment.etc.state.text = "hello world";

View File

@@ -10,7 +10,7 @@
self.clanModules.deltachat self.clanModules.deltachat
self.nixosModules.clanCore self.nixosModules.clanCore
{ {
clan.core.machineName = "machine"; clan.core.settings.machine.name = "machine";
clan.core.settings.directory = ./.; clan.core.settings.directory = ./.;
} }
]; ];

View File

@@ -15,7 +15,7 @@
self.clanModules.matrix-synapse self.clanModules.matrix-synapse
self.nixosModules.clanCore self.nixosModules.clanCore
{ {
clan.core.machineName = "machine"; clan.core.settings.machine.name = "machine";
clan.core.settings.directory = ./.; clan.core.settings.directory = ./.;
services.nginx.virtualHosts."matrix.clan.test" = { services.nginx.virtualHosts."matrix.clan.test" = {

View File

@@ -32,7 +32,7 @@
imports = [ imports = [
common common
{ {
clan.core.machineName = "peer1"; clan.core.settings.machine.name = "peer1";
environment.etc = { environment.etc = {
"mumble-key".source = ./peer_1/peer_1_test_key; "mumble-key".source = ./peer_1/peer_1_test_key;
"mumble-cert".source = ./peer_1/peer_1_test_cert; "mumble-cert".source = ./peer_1/peer_1_test_cert;
@@ -64,7 +64,7 @@
imports = [ imports = [
common common
{ {
clan.core.machineName = "peer2"; clan.core.settings.machine.name = "peer2";
environment.etc = { environment.etc = {
"mumble-key".source = ./peer_2/peer_2_test_key; "mumble-key".source = ./peer_2/peer_2_test_key;
"mumble-cert".source = ./peer_2/peer_2_test_cert; "mumble-cert".source = ./peer_2/peer_2_test_cert;

View File

@@ -11,7 +11,7 @@
sops.age.keyFile = "/etc/privkey.age"; sops.age.keyFile = "/etc/privkey.age";
clan.core.settings.directory = "${./.}"; clan.core.settings.directory = "${./.}";
clan.core.machineName = "machine"; clan.core.settings.machine.name = "machine";
networking.hostName = "machine"; networking.hostName = "machine";
}; };

View File

@@ -12,7 +12,7 @@
self.clanModules.syncthing self.clanModules.syncthing
self.nixosModules.clanCore self.nixosModules.clanCore
{ {
clan.core.machineName = "introducer"; clan.core.settings.machine.name = "introducer";
clan.core.settings.directory = ./.; clan.core.settings.directory = ./.;
environment.etc = { environment.etc = {
"syncthing.pam".source = ./introducer/introducer_test_cert; "syncthing.pam".source = ./introducer/introducer_test_cert;
@@ -53,7 +53,7 @@
self.clanModules.syncthing self.clanModules.syncthing
self.nixosModules.clanCore self.nixosModules.clanCore
{ {
clan.core.machineName = "peer1"; clan.core.settings.machine.name = "peer1";
clan.core.settings.directory = ./.; clan.core.settings.directory = ./.;
clan.syncthing.introducer = lib.strings.removeSuffix "\n" ( clan.syncthing.introducer = lib.strings.removeSuffix "\n" (
builtins.readFile ./introducer/introducer_device_id builtins.readFile ./introducer/introducer_device_id
@@ -75,7 +75,7 @@
self.clanModules.syncthing self.clanModules.syncthing
self.nixosModules.clanCore self.nixosModules.clanCore
{ {
clan.core.machineName = "peer2"; clan.core.settings.machine.name = "peer2";
clan.core.settings.directory = ./.; clan.core.settings.directory = ./.;
clan.syncthing.introducer = lib.strings.removeSuffix "\n" ( clan.syncthing.introducer = lib.strings.removeSuffix "\n" (
builtins.readFile ./introducer/introducer_device_id builtins.readFile ./introducer/introducer_device_id

View File

@@ -14,7 +14,7 @@ import ../lib/test-base.nix (
imports = [ imports = [
self.nixosModules.clanCore self.nixosModules.clanCore
{ {
clan.core.machineName = "machine"; clan.core.settings.machine.name = "machine";
clan.core.settings.directory = ./.; clan.core.settings.directory = ./.;
} }
]; ];

View File

@@ -10,7 +10,7 @@
self.nixosModules.clanCore self.nixosModules.clanCore
self.clanModules.zt-tcp-relay self.clanModules.zt-tcp-relay
{ {
clan.core.machineName = "machine"; clan.core.settings.machine.name = "machine";
clan.core.settings.directory = ./.; clan.core.settings.directory = ./.;
} }
]; ];

View File

@@ -9,7 +9,7 @@ in
options.clan.borgbackup-static = { options.clan.borgbackup-static = {
excludeMachines = lib.mkOption { excludeMachines = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
example = [ config.clan.core.machineName ]; example = [ config.clan.core.settings.machine.name ];
default = [ ]; default = [ ];
description = '' description = ''
Machines that should not be backuped. Machines that should not be backuped.
@@ -20,7 +20,7 @@ in
}; };
includeMachines = lib.mkOption { includeMachines = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
example = [ config.clan.core.machineName ]; example = [ config.clan.core.settings.machine.name ];
default = [ ]; default = [ ];
description = '' description = ''
Machines that should be backuped. Machines that should be backuped.
@@ -63,7 +63,7 @@ in
in in
lib.mkIf lib.mkIf
(builtins.any ( (builtins.any (
target: target == config.clan.core.machineName target: target == config.clan.core.settings.machine.name
) config.clan.borgbackup-static.targets) ) config.clan.borgbackup-static.targets)
(if (builtins.listToAttrs hosts) != null then builtins.listToAttrs hosts else { }); (if (builtins.listToAttrs hosts) != null then builtins.listToAttrs hosts else { });
@@ -72,12 +72,12 @@ in
destinations = builtins.map (d: { destinations = builtins.map (d: {
name = d; name = d;
value = { value = {
repo = "borg@${d}:/var/lib/borgbackup/${config.clan.core.machineName}"; repo = "borg@${d}:/var/lib/borgbackup/${config.clan.core.settings.machine.name}";
}; };
}) config.clan.borgbackup-static.targets; }) config.clan.borgbackup-static.targets;
in in
lib.mkIf (builtins.any ( lib.mkIf (builtins.any (
target: target == config.clan.core.machineName target: target == config.clan.core.settings.machine.name
) config.clan.borgbackup-static.includeMachines) (builtins.listToAttrs destinations); ) config.clan.borgbackup-static.includeMachines) (builtins.listToAttrs destinations);
config.assertions = [ config.assertions = [

View File

@@ -19,7 +19,7 @@ let
) )
) [ ] instances; ) [ ] instances;
inherit (config.clan.core) machineName; machineName = config.clan.core.settings.machine.name;
cfg = config.clan.borgbackup; cfg = config.clan.borgbackup;
preBackupScript = '' preBackupScript = ''

View File

@@ -2,7 +2,7 @@
let let
dir = config.clan.core.settings.directory; dir = config.clan.core.settings.directory;
machineDir = dir + "/machines/"; machineDir = dir + "/machines/";
inherit (config.clan.core) machineName; machineName = config.clan.core.settings.machine.name;
# Instances might be empty, if the module is not used via the inventory # Instances might be empty, if the module is not used via the inventory
# #

View File

@@ -5,7 +5,7 @@
services.maddy = services.maddy =
let let
domain = "${config.clan.core.machineName}.local"; domain = "${config.clan.core.settings.machine.name}.local";
in in
{ {
enable = true; enable = true;

View File

@@ -39,7 +39,7 @@ in
services.murmur = { services.murmur = {
enable = true; enable = true;
logDays = -1; logDays = -1;
registerName = config.clan.core.machineName; registerName = config.clan.core.settings.machine.name;
openFirewall = true; openFirewall = true;
bonjour = true; bonjour = true;
sslKey = "/var/lib/murmur/sslKey"; sslKey = "/var/lib/murmur/sslKey";
@@ -97,8 +97,8 @@ in
XDG_DATA_DIR=${mumbleCfgDir} XDG_DATA_DIR=${mumbleCfgDir}
${populate-channels} --ensure-config '${mumbleCfgPath}' --db-location ${mumbleDatabasePath} ${populate-channels} --ensure-config '${mumbleCfgPath}' --db-location ${mumbleDatabasePath}
echo ${machineCertJson} echo ${machineCertJson}
${populate-channels} --machines '${machineJson}' --username ${config.clan.core.machineName} --db-location ${mumbleDatabasePath} ${populate-channels} --machines '${machineJson}' --username ${config.clan.core.settings.machine.name} --db-location ${mumbleDatabasePath}
${populate-channels} --servers '${machineCertJson}' --username ${config.clan.core.machineName} --db-location ${mumbleDatabasePath} --cert True ${populate-channels} --servers '${machineCertJson}' --username ${config.clan.core.settings.machine.name} --db-location ${mumbleDatabasePath} --cert True
${pkgs.mumble}/bin/mumble --config ${mumbleCfgPath} "$@" ${pkgs.mumble}/bin/mumble --config ${mumbleCfgPath} "$@"
popd popd
''; '';

View File

@@ -9,7 +9,7 @@ pkgs.nixosTest {
self.inputs.clan-core.nixosModules.clanCore self.inputs.clan-core.nixosModules.clanCore
{ {
config = { config = {
clan.core.machineName = "peer1"; clan.core.settings.machine.name = "peer1";
clan.core.settings.directory = ./.; clan.core.settings.directory = ./.;
documentation.enable = false; documentation.enable = false;
@@ -26,7 +26,7 @@ pkgs.nixosTest {
{ {
config = { config = {
clan.core.machineName = "peer2"; clan.core.settings.machine.name = "peer2";
clan.core.settings.directory = ./.; clan.core.settings.directory = ./.;
documentation.enable = false; documentation.enable = false;

View File

@@ -10,7 +10,7 @@
config.clan.core.facts.services.root-password.secret.password-hash.path; config.clan.core.facts.services.root-password.secret.password-hash.path;
sops.secrets = lib.mkIf (config.clan.core.facts.secretStore == "sops") { sops.secrets = lib.mkIf (config.clan.core.facts.secretStore == "sops") {
"${config.clan.core.machineName}-password-hash".neededForUsers = true; "${config.clan.core.settings.machine.name}-password-hash".neededForUsers = true;
}; };
clan.core.facts.services.root-password = { clan.core.facts.services.root-password = {

View File

@@ -69,7 +69,7 @@ in
"openssh-ca" "openssh-ca"
]; ];
validation = { validation = {
name = config.clan.core.machineName; name = config.clan.core.settings.machine.name;
domains = lib.genAttrs config.clan.sshd.certificate.searchDomains lib.id; domains = lib.genAttrs config.clan.sshd.certificate.searchDomains lib.id;
}; };
runtimeInputs = [ runtimeInputs = [
@@ -79,9 +79,9 @@ in
script = '' script = ''
ssh-keygen \ ssh-keygen \
-s $in/openssh-ca/id_ed25519 \ -s $in/openssh-ca/id_ed25519 \
-I ${config.clan.core.machineName} \ -I ${config.clan.core.settings.machine.name} \
-h \ -h \
-n ${lib.concatMapStringsSep "," (d: "${config.clan.core.machineName}.${d}") domains} \ -n ${lib.concatMapStringsSep "," (d: "${config.clan.core.settings.machine.name}.${d}") domains} \
$in/openssh/ssh.id_ed25519.pub $in/openssh/ssh.id_ed25519.pub
mv $in/openssh/ssh.id_ed25519-cert.pub $out/ssh.id_ed25519-cert.pub mv $in/openssh/ssh.id_ed25519-cert.pub $out/ssh.id_ed25519-cert.pub
''; '';

View File

@@ -4,7 +4,10 @@
excludeHosts = lib.mkOption { excludeHosts = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
default = default =
if config.clan.static-hosts.topLevelDomain != "" then [ ] else [ config.clan.core.machineName ]; if config.clan.static-hosts.topLevelDomain != "" then
[ ]
else
[ config.clan.core.settings.machine.name ];
description = "Hosts that should be excluded"; description = "Hosts that should be excluded";
}; };
topLevelDomain = lib.mkOption { topLevelDomain = lib.mkOption {

View File

@@ -47,7 +47,7 @@ in
options.clan.syncthing-static-peers = { options.clan.syncthing-static-peers = {
excludeMachines = lib.mkOption { excludeMachines = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
example = [ config.clan.core.machineName ]; example = [ config.clan.core.settings.machine.name ];
default = [ ]; default = [ ];
description = '' description = ''
Machines that should not be added. Machines that should not be added.

View File

@@ -30,7 +30,7 @@ in
}; };
sops.secrets = lib.mkIf (config.clan.core.facts.secretStore == "sops") { sops.secrets = lib.mkIf (config.clan.core.facts.secretStore == "sops") {
"${config.clan.core.machineName}-user-password-hash".neededForUsers = true; "${config.clan.core.settings.machine.name}-user-password-hash".neededForUsers = true;
}; };
clan.core.facts.services.user-password = { clan.core.facts.services.user-password = {

View File

@@ -27,7 +27,7 @@ in
options.clan.zerotier-static-peers = { options.clan.zerotier-static-peers = {
excludeHosts = lib.mkOption { excludeHosts = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
default = [ config.clan.core.machineName ]; default = [ config.clan.core.settings.machine.name ];
description = "Hosts that should be excluded"; description = "Hosts that should be excluded";
}; };
networkIps = lib.mkOption { networkIps = lib.mkOption {

View File

@@ -34,7 +34,7 @@ in
{ {
excludeHosts = lib.mkOption { excludeHosts = lib.mkOption {
type = listOf str; type = listOf str;
default = [ config.clan.core.machineName ]; default = [ config.clan.core.settings.machine.name ];
description = "Hosts that should be excluded"; description = "Hosts that should be excluded";
}; };
networkIps = lib.mkOption { networkIps = lib.mkOption {
@@ -54,7 +54,7 @@ in
# TODO: This should also be checked via frontmatter constraints # TODO: This should also be checked via frontmatter constraints
{ {
assertion = builtins.length instanceNames == 1; assertion = builtins.length instanceNames == 1;
message = "The zerotier module currently only supports one instance per machine, but found ${builtins.toString instanceNames} on machine ${config.clan.core.machineName}"; message = "The zerotier module currently only supports one instance per machine, but found ${builtins.toString instanceNames} on machine ${config.clan.core.settings.machine.name}";
} }
]; ];

View File

@@ -82,6 +82,10 @@ let
# Settings # Settings
clan.core.settings = { clan.core.settings = {
inherit directory; inherit directory;
machine = {
inherit name;
};
}; };
# clan.core.settings.directory = directory; # clan.core.settings.directory = directory;
# Inherited from clan wide settings # Inherited from clan wide settings
@@ -90,7 +94,8 @@ let
clan.core.icon = config.inventory.meta.icon; clan.core.icon = config.inventory.meta.icon;
# Machine specific settings # Machine specific settings
clan.core.machineName = name; # clan.core.settings.machine.name = name;
networking.hostName = lib.mkDefault name; networking.hostName = lib.mkDefault name;
# speeds up nix commands by using the nixpkgs from the host system (especially useful in VMs) # speeds up nix commands by using the nixpkgs from the host system (especially useful in VMs)

View File

@@ -141,8 +141,8 @@
''; '';
default = default =
config.clan.core.settings.directory config.clan.core.settings.directory
+ "/machines/${config.clan.core.machineName}/facts/${fact.config._module.args.name}"; + "/machines/${config.clan.core.settings.machine.name}/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}"; defaultText = lib.literalExpression "\${config.clan.core.settings.directory}/machines/\${config.clan.core.settings.machine.name}/facts/\${fact.config._module.args.name}";
}; };
value = lib.mkOption { value = lib.mkOption {
defaultText = lib.literalExpression "\${config.clan.core.settings.directory}/\${fact.config.path}"; defaultText = lib.literalExpression "\${config.clan.core.settings.directory}/\${fact.config.path}";

View File

@@ -219,10 +219,10 @@
description = '' description = ''
path to a fact which is generated by the generator path to a fact which is generated by the generator
''; '';
defaultText = lib.literalExpression "\${config.clan.core.settings.directory}/machines/\${config.clan.core.machineName}/facts/\${fact.config.name}"; defaultText = lib.literalExpression "\${config.clan.core.settings.directory}/machines/\${config.clan.core.settings.machine.name}/facts/\${fact.config.name}";
default = default =
config.clan.core.settings.directory config.clan.core.settings.directory
+ "/machines/${config.clan.core.machineName}/facts/${fact.config.name}"; + "/machines/${config.clan.core.settings.machine.name}/facts/${fact.config.name}";
}; };
value = lib.mkOption { value = lib.mkOption {
description = '' description = ''

View File

@@ -16,7 +16,8 @@ let
containsMachine = containsMachine =
parent: name: type: parent: name: type:
type == "directory" && containsSymlink "${parent}/${name}/machines/${config.clan.core.machineName}"; type == "directory"
&& containsSymlink "${parent}/${name}/machines/${config.clan.core.settings.machine.name}";
containsMachineOrGroups = containsMachineOrGroups =
name: type: name: type:
@@ -37,7 +38,7 @@ in
# Before we generate a secret we cannot know the path yet, so we need to set it to an empty string # Before we generate a secret we cannot know the path yet, so we need to set it to an empty string
clan.core.facts.secretPathFunction = clan.core.facts.secretPathFunction =
secret: secret:
config.sops.secrets.${"${config.clan.core.machineName}-${secret.config.name}"}.path config.sops.secrets.${"${config.clan.core.settings.machine.name}-${secret.config.name}"}.path
or "/no-such-path"; or "/no-such-path";
clan.core.facts.secretModule = "clan_cli.facts.secret_modules.sops"; clan.core.facts.secretModule = "clan_cli.facts.secret_modules.sops";
clan.core.facts.secretUploadDirectory = lib.mkDefault "/var/lib/sops-nix"; clan.core.facts.secretUploadDirectory = lib.mkDefault "/var/lib/sops-nix";
@@ -51,7 +52,8 @@ in
); );
sops.age.keyFile = lib.mkIf (builtins.pathExists ( sops.age.keyFile = lib.mkIf (builtins.pathExists (
config.clan.core.settings.directory + "/sops/secrets/${config.clan.core.machineName}-age.key/secret" config.clan.core.settings.directory
+ "/sops/secrets/${config.clan.core.settings.machine.name}-age.key/secret"
)) (lib.mkDefault "/var/lib/sops-nix/key.txt"); )) (lib.mkDefault "/var/lib/sops-nix/key.txt");
}; };
} }

View File

@@ -15,6 +15,7 @@ in
"clanIcon" "clanIcon"
] "clanIcon has been removed. Use clan.core.icon instead.") ] "clanIcon has been removed. Use clan.core.icon instead.")
# The following options have been moved into clan.core.settings
(lib.mkRenamedOptionModule (lib.mkRenamedOptionModule
[ "clan" "core" "clanDir" ] [ "clan" "core" "clanDir" ]
[ [
@@ -24,6 +25,17 @@ in
"directory" "directory"
] ]
) )
# The following options have been moved into clan.core.settings.machine
(lib.mkRenamedOptionModule
[ "clan" "core" "machineName" ]
[
"clan"
"core"
"settings"
"machine"
"name"
]
)
]; ];
options.clan.core = { options.clan.core = {
settings = mkOption { settings = mkOption {
@@ -34,17 +46,26 @@ in
''; '';
type = types.submodule { type = types.submodule {
options = { options = {
directory = lib.mkOption { directory = mkOption {
type = lib.types.path; type = types.path;
# documentation.nixos.extraModules = [
# ...
# clan-core.nixosModules.clanCore
# { clan.core.settings.directory = ./path/to/flake; }
# ];
description = '' description = ''
the location of the flake repo, used to calculate the location of facts and secrets the location of the flake repo, used to calculate the location of facts and secrets
''; '';
}; };
machine = mkOption {
default = {};
type = types.submodule {
options = {
name = mkOption {
type = types.str;
default = "nixos";
description = ''
the name of the machine
'';
};
};
};
};
}; };
}; };
}; };
@@ -79,13 +100,6 @@ in
the description of the machine the description of the machine
''; '';
}; };
machineName = lib.mkOption {
type = lib.types.str;
default = "nixos";
description = ''
the name of the machine
'';
};
clanPkgs = lib.mkOption { clanPkgs = lib.mkOption {
defaultText = "self.packages.${pkgs.system}"; defaultText = "self.packages.${pkgs.system}";
internal = true; internal = true;

View File

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

View File

@@ -20,7 +20,7 @@ in
else else
( (
config.clan.core.settings.directory config.clan.core.settings.directory
+ "/vars/per-machine/${config.clan.core.machineName}/${file.config.generatorName}/${file.config.name}/value" + "/vars/per-machine/${config.clan.core.settings.machine.name}/${file.config.generatorName}/${file.config.name}/value"
) )
); );
value = mkIf (file.config.secret == false) ( value = mkIf (file.config.secret == false) (

View File

@@ -10,7 +10,7 @@ let
inherit (import ./funcs.nix { inherit lib; }) collectFiles; inherit (import ./funcs.nix { inherit lib; }) collectFiles;
inherit (config.clan.core) machineName; machineName = config.clan.core.settings.machine.name;
secretPath = secretPath =
secret: secret:

View File

@@ -252,7 +252,7 @@ in
clan.core.vm.inspect = { clan.core.vm.inspect = {
clan_name = config.clan.core.name; clan_name = config.clan.core.name;
machine_icon = config.clan.core.machineIcon or config.clan.core.icon; machine_icon = config.clan.core.machineIcon or config.clan.core.icon;
machine_name = config.clan.core.machineName; machine_name = config.clan.core.settings.machine.name;
machine_description = config.clan.core.machineDescription; machine_description = config.clan.core.machineDescription;
memory_size = config.clan.virtualisation.memorySize; memory_size = config.clan.virtualisation.memorySize;
inherit (config.clan.virtualisation) cores graphics waypipe; inherit (config.clan.virtualisation) cores graphics waypipe;