From 6154b4cb3a965dc07acc678b5df6565846f7d2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 9 Apr 2025 16:08:39 +0200 Subject: [PATCH] Revert "Merge pull request 'chore(buildClan): move machineClass option into inventory.machines submodule' (#3259) from hsjobeki/clan-core:buildclan-cleanup into main" This reverts commit 325a794d12b3a47ab8a7b9a4b61f27e9065f8a29, reversing changes made to afbae04aa6b6c0374ba9f4885593dbaa1324d727. --- inventory.json | 3 --- lib/build-clan/module.nix | 16 +++++------- lib/build-clan/tests.nix | 13 +++++---- lib/inventory/build-inventory/interface.nix | 29 +++++++++++---------- pkgs/clan-cli/clan_cli/inventory/classes.py | 2 +- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/inventory.json b/inventory.json index af7896845..7e50ba188 100644 --- a/inventory.json +++ b/inventory.json @@ -5,9 +5,6 @@ "description": "A nice thing", "icon": "./path/to/icon.png", "tags": ["1", "2", "3"] - }, - "test-darwin-machine": { - "machineClass": "darwin" } }, "services": { diff --git a/lib/build-clan/module.nix b/lib/build-clan/module.nix index 16ca78aff..9f69bf99b 100644 --- a/lib/build-clan/module.nix +++ b/lib/build-clan/module.nix @@ -164,18 +164,16 @@ let }; }; - allMachines = inventoryClass.machines; + allMachines = inventory.machines or { } // machines; - machineClasses = lib.mapAttrs ( - name: _: inventory.machines.${name}.machineClass or "nixos" - ) allMachines; + machineClass = lib.mapAttrs (name: _: inventory.machineClass.${name} or "nixos") allMachines; configurations = lib.mapAttrs ( - name: _: moduleSystemConstructor.${machineClasses.${name}} { inherit name; } + name: _: moduleSystemConstructor.${machineClass.${name}} { inherit name; } ) allMachines; - nixosConfigurations = lib.filterAttrs (name: _: machineClasses.${name} == "nixos") configurations; - darwinConfigurations = lib.filterAttrs (name: _: machineClasses.${name} == "darwin") configurations; + nixosConfigurations = lib.filterAttrs (name: _: machineClass.${name} == "nixos") configurations; + darwinConfigurations = lib.filterAttrs (name: _: machineClass.${name} == "darwin") configurations; # This instantiates NixOS for each system that we support: # configPerSystem = ..nixosConfiguration @@ -186,7 +184,7 @@ let lib.nameValuePair system ( lib.mapAttrs ( name: _: - moduleSystemConstructor.${machineClasses.${name}} { + moduleSystemConstructor.${machineClass.${name}} { inherit name system; pkgs = pkgsFor.${system}; } @@ -201,7 +199,7 @@ let lib.nameValuePair system ( lib.mapAttrs ( name: _: args: - moduleSystemConstructor.${machineClasses.${name}} ( + moduleSystemConstructor.${machineClass.${name}} ( args // { inherit name system; diff --git a/lib/build-clan/tests.nix b/lib/build-clan/tests.nix index 875f6e538..f87918e7a 100644 --- a/lib/build-clan/tests.nix +++ b/lib/build-clan/tests.nix @@ -210,16 +210,14 @@ in meta.name = "test"; machines.machine1 = { }; - inventory.machines.machine2 = { - machineClass = "darwin"; - }; - inventory.machines.machine3 = { - machineClass = "nixos"; - }; + machines.machine2 = { }; + machines.machine3 = { }; + + inventory.machineClass.machine2 = "darwin"; + inventory.machineClass.machine3 = "nixos"; }; in { - inherit result; expr = { nixos = builtins.attrNames result.nixosConfigurations; darwin = builtins.attrNames result.darwinConfigurations; @@ -243,6 +241,7 @@ in meta.name = "test"; machines.machine1.non_existent_option = throw "eval error"; + inventory.machines.machine1.other_non_existent_option = throw "different eval error"; }; in { diff --git a/lib/inventory/build-inventory/interface.nix b/lib/inventory/build-inventory/interface.nix index 45564f6d9..110b3199b 100644 --- a/lib/inventory/build-inventory/interface.nix +++ b/lib/inventory/build-inventory/interface.nix @@ -243,19 +243,6 @@ in options = { inherit (metaOptionsWith name) name description icon; - machineClass = lib.mkOption { - default = "nixos"; - type = types.enum [ - "nixos" - "darwin" - ]; - description = '' - The module system that should be used to construct the machine - - Set this to `darwin` for macOS machines - ''; - }; - tags = lib.mkOption { description = '' List of tags for the machine. @@ -291,6 +278,21 @@ in ); }; + machineClass = lib.mkOption { + default = { }; + type = types.attrsOf ( + types.enum [ + "nixos" + "darwin" + ] + ); + description = '' + The module system that should be used to construct the machine + + Set this to `darwin` for macOS machines + ''; + }; + instances = lib.mkOption { # Keep as internal until all de-/serialization issues are resolved visible = false; @@ -364,7 +366,6 @@ in else lib.warn "Inventory.instances and related features are still under development. Please use with care." v; }; - services = lib.mkOption { description = '' Services of the inventory. diff --git a/pkgs/clan-cli/clan_cli/inventory/classes.py b/pkgs/clan-cli/clan_cli/inventory/classes.py index 77218498b..d21fb139c 100644 --- a/pkgs/clan-cli/clan_cli/inventory/classes.py +++ b/pkgs/clan-cli/clan_cli/inventory/classes.py @@ -16,7 +16,6 @@ class Machine(TypedDict): deploy: NotRequired[MachineDeploy] description: NotRequired[str] icon: NotRequired[str] - machineClass: NotRequired[Literal["nixos", "darwin"]] name: NotRequired[str] tags: NotRequired[list[str]] @@ -30,6 +29,7 @@ Service = dict[str, Any] class Inventory(TypedDict): + machineClass: NotRequired[dict[str, Any]] machines: NotRequired[dict[str, Machine]] meta: NotRequired[Meta] modules: NotRequired[dict[str, Any]]