From afbd4a984de393d54a053e9d721929fb644b001b Mon Sep 17 00:00:00 2001 From: DavHau Date: Thu, 4 Jul 2024 16:09:15 +0700 Subject: [PATCH] clan.core: rename clan.{deployment,networking} -> clan.core.{deployment,networking} --- checks/backups/flake-module.nix | 2 +- checks/installation/flake-module.nix | 2 +- clanModules/syncthing/default.nix | 2 +- clanModules/zerotier-static-peers/default.nix | 4 +-- docs/mkdocs.yml | 2 ++ docs/site/getting-started/configure.md | 4 +-- docs/site/getting-started/deploy.md | 4 +-- docs/site/getting-started/flake-parts.md | 4 +-- docs/site/getting-started/mesh-vpn.md | 4 +-- nixosModules/clanCore/networking.nix | 26 ++++++++++++++++++- nixosModules/clanCore/outputs.nix | 2 +- nixosModules/clanCore/zerotier/default.nix | 8 +++--- pkgs/clan-cli/clan_cli/machines/hardware.py | 2 +- pkgs/clan-cli/clan_cli/machines/machines.py | 2 +- pkgs/clan-cli/clan_cli/machines/update.py | 2 +- pkgs/clan-cli/tests/machines/vm1/default.nix | 4 +-- .../machines/vm_with_secrets/default.nix | 4 +-- .../machines/vm_without_secrets/default.nix | 2 +- .../tests/test_flake_with_core/flake.nix | 8 +++--- .../test_flake_with_core_and_pass/flake.nix | 4 +-- templates/new-clan/flake.nix | 8 +++--- 21 files changed, 63 insertions(+), 37 deletions(-) diff --git a/checks/backups/flake-module.nix b/checks/backups/flake-module.nix index 6c6dad17..b06f15f8 100644 --- a/checks/backups/flake-module.nix +++ b/checks/backups/flake-module.nix @@ -27,7 +27,7 @@ self.clanModules.localbackup self.clanModules.sshd ]; - clan.networking.targetHost = "machine"; + clan.core.networking.targetHost = "machine"; networking.hostName = "machine"; services.openssh.settings.UseDns = false; diff --git a/checks/installation/flake-module.nix b/checks/installation/flake-module.nix index 2b87b9ee..ac8ddf84 100644 --- a/checks/installation/flake-module.nix +++ b/checks/installation/flake-module.nix @@ -1,7 +1,7 @@ { self, lib, ... }: { clan.machines.test_install_machine = { - clan.networking.targetHost = "test_install_machine"; + clan.core.networking.targetHost = "test_install_machine"; fileSystems."/".device = lib.mkDefault "/dev/vdb"; boot.loader.grub.device = lib.mkDefault "/dev/vdb"; diff --git a/clanModules/syncthing/default.nix b/clanModules/syncthing/default.nix index e32ea20a..ca3765fc 100644 --- a/clanModules/syncthing/default.nix +++ b/clanModules/syncthing/default.nix @@ -98,7 +98,7 @@ settings = { options = { urAccepted = -1; - allowedNetworks = [ config.clan.networking.zerotier.subnet ]; + allowedNetworks = [ config.clan.core.networking.zerotier.subnet ]; }; devices = { } diff --git a/clanModules/zerotier-static-peers/default.nix b/clanModules/zerotier-static-peers/default.nix index 34dca03f..a55889d2 100644 --- a/clanModules/zerotier-static-peers/default.nix +++ b/clanModules/zerotier-static-peers/default.nix @@ -57,7 +57,7 @@ in ) filteredMachines ); in - lib.mkIf (config.clan.networking.zerotier.controller.enable) { + lib.mkIf (config.clan.core.networking.zerotier.controller.enable) { wantedBy = [ "multi-user.target" ]; after = [ "zerotierone.service" ]; path = [ config.clan.core.clanPkgs.zerotierone ]; @@ -69,5 +69,5 @@ in ''; }; - config.clan.networking.zerotier.networkId = lib.mkDefault networkId; + config.clan.core.networking.zerotier.networkId = lib.mkDefault networkId; } diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 1432872d..358092ca 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -94,6 +94,8 @@ nav: - reference/clan-core/facts.md - reference/clan-core/sops.md - reference/clan-core/state.md + - reference/clan-core/deployment.md + - reference/clan-core/networking.md - Contributing: contributing/contributing.md docs_dir: site diff --git a/docs/site/getting-started/configure.md b/docs/site/getting-started/configure.md index 1b872b24..8f191d53 100644 --- a/docs/site/getting-started/configure.md +++ b/docs/site/getting-started/configure.md @@ -89,7 +89,7 @@ Adding or configuring a new machine requires two simple steps: # Change this to the correct ip-address or hostname # The hostname is the machine name by default - clan.networking.targetHost = pkgs.lib.mkDefault "root@jon" + clan.core.networking.targetHost = pkgs.lib.mkDefault "root@jon" # Change this to the ID-LINK of the desired disk shown by 'lsblk' disko.devices.disk.main = { @@ -122,7 +122,7 @@ Adding or configuring a new machine requires two simple steps: # Change this to the correct ip-address or hostname # The hostname is the machine name by default - clan.networking.targetHost = pkgs.lib.mkDefault "root@jon" + clan.core.networking.targetHost = pkgs.lib.mkDefault "root@jon" # Change this to the ID-LINK of the desired disk shown by 'lsblk' disko.devices.disk.main = { diff --git a/docs/site/getting-started/deploy.md b/docs/site/getting-started/deploy.md index 02ef0875..ff09e188 100644 --- a/docs/site/getting-started/deploy.md +++ b/docs/site/getting-started/deploy.md @@ -160,7 +160,7 @@ buildClan { # Set this for clan commands use ssh i.e. `clan machines update` # If you change the hostname, you need to update this line to root@ # This only works however if you have avahi running on your admin machine else use IP - clan.networking.targetHost = pkgs.lib.mkDefault "root@jon"; + clan.core.networking.targetHost = pkgs.lib.mkDefault "root@jon"; }; }; }; @@ -197,7 +197,7 @@ buildClan { # ... machines = { "jon" = { - clan.networking.buildHost = "root@"; + clan.core.networking.buildHost = "root@"; }; }; }; diff --git a/docs/site/getting-started/flake-parts.md b/docs/site/getting-started/flake-parts.md index 69ad2928..86178462 100644 --- a/docs/site/getting-started/flake-parts.md +++ b/docs/site/getting-started/flake-parts.md @@ -75,7 +75,7 @@ Below is a guide on how to structure this in your flake.nix: nixpkgs.hostPlatform = "x86_64-linux"; # Set this for clan commands use ssh i.e. `clan machines update` - clan.networking.targetHost = pkgs.lib.mkDefault "root@jon"; + clan.core.networking.targetHost = pkgs.lib.mkDefault "root@jon"; # remote> lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT disko.devices.disk.main = { @@ -83,7 +83,7 @@ Below is a guide on how to structure this in your flake.nix: }; # There needs to be exactly one controller per clan - clan.networking.zerotier.controller.enable = true; + clan.core.networking.zerotier.controller.enable = true; }; }; diff --git a/docs/site/getting-started/mesh-vpn.md b/docs/site/getting-started/mesh-vpn.md index 56f0c89c..0582b68b 100644 --- a/docs/site/getting-started/mesh-vpn.md +++ b/docs/site/getting-started/mesh-vpn.md @@ -29,7 +29,7 @@ peers. Once addresses are allocated, the controller's continuous operation is no 2. **Add Configuration**: Input the following configuration to the NixOS configuration of the controller machine: ```nix - clan.networking.zerotier.controller = { + clan.core.networking.zerotier.controller = { enable = true; public = true; }; @@ -48,7 +48,7 @@ To introduce a new machine to the VPN, adhere to the following steps: configuration, substituting `` with the controller machine name: ```nix { config, ... }: { - clan.networking.zerotier.networkId = builtins.readFile (config.clan.core.clanDir + "/machines//facts/zerotier-network-id"); + clan.core.networking.zerotier.networkId = builtins.readFile (config.clan.core.clanDir + "/machines//facts/zerotier-network-id"); } ``` 1. **Update the New Machine**: Execute: diff --git a/nixosModules/clanCore/networking.nix b/nixosModules/clanCore/networking.nix index e5dcbc70..a4142a52 100644 --- a/nixosModules/clanCore/networking.nix +++ b/nixosModules/clanCore/networking.nix @@ -1,6 +1,6 @@ { config, lib, ... }: { - options.clan = { + options.clan.core = { networking = { targetHost = lib.mkOption { description = '' @@ -53,10 +53,34 @@ [ "clan" "networking" + ] + [ + "clan" + "core" + "networking" + ] + ) + (lib.mkRenamedOptionModule + [ + "clan" + "deployment" + ] + [ + "clan" + "core" + "deployment" + ] + ) + (lib.mkRenamedOptionModule + [ + "clan" + "core" + "networking" "deploymentAddress" ] [ "clan" + "core" "networking" "targetHost" ] diff --git a/nixosModules/clanCore/outputs.nix b/nixosModules/clanCore/outputs.nix index e88b615a..aa71b41b 100644 --- a/nixosModules/clanCore/outputs.nix +++ b/nixosModules/clanCore/outputs.nix @@ -73,7 +73,7 @@ services ; }; - inherit (config.clan.networking) targetHost buildHost; + inherit (config.clan.core.networking) targetHost buildHost; inherit (config.clan.deployment) requireExplicitUpdate; }; system.clan.deployment.file = pkgs.writeText "deployment.json" ( diff --git a/nixosModules/clanCore/zerotier/default.nix b/nixosModules/clanCore/zerotier/default.nix index 8a07f36d..a26974b0 100644 --- a/nixosModules/clanCore/zerotier/default.nix +++ b/nixosModules/clanCore/zerotier/default.nix @@ -5,7 +5,7 @@ ... }: let - cfg = config.clan.networking.zerotier; + cfg = config.clan.core.networking.zerotier; facts = config.clan.core.facts.services.zerotier.public or { }; genMoonScript = pkgs.runCommand "genmoon" { nativeBuildInputs = [ pkgs.python3 ]; } '' install -Dm755 ${./genmoon.py} $out/bin/genmoon @@ -13,7 +13,7 @@ let ''; in { - options.clan.networking.zerotier = { + options.clan.core.networking.zerotier = { networkId = lib.mkOption { type = lib.types.nullOr lib.types.str; default = null; @@ -231,8 +231,8 @@ in }; }) (lib.mkIf (cfg.controller.enable && (facts.zerotier-network-id.value or null) != null) { - clan.networking.zerotier.networkId = facts.zerotier-network-id.value; - clan.networking.zerotier.settings = { + clan.core.networking.zerotier.networkId = facts.zerotier-network-id.value; + clan.core.networking.zerotier.settings = { authTokens = [ null ]; authorizationEndpoint = ""; capabilities = [ ]; diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index 1c60ae9b..23dec301 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -51,7 +51,7 @@ def show_machine_deployment_target( [ f"{clan_dir}#clanInternals.machines.{system}.{machine_name}", "--apply", - "machine: { inherit (machine.config.clan.networking) targetHost; }", + "machine: { inherit (machine.config.clan.core.networking) targetHost; }", "--json", ] ) diff --git a/pkgs/clan-cli/clan_cli/machines/machines.py b/pkgs/clan-cli/clan_cli/machines/machines.py index 877ba642..36eda175 100644 --- a/pkgs/clan-cli/clan_cli/machines/machines.py +++ b/pkgs/clan-cli/clan_cli/machines/machines.py @@ -53,7 +53,7 @@ class Machine: "deploymentAddress" ) if val is None: - msg = f"the 'clan.networking.targetHost' nixos option is not set for machine '{self.name}'" + msg = f"the 'clan.core.networking.targetHost' nixos option is not set for machine '{self.name}'" raise ClanError(msg) return val diff --git a/pkgs/clan-cli/clan_cli/machines/update.py b/pkgs/clan-cli/clan_cli/machines/update.py index b1ab7efd..cd6910cd 100644 --- a/pkgs/clan-cli/clan_cli/machines/update.py +++ b/pkgs/clan-cli/clan_cli/machines/update.py @@ -161,7 +161,7 @@ def update(args: argparse.Namespace) -> None: if not machines and ignored_machines != []: print( - "WARNING: No machines to update. The following defined machines were ignored because they do not have `clan.networking.targetHost` nixos option set:", + "WARNING: No machines to update. The following defined machines were ignored because they do not have `clan.core.networking.targetHost` nixos option set:", file=sys.stderr, ) for machine in ignored_machines: diff --git a/pkgs/clan-cli/tests/machines/vm1/default.nix b/pkgs/clan-cli/tests/machines/vm1/default.nix index b77d37a2..bf87046c 100644 --- a/pkgs/clan-cli/tests/machines/vm1/default.nix +++ b/pkgs/clan-cli/tests/machines/vm1/default.nix @@ -1,12 +1,12 @@ { lib, ... }: { - clan.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; + clan.core.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; system.stateVersion = lib.version; sops.age.keyFile = "__CLAN_SOPS_KEY_PATH__"; clan.core.secretsUploadDirectory = "__CLAN_SOPS_KEY_DIR__"; clan.virtualisation.graphics = false; - clan.networking.zerotier.controller.enable = true; + clan.core.networking.zerotier.controller.enable = true; networking.useDHCP = false; systemd.services.shutdown-after-boot = { diff --git a/pkgs/clan-cli/tests/machines/vm_with_secrets/default.nix b/pkgs/clan-cli/tests/machines/vm_with_secrets/default.nix index b77d37a2..bf87046c 100644 --- a/pkgs/clan-cli/tests/machines/vm_with_secrets/default.nix +++ b/pkgs/clan-cli/tests/machines/vm_with_secrets/default.nix @@ -1,12 +1,12 @@ { lib, ... }: { - clan.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; + clan.core.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; system.stateVersion = lib.version; sops.age.keyFile = "__CLAN_SOPS_KEY_PATH__"; clan.core.secretsUploadDirectory = "__CLAN_SOPS_KEY_DIR__"; clan.virtualisation.graphics = false; - clan.networking.zerotier.controller.enable = true; + clan.core.networking.zerotier.controller.enable = true; networking.useDHCP = false; systemd.services.shutdown-after-boot = { diff --git a/pkgs/clan-cli/tests/machines/vm_without_secrets/default.nix b/pkgs/clan-cli/tests/machines/vm_without_secrets/default.nix index 2d02b56a..41941cea 100644 --- a/pkgs/clan-cli/tests/machines/vm_without_secrets/default.nix +++ b/pkgs/clan-cli/tests/machines/vm_without_secrets/default.nix @@ -1,6 +1,6 @@ { lib, ... }: { - clan.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; + clan.core.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; system.stateVersion = lib.version; clan.virtualisation.graphics = false; diff --git a/pkgs/clan-cli/tests/test_flake_with_core/flake.nix b/pkgs/clan-cli/tests/test_flake_with_core/flake.nix index 63e71c4c..aaf4fd8d 100644 --- a/pkgs/clan-cli/tests/test_flake_with_core/flake.nix +++ b/pkgs/clan-cli/tests/test_flake_with_core/flake.nix @@ -15,14 +15,14 @@ vm1 = { lib, ... }: { - clan.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; + clan.core.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; system.stateVersion = lib.version; sops.age.keyFile = "__CLAN_SOPS_KEY_PATH__"; clan.core.secretsUploadDirectory = "__CLAN_SOPS_KEY_DIR__"; clan.core.sops.defaultGroups = [ "admins" ]; clan.virtualisation.graphics = false; - clan.networking.zerotier.controller.enable = true; + clan.core.networking.zerotier.controller.enable = true; networking.useDHCP = false; systemd.services.shutdown-after-boot = { @@ -45,11 +45,11 @@ ]; clan.user-password.user = "alice"; clan.user-password.prompt = false; - clan.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; + clan.core.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; system.stateVersion = lib.version; sops.age.keyFile = "__CLAN_SOPS_KEY_PATH__"; clan.core.secretsUploadDirectory = "__CLAN_SOPS_KEY_DIR__"; - clan.networking.zerotier.networkId = "82b44b162ec6c013"; + clan.core.networking.zerotier.networkId = "82b44b162ec6c013"; }; }; }; diff --git a/pkgs/clan-cli/tests/test_flake_with_core_and_pass/flake.nix b/pkgs/clan-cli/tests/test_flake_with_core_and_pass/flake.nix index 457909cb..6bc68dc4 100644 --- a/pkgs/clan-cli/tests/test_flake_with_core_and_pass/flake.nix +++ b/pkgs/clan-cli/tests/test_flake_with_core_and_pass/flake.nix @@ -23,12 +23,12 @@ clan.user-password.user = "alice"; clan.user-password.prompt = false; - clan.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; + clan.core.networking.targetHost = "__CLAN_TARGET_ADDRESS__"; system.stateVersion = lib.version; clan.core.secretStore = "password-store"; clan.core.secretsUploadDirectory = lib.mkForce "__CLAN_SOPS_KEY_DIR__/secrets"; - clan.networking.zerotier.controller.enable = true; + clan.core.networking.zerotier.controller.enable = true; systemd.services.shutdown-after-boot = { enable = true; diff --git a/templates/new-clan/flake.nix b/templates/new-clan/flake.nix index 8ae5055d..82cd47b2 100644 --- a/templates/new-clan/flake.nix +++ b/templates/new-clan/flake.nix @@ -42,7 +42,7 @@ # Set this for clan commands use ssh i.e. `clan machines update` # If you change the hostname, you need to update this line to root@ # This only works however if you have avahi running on your admin machine else use IP - clan.networking.targetHost = pkgs.lib.mkDefault "root@jon"; + clan.core.networking.targetHost = pkgs.lib.mkDefault "root@jon"; # ssh root@flash-installer.local lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT disko.devices.disk.main = { @@ -58,7 +58,7 @@ # Zerotier needs one controller to accept new nodes. Once accepted # the controller can be offline and routing still works. - clan.networking.zerotier.controller.enable = true; + clan.core.networking.zerotier.controller.enable = true; }; # "sara" will be the hostname of the machine sara = { @@ -72,7 +72,7 @@ # Set this for clan commands use ssh i.e. `clan machines update` # If you change the hostname, you need to update this line to root@ # This only works however if you have avahi running on your admin machine else use IP - clan.networking.targetHost = pkgs.lib.mkDefault "root@sara"; + clan.core.networking.targetHost = pkgs.lib.mkDefault "root@sara"; # ssh root@flash-installer.local lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT disko.devices.disk.main = { @@ -91,7 +91,7 @@ This will allow sara to share the VPN overlay network with jon The networkId is generated by the first deployment of jon */ - # clan.networking.zerotier.networkId = builtins.readFile ../jon/facts/zerotier-network-id; + # clan.core.networking.zerotier.networkId = builtins.readFile ../jon/facts/zerotier-network-id; }; }; };