From 762cc5e7cb47487338be6d61fecd62f373d1bc4e Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Fri, 11 Apr 2025 13:47:20 +0200 Subject: [PATCH 1/3] chore(checks/inventory): doogfood 'clan' flake-parts module into the test, instead of custom inventory logic --- checks/dummy-inventory-test/default.nix | 66 +++++++++++++------------ checks/lib/test-inventory.nix | 60 +++++++++++++++------- 2 files changed, 78 insertions(+), 48 deletions(-) diff --git a/checks/dummy-inventory-test/default.nix b/checks/dummy-inventory-test/default.nix index ce03c3fb9..83da56038 100644 --- a/checks/dummy-inventory-test/default.nix +++ b/checks/dummy-inventory-test/default.nix @@ -7,40 +7,44 @@ # - clan.service modules name = "dummy-inventory-test"; - inventory.directory = ./.; - inventory.inventory = { - machines.peer1 = { }; - machines.admin1 = { }; - services = { - legacy-module.default = { - roles.peer.machines = [ "peer1" ]; - roles.admin.machines = [ "admin1" ]; + clanSettings = { + self = ./.; + }; + clan = { + inventory = { + machines.peer1 = { }; + machines.admin1 = { }; + services = { + legacy-module.default = { + roles.peer.machines = [ "peer1" ]; + roles.admin.machines = [ "admin1" ]; + }; + }; + instances."test" = { + module.name = "new-service"; + roles.peer.machines.peer1 = { }; }; - }; - instances."test" = { - module.name = "new-service"; - roles.peer.machines.peer1 = { }; - }; - modules = { - legacy-module = ./legacy-module; - new-service = { - _class = "clan.service"; - manifest.name = "new-service"; - roles.peer = { }; - perMachine = { - nixosModule = { - # This should be generated by: - # ./pkgs/scripts/update-vars.py inventory-test-framework-compatibility-test - clan.core.vars.generators.new-service = { - files.hello = { - secret = false; - deploy = true; + modules = { + legacy-module = ./legacy-module; + new-service = { + _class = "clan.service"; + manifest.name = "new-service"; + roles.peer = { }; + perMachine = { + nixosModule = { + # This should be generated by: + # ./pkgs/scripts/update-vars.py inventory-test-framework-compatibility-test + clan.core.vars.generators.new-service = { + files.hello = { + secret = false; + deploy = true; + }; + script = '' + # This is a dummy script that does nothing + echo "This is a dummy script" > $out/hello + ''; }; - script = '' - # This is a dummy script that does nothing - echo "This is a dummy script" > $out/hello - ''; }; }; }; diff --git a/checks/lib/test-inventory.nix b/checks/lib/test-inventory.nix index feb712586..bbe454dda 100644 --- a/checks/lib/test-inventory.nix +++ b/checks/lib/test-inventory.nix @@ -2,37 +2,62 @@ test: { pkgs, self, ... }: let inherit (pkgs) lib; - inherit (lib) mkOption flip mapAttrs; - inherit (lib.types) path raw; - inherit (self.clanLib) buildClan; + inherit (lib) + mkOption + flip + mapAttrs + types + ; nixos-lib = import (pkgs.path + "/nixos/lib") { }; in (nixos-lib.runTest ( { config, ... }: let - result = buildClan { - inventory = config.inventory.inventory; - # TODO: make directory argument optional in buildInventory - directory = config.inventory.directory; - }; + clanFlakeResult = config.clan; in { imports = [ test ]; options = { - inventory.inventory = mkOption { - description = "Inventory of machines and services"; - type = raw; + clanSettings = mkOption { + default = { }; + type = types.submodule { + options = { + clan-core = mkOption { default = self; }; + self = mkOption { + default = throw '' + Clan testing: 'clanSettings.self' is required to be set explizitly during testing. + + It is recommended to set 'clanSettings.self' during testing to the directory where the test lives in i.e. './.' + ''; + }; + nixpkgs = mkOption { default = self.inputs.nixpkgs; }; + nix-darwin = mkOption { default = self.inputs.nix-darwin; }; + }; + }; }; - inventory.directory = mkOption { - description = "Directory which contains the vars"; - type = path; + + clan = mkOption { + default = { }; + type = types.submoduleWith { + specialArgs = { + inherit (config.clanSettings) + clan-core + self + nixpkgs + nix-darwin + ; + }; + modules = [ + self.clanLib.buildClanModule.flakePartsModule + ]; + }; }; }; config = { - nodes = flip mapAttrs result.clanInternals.inventoryClass.machines ( + nodes = flip mapAttrs clanFlakeResult.clanInternals.inventoryClass.machines ( machineName: attrs: { imports = attrs.machineImports ++ [ self.nixosModules.clanCore ]; - clan.core.settings.directory = "${config.inventory.directory}"; + clan.core.settings.directory = "${config.clan.directory}"; clan.core.settings.machine.name = machineName; } ); @@ -69,4 +94,5 @@ in node.specialArgs.self = self; }; } -)).config.result +)) +# .config.result From 02f630a25b0e78a2e7a8ce0f891baf8b70339b4e Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Fri, 11 Apr 2025 13:53:04 +0200 Subject: [PATCH 2/3] chore(checks): rename data-mesher test attributes --- checks/data-mesher/default.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/checks/data-mesher/default.nix b/checks/data-mesher/default.nix index e8a6b0eba..1975df621 100644 --- a/checks/data-mesher/default.nix +++ b/checks/data-mesher/default.nix @@ -11,7 +11,10 @@ { name = "data-mesher"; - inventory = { + clanSettings = { + self = ./.; + }; + clan = { inventory = { machines = lib.genAttrs machines (_: { }); services = { @@ -22,7 +25,6 @@ }; }; }; - directory = ./.; }; defaults = From 5e03a449374dbfcc7cbacbd64a9181342322b2c8 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 12 Apr 2025 12:41:04 +0200 Subject: [PATCH 3/3] fixup(checks/inventory): remove 'self' from clan settings; doesn't work in the nixos tests yet. We need to reasearch why that is the case. Removing the option for now to prevent weird bugs --- checks/data-mesher/default.nix | 4 +--- checks/dummy-inventory-test/default.nix | 4 +--- checks/lib/test-inventory.nix | 11 +---------- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/checks/data-mesher/default.nix b/checks/data-mesher/default.nix index 1975df621..029b2277d 100644 --- a/checks/data-mesher/default.nix +++ b/checks/data-mesher/default.nix @@ -11,10 +11,8 @@ { name = "data-mesher"; - clanSettings = { - self = ./.; - }; clan = { + directory = ./.; inventory = { machines = lib.genAttrs machines (_: { }); services = { diff --git a/checks/dummy-inventory-test/default.nix b/checks/dummy-inventory-test/default.nix index 83da56038..bafac94e9 100644 --- a/checks/dummy-inventory-test/default.nix +++ b/checks/dummy-inventory-test/default.nix @@ -7,10 +7,8 @@ # - clan.service modules name = "dummy-inventory-test"; - clanSettings = { - self = ./.; - }; clan = { + directory = ./.; inventory = { machines.peer1 = { }; machines.admin1 = { }; diff --git a/checks/lib/test-inventory.nix b/checks/lib/test-inventory.nix index bbe454dda..60939c13f 100644 --- a/checks/lib/test-inventory.nix +++ b/checks/lib/test-inventory.nix @@ -23,13 +23,6 @@ in type = types.submodule { options = { clan-core = mkOption { default = self; }; - self = mkOption { - default = throw '' - Clan testing: 'clanSettings.self' is required to be set explizitly during testing. - - It is recommended to set 'clanSettings.self' during testing to the directory where the test lives in i.e. './.' - ''; - }; nixpkgs = mkOption { default = self.inputs.nixpkgs; }; nix-darwin = mkOption { default = self.inputs.nix-darwin; }; }; @@ -42,7 +35,6 @@ in specialArgs = { inherit (config.clanSettings) clan-core - self nixpkgs nix-darwin ; @@ -94,5 +86,4 @@ in node.specialArgs.self = self; }; } -)) -# .config.result +)).config.result