From 2f0ba0782aa4677f56c2a4bd3c8f275342b8681d Mon Sep 17 00:00:00 2001 From: a-kenji Date: Mon, 21 Jul 2025 20:43:25 +0200 Subject: [PATCH] clanServices/zerotier: Make moon configuration optional Make moon configuration optional. Before the `attrNames` evaluated the attributes eagerly, which in practice meant that you had to set a moon, if there was a controller configured, which is not on purpose. --- clanServices/zerotier/default.nix | 6 +-- clanServices/zerotier/tests/eval-tests.nix | 53 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/clanServices/zerotier/default.nix b/clanServices/zerotier/default.nix index 7165ef41a..cc48ae16d 100644 --- a/clanServices/zerotier/default.nix +++ b/clanServices/zerotier/default.nix @@ -134,9 +134,9 @@ systemd.services.zerotier-inventory-autoaccept = let machines = uniqueStrings ( - (lib.attrNames roles.moon.machines) - ++ (lib.attrNames roles.controller.machines) - ++ (lib.attrNames roles.peer.machines) + (lib.optionals (roles ? moon) (lib.attrNames roles.moon.machines)) + ++ (lib.optionals (roles ? controller) (lib.attrNames roles.controller.machines)) + ++ (lib.optionals (roles ? peer) (lib.attrNames roles.peer.machines)) ); networkIps = builtins.foldl' ( ips: name: diff --git a/clanServices/zerotier/tests/eval-tests.nix b/clanServices/zerotier/tests/eval-tests.nix index 0feddfe0b..5e24c0b9f 100644 --- a/clanServices/zerotier/tests/eval-tests.nix +++ b/clanServices/zerotier/tests/eval-tests.nix @@ -32,6 +32,33 @@ let }; }; }).config; + testFlakeNoMoon = + (clanLib.clan { + self = { }; + directory = ./vm; + + machines.jon = { + nixpkgs.hostPlatform = "x86_64-linux"; + }; + machines.sara = { + nixpkgs.hostPlatform = "x86_64-linux"; + }; + machines.bam = { + nixpkgs.hostPlatform = "x86_64-linux"; + }; + + modules.zerotier = module; + + inventory.instances = { + zerotier = { + module.name = "zerotier"; + module.input = "self"; + + roles.peer.tags.all = { }; + roles.controller.machines.bam = { }; + }; + }; + }).config; in { test_peers = { @@ -73,4 +100,30 @@ in networkName = "zerotier"; }; }; + test_peers_no_moon = { + expr = { + hasNetworkIds = testFlakeNoMoon.nixosConfigurations.jon.config.services.zerotierone.joinNetworks; + isController = + testFlakeNoMoon.nixosConfigurations.jon.config.clan.core.networking.zerotier.controller.enable; + networkName = testFlakeNoMoon.nixosConfigurations.jon.config.clan.core.networking.zerotier.name; + }; + expected = { + hasNetworkIds = [ "0e28cb903344475e" ]; + isController = false; + networkName = "zerotier"; + }; + }; + test_controller_no_moon = { + expr = { + hasNetworkIds = testFlakeNoMoon.nixosConfigurations.bam.config.services.zerotierone.joinNetworks; + isController = + testFlakeNoMoon.nixosConfigurations.bam.config.clan.core.networking.zerotier.controller.enable; + networkName = testFlakeNoMoon.nixosConfigurations.bam.config.clan.core.networking.zerotier.name; + }; + expected = { + hasNetworkIds = [ "0e28cb903344475e" ]; + isController = true; + networkName = "zerotier"; + }; + }; }