From ac95878eadb37b5f7afd16ccbc3beb5c94b7a81d Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 16 Jul 2024 13:56:53 +0200 Subject: [PATCH 1/7] Inventory: init: deployment info for machines --- flakeModules/clan.nix | 2 +- lib/build-clan/default.nix | 7 +++++++ lib/inventory/build-inventory/default.nix | 2 +- lib/inventory/build-inventory/interface.nix | 11 +++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/flakeModules/clan.nix b/flakeModules/clan.nix index 01739305a..f8a60d1fb 100644 --- a/flakeModules/clan.nix +++ b/flakeModules/clan.nix @@ -120,8 +120,8 @@ in machines pkgsForSystem meta + inventory ; - inventory = (lib.traceValSeq cfg.inventory); }; }; _file = __curPos.file; diff --git a/lib/build-clan/default.nix b/lib/build-clan/default.nix index 82c8f9c36..7b6e4969e 100644 --- a/lib/build-clan/default.nix +++ b/lib/build-clan/default.nix @@ -72,6 +72,13 @@ let "nixpkgs" "hostSystem" ] null config; + + deploymentInfo.targetHost = lib.attrByPath [ + "clan" + "core" + "networking" + "targetHost" + ] null config; } ) machines; } diff --git a/lib/inventory/build-inventory/default.nix b/lib/inventory/build-inventory/default.nix index a24eaa053..413c79766 100644 --- a/lib/inventory/build-inventory/default.nix +++ b/lib/inventory/build-inventory/default.nix @@ -24,7 +24,7 @@ let availableTags = lib.foldlAttrs ( acc: _: v: v.tags or [ ] ++ acc - ) [ ] (lib.traceValSeq inventory.machines); + ) [ ] (inventory.machines); tagMembers = builtins.attrNames ( lib.filterAttrs (_n: v: builtins.elem tag v.tags or [ ]) inventory.machines diff --git a/lib/inventory/build-inventory/interface.nix b/lib/inventory/build-inventory/interface.nix index a64b376e4..cc121c946 100644 --- a/lib/inventory/build-inventory/interface.nix +++ b/lib/inventory/build-inventory/interface.nix @@ -49,6 +49,17 @@ in default = null; type = types.nullOr types.str; }; + deploymentInfo = lib.mkOption { + default = { }; + type = types.submodule { + options = { + targetHost = lib.mkOption { + default = null; + type = types.nullOr types.str; + }; + }; + }; + }; }; } ); From 7e21428548c7c818ec28b3b281794bf765deb44b Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 16 Jul 2024 16:15:56 +0200 Subject: [PATCH 2/7] Inventory: extend model by deployment info --- inventory.json | 5 ++- lib/build-clan/default.nix | 40 +++++++++++++++----- lib/inventory/build-inventory/default.nix | 3 ++ pkgs/clan-cli/clan_cli/inventory/__init__.py | 24 +++++++++++- 4 files changed, 60 insertions(+), 12 deletions(-) diff --git a/inventory.json b/inventory.json index 3929343b5..fae406ab1 100644 --- a/inventory.json +++ b/inventory.json @@ -8,7 +8,10 @@ "system": "x86_64-linux", "description": "A nice thing", "icon": "./path/to/icon.png", - "tags": ["1", "2", "3"] + "tags": ["1", "2", "3"], + "deploymentInfo": { + "targetHost": "root@remote.com" + } } }, "services": { diff --git a/lib/build-clan/default.nix b/lib/build-clan/default.nix index 7b6e4969e..2b1921734 100644 --- a/lib/build-clan/default.nix +++ b/lib/build-clan/default.nix @@ -30,6 +30,15 @@ let # - Machines that exist in the machines directory # Checks on the module level: # - Each service role must reference a valid machine after all machines are merged + + clanToInventory = + config: + { clanPath, inventoryPath }: + let + v = lib.attrByPath clanPath null config; + in + lib.optionalAttrs (v != null) (lib.setAttrByPath inventoryPath v); + mergedInventory = (lib.evalModules { modules = [ @@ -63,23 +72,36 @@ let "name" ] name config ); - tags = lib.attrByPath [ + } + # tags + // (clanToInventory config { + clanPath = [ "clan" "tags" - ] [ ] config; - - system = lib.attrByPath [ + ]; + inventoryPath = [ "tags" ]; + }) + # system + // (clanToInventory config { + clanPath = [ "nixpkgs" "hostSystem" - ] null config; - - deploymentInfo.targetHost = lib.attrByPath [ + ]; + inventoryPath = [ "system" ]; + }) + # deploymentInfo.targetHost + // (clanToInventory config { + clanPath = [ "clan" "core" "networking" "targetHost" - ] null config; - } + ]; + inventoryPath = [ + "deploymentInfo" + "targetHost" + ]; + }) ) machines; } diff --git a/lib/inventory/build-inventory/default.nix b/lib/inventory/build-inventory/default.nix index 413c79766..9b1e3f3e5 100644 --- a/lib/inventory/build-inventory/default.nix +++ b/lib/inventory/build-inventory/default.nix @@ -148,6 +148,9 @@ let (lib.optionalAttrs (machineConfig.system or null != null) { config.nixpkgs.hostPlatform = machineConfig.system; }) + (lib.optionalAttrs (machineConfig.deploymentInfo.targetHost or null != null) { + config.clan.core.networking.targetHost = machineConfig.deploymentInfo.targetHost; + }) ] ) inventory.machines or { }; in diff --git a/pkgs/clan-cli/clan_cli/inventory/__init__.py b/pkgs/clan-cli/clan_cli/inventory/__init__.py index 00fb00972..bb621e1d5 100644 --- a/pkgs/clan-cli/clan_cli/inventory/__init__.py +++ b/pkgs/clan-cli/clan_cli/inventory/__init__.py @@ -35,6 +35,15 @@ def dataclass_to_dict(obj: Any) -> Any: return obj +@dataclass +class DeploymentInfo: + """ + Deployment information for a machine. + """ + + target_host: str | None = None + + @dataclass class Machine: """ @@ -49,14 +58,25 @@ class Machine: """ name: str - system: Literal["x86_64-linux"] | str | None = None description: str | None = None icon: str | None = None tags: list[str] = field(default_factory=list) + system: Literal["x86_64-linux"] | str | None = None + + deployment_info: DeploymentInfo | None = None @staticmethod def from_dict(d: dict[str, Any]) -> "Machine": - return Machine(**d) + return Machine( + name=d["name"], + description=d.get("description", None), + icon=d.get("icon", None), + tags=d.get("tags", []), + system=d.get("system", None), + deployment_info=DeploymentInfo( + target_host=d.get("deploymentInfo", {}).get("targetHost", None) + ), + ) @dataclass From ef18d60286792d39a72365010b11a3ef6a04432f Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 17 Jul 2024 10:06:46 +0200 Subject: [PATCH 3/7] Inventory: extend python dataclasses by schema changes --- inventory.json | 69 +++++++++++++------- lib/inventory/flake-module.nix | 17 +++-- lib/inventory/interface-to-schema.nix | 37 +++++++++-- pkgs/clan-cli/clan_cli/inventory/__init__.py | 7 ++ 4 files changed, 97 insertions(+), 33 deletions(-) diff --git a/inventory.json b/inventory.json index fae406ab1..021f9ab05 100644 --- a/inventory.json +++ b/inventory.json @@ -1,16 +1,18 @@ { "meta": { - "name": "clan-core" + "name": "clan-core", + "description": null, + "icon": null }, "machines": { - "minimal-inventory-machine": { + "test-inventory-machine": { "name": "foo", - "system": "x86_64-linux", "description": "A nice thing", "icon": "./path/to/icon.png", "tags": ["1", "2", "3"], - "deploymentInfo": { - "targetHost": "root@remote.com" + "system": "x86_64-linux", + "deployment_info": { + "target_host": "root@remote.com" } } }, @@ -18,65 +20,82 @@ "packages": { "editors": { "meta": { - "name": "Some editor packages" + "name": "Some editor packages", + "description": null, + "icon": null }, "roles": { "default": { - "machines": ["minimal-inventory-machine"], + "machines": ["test-inventory-machine"], + "tags": [], "config": { "packages": ["vim"] - } + }, + "imports": [] } }, "machines": { - "minimal-inventory-machine": { + "test-inventory-machine": { "config": { "packages": ["zed-editor"] - } + }, + "imports": [] } }, - "config": { - "packages": ["vim"] - } + "config": null, + "imports": [] }, "browsing": { "meta": { - "name": "Web browsing packages" + "name": "Web browsing packages", + "description": null, + "icon": null }, "roles": { "default": { - "machines": ["minimal-inventory-machine"] + "machines": ["test-inventory-machine"], + "tags": [], + "config": null, + "imports": [] } }, "machines": { - "minimal-inventory-machine": { + "test-inventory-machine": { "config": { "packages": ["chromium"] - } + }, + "imports": [] } }, - "config": { - "packages": ["firefox"] - } + "config": null, + "imports": [] } }, "single-disk": { "default": { "meta": { - "name": "single-disk" + "name": "single-disk", + "description": null, + "icon": null }, "roles": { "default": { - "machines": ["minimal-inventory-machine"] + "machines": ["test-inventory-machine"], + "tags": [], + "config": null, + "imports": [] } }, "machines": { - "minimal-inventory-machine": { + "test-inventory-machine": { "config": { "device": "/dev/null" - } + }, + "imports": [] } - } + }, + "config": null, + "imports": [] } } } diff --git a/lib/inventory/flake-module.nix b/lib/inventory/flake-module.nix index 5ca9385cc..07ad18f5c 100644 --- a/lib/inventory/flake-module.nix +++ b/lib/inventory/flake-module.nix @@ -23,10 +23,19 @@ in }; getSchema = import ./interface-to-schema.nix { inherit lib self; }; + + # The schema for the inventory, without default values, from the module system. + # This is better suited for human reading and for generating code. + bareSchema = getSchema { includeDefaults = false; }; + # The schema for the inventory with default values, from the module system. + # This is better suited for validation, since default values are included. + fullSchema = getSchema { }; in { - legacyPackages.inventorySchema = getSchema { }; - legacyPackages.inventorySchemaPretty = getSchema { includeDefaults = false; }; + legacyPackages.inventory = { + inherit fullSchema; + inherit bareSchema; + }; devShells.inventory-schema = pkgs.mkShell { inputsFrom = with config.checks; [ @@ -42,7 +51,7 @@ in buildInputs = [ pkgs.cue ]; src = ./.; buildPhase = '' - export SCHEMA=${builtins.toFile "inventory-schema.json" (builtins.toJSON self'.legacyPackages.inventorySchema)} + export SCHEMA=${builtins.toFile "inventory-schema.json" (builtins.toJSON fullSchema.schemaWithModules)} cp $SCHEMA schema.json cue import -f -p compose -l '#Root:' schema.json mkdir $out @@ -55,7 +64,7 @@ in buildInputs = [ pkgs.cue ]; src = ./.; buildPhase = '' - export SCHEMA=${builtins.toFile "inventory-schema.json" (builtins.toJSON self'.legacyPackages.inventorySchemaPretty)} + export SCHEMA=${builtins.toFile "inventory-schema.json" (builtins.toJSON bareSchema.schemaWithModules)} cp $SCHEMA schema.json cue import -f -p compose -l '#Root:' schema.json mkdir $out diff --git a/lib/inventory/interface-to-schema.nix b/lib/inventory/interface-to-schema.nix index 0daa5c639..b9ee02808 100644 --- a/lib/inventory/interface-to-schema.nix +++ b/lib/inventory/interface-to-schema.nix @@ -53,7 +53,9 @@ let properties = { meta = inventorySchema.properties.services.additionalProperties.additionalProperties.properties.meta; - config = moduleSchema; + config = { + title = "${moduleName}-config"; + } // moduleSchema; roles = { type = "object"; additionalProperties = false; @@ -62,14 +64,24 @@ let map (role: { name = role; value = - inventorySchema.properties.services.additionalProperties.additionalProperties.properties.roles.additionalProperties; + lib.recursiveUpdate + inventorySchema.properties.services.additionalProperties.additionalProperties.properties.roles.additionalProperties + { + properties.config = { + title = "${moduleName}-config"; + } // moduleSchema; + }; }) (rolesOf moduleName) ); }; machines = lib.recursiveUpdate inventorySchema.properties.services.additionalProperties.additionalProperties.properties.machines - { additionalProperties.properties.config = moduleSchema; }; + { + additionalProperties.properties.config = { + title = "${moduleName}-config"; + } // moduleSchema; + }; }; }; }; @@ -95,4 +107,21 @@ let }; }; in -schema +{ + /* + The abstract inventory without the exact schema for each module filled + + InventorySchema :: { + serviceConfig :: dict[str, T]; + } + */ + abstractSchema = inventorySchema; + /* + The inventory with each module schema filled. + + InventorySchema :: { + ${serviceConfig} :: T; # <- each concrete module name is filled + } + */ + schemaWithModules = schema; +} diff --git a/pkgs/clan-cli/clan_cli/inventory/__init__.py b/pkgs/clan-cli/clan_cli/inventory/__init__.py index bb621e1d5..021efc70d 100644 --- a/pkgs/clan-cli/clan_cli/inventory/__init__.py +++ b/pkgs/clan-cli/clan_cli/inventory/__init__.py @@ -82,6 +82,7 @@ class Machine: @dataclass class MachineServiceConfig: config: dict[str, Any] | None = None + imports: list[str] = field(default_factory=list) @dataclass @@ -93,6 +94,8 @@ class ServiceMeta: @dataclass class Role: + config: dict[str, Any] | None = None + imports: list[str] = field(default_factory=list) machines: list[str] = field(default_factory=list) tags: list[str] = field(default_factory=list) @@ -101,6 +104,8 @@ class Role: class Service: meta: ServiceMeta roles: dict[str, Role] + config: dict[str, Any] | None = None + imports: list[str] = field(default_factory=list) machines: dict[str, MachineServiceConfig] = field(default_factory=dict) @staticmethod @@ -116,6 +121,8 @@ class Service: if d.get("machines") else {} ), + config=d.get("config", None), + imports=d.get("imports", []), ) From 0bfba72739a5631092d9b5227ef7adaa7852c5de Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 17 Jul 2024 10:55:46 +0200 Subject: [PATCH 4/7] Inventory: fix options --- inventory.json | 4 ++-- lib/build-clan/default.nix | 4 ++-- lib/inventory/build-inventory/default.nix | 4 ++-- lib/inventory/build-inventory/interface.nix | 2 +- pkgs/clan-cli/clan_cli/inventory/__init__.py | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/inventory.json b/inventory.json index 021f9ab05..1ce2a79bf 100644 --- a/inventory.json +++ b/inventory.json @@ -11,8 +11,8 @@ "icon": "./path/to/icon.png", "tags": ["1", "2", "3"], "system": "x86_64-linux", - "deployment_info": { - "target_host": "root@remote.com" + "deploy": { + "targetHost": "root@remote.com" } } }, diff --git a/lib/build-clan/default.nix b/lib/build-clan/default.nix index 2b1921734..467971f77 100644 --- a/lib/build-clan/default.nix +++ b/lib/build-clan/default.nix @@ -89,7 +89,7 @@ let ]; inventoryPath = [ "system" ]; }) - # deploymentInfo.targetHost + # deploy.targetHost // (clanToInventory config { clanPath = [ "clan" @@ -98,7 +98,7 @@ let "targetHost" ]; inventoryPath = [ - "deploymentInfo" + "deploy" "targetHost" ]; }) diff --git a/lib/inventory/build-inventory/default.nix b/lib/inventory/build-inventory/default.nix index 9b1e3f3e5..1617d8f8c 100644 --- a/lib/inventory/build-inventory/default.nix +++ b/lib/inventory/build-inventory/default.nix @@ -148,8 +148,8 @@ let (lib.optionalAttrs (machineConfig.system or null != null) { config.nixpkgs.hostPlatform = machineConfig.system; }) - (lib.optionalAttrs (machineConfig.deploymentInfo.targetHost or null != null) { - config.clan.core.networking.targetHost = machineConfig.deploymentInfo.targetHost; + (lib.optionalAttrs (machineConfig.deploy.targetHost or null != null) { + config.clan.core.networking.targetHost = machineConfig.deploy.targetHost; }) ] ) inventory.machines or { }; diff --git a/lib/inventory/build-inventory/interface.nix b/lib/inventory/build-inventory/interface.nix index cc121c946..362bca5a2 100644 --- a/lib/inventory/build-inventory/interface.nix +++ b/lib/inventory/build-inventory/interface.nix @@ -49,7 +49,7 @@ in default = null; type = types.nullOr types.str; }; - deploymentInfo = lib.mkOption { + deploy = lib.mkOption { default = { }; type = types.submodule { options = { diff --git a/pkgs/clan-cli/clan_cli/inventory/__init__.py b/pkgs/clan-cli/clan_cli/inventory/__init__.py index 021efc70d..e1247034d 100644 --- a/pkgs/clan-cli/clan_cli/inventory/__init__.py +++ b/pkgs/clan-cli/clan_cli/inventory/__init__.py @@ -63,7 +63,7 @@ class Machine: tags: list[str] = field(default_factory=list) system: Literal["x86_64-linux"] | str | None = None - deployment_info: DeploymentInfo | None = None + deploy: DeploymentInfo | None = None @staticmethod def from_dict(d: dict[str, Any]) -> "Machine": @@ -73,8 +73,8 @@ class Machine: icon=d.get("icon", None), tags=d.get("tags", []), system=d.get("system", None), - deployment_info=DeploymentInfo( - target_host=d.get("deploymentInfo", {}).get("targetHost", None) + deploy=DeploymentInfo( + target_host=d.get("deploy", {}).get("targetHost", None) ), ) From 24b3674983acd4ae19d6933c057eef37d2dd2809 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 17 Jul 2024 11:32:36 +0200 Subject: [PATCH 5/7] Inventory: fix dataclasses discrepancy once more --- inventory.json | 44 ++++++++++---------- pkgs/clan-cli/clan_cli/inventory/__init__.py | 32 +++++++------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/inventory.json b/inventory.json index 1ce2a79bf..f984b63a9 100644 --- a/inventory.json +++ b/inventory.json @@ -7,13 +7,13 @@ "machines": { "test-inventory-machine": { "name": "foo", + "deploy": { + "targetHost": null + }, "description": "A nice thing", "icon": "./path/to/icon.png", "tags": ["1", "2", "3"], - "system": "x86_64-linux", - "deploy": { - "targetHost": "root@remote.com" - } + "system": "x86_64-linux" } }, "services": { @@ -26,14 +26,16 @@ }, "roles": { "default": { - "machines": ["test-inventory-machine"], - "tags": [], "config": { "packages": ["vim"] }, - "imports": [] + "imports": [], + "machines": ["test-inventory-machine"], + "tags": [] } }, + "config": {}, + "imports": [], "machines": { "test-inventory-machine": { "config": { @@ -41,9 +43,7 @@ }, "imports": [] } - }, - "config": null, - "imports": [] + } }, "browsing": { "meta": { @@ -53,12 +53,14 @@ }, "roles": { "default": { + "config": {}, + "imports": [], "machines": ["test-inventory-machine"], - "tags": [], - "config": null, - "imports": [] + "tags": [] } }, + "config": {}, + "imports": [], "machines": { "test-inventory-machine": { "config": { @@ -66,9 +68,7 @@ }, "imports": [] } - }, - "config": null, - "imports": [] + } } }, "single-disk": { @@ -80,12 +80,14 @@ }, "roles": { "default": { + "config": {}, + "imports": [], "machines": ["test-inventory-machine"], - "tags": [], - "config": null, - "imports": [] + "tags": [] } }, + "config": {}, + "imports": [], "machines": { "test-inventory-machine": { "config": { @@ -93,9 +95,7 @@ }, "imports": [] } - }, - "config": null, - "imports": [] + } } } } diff --git a/pkgs/clan-cli/clan_cli/inventory/__init__.py b/pkgs/clan-cli/clan_cli/inventory/__init__.py index e1247034d..95778b7e8 100644 --- a/pkgs/clan-cli/clan_cli/inventory/__init__.py +++ b/pkgs/clan-cli/clan_cli/inventory/__init__.py @@ -1,3 +1,5 @@ +# ruff: noqa: N815 +# ruff: noqa: N806 import json from dataclasses import asdict, dataclass, field, is_dataclass from pathlib import Path @@ -41,7 +43,7 @@ class DeploymentInfo: Deployment information for a machine. """ - target_host: str | None = None + targetHost: str | None = None @dataclass @@ -58,30 +60,28 @@ class Machine: """ name: str + deploy: DeploymentInfo = field(default_factory=DeploymentInfo) description: str | None = None icon: str | None = None tags: list[str] = field(default_factory=list) system: Literal["x86_64-linux"] | str | None = None - deploy: DeploymentInfo | None = None - @staticmethod - def from_dict(d: dict[str, Any]) -> "Machine": + def from_dict(data: dict[str, Any]) -> "Machine": + targetHost = data.get("deploy", {}).get("targetHost", None) return Machine( - name=d["name"], - description=d.get("description", None), - icon=d.get("icon", None), - tags=d.get("tags", []), - system=d.get("system", None), - deploy=DeploymentInfo( - target_host=d.get("deploy", {}).get("targetHost", None) - ), + name=data["name"], + description=data.get("description", None), + icon=data.get("icon", None), + tags=data.get("tags", []), + system=data.get("system", None), + deploy=DeploymentInfo(targetHost), ) @dataclass class MachineServiceConfig: - config: dict[str, Any] | None = None + config: dict[str, Any] = field(default_factory=dict) imports: list[str] = field(default_factory=list) @@ -94,7 +94,7 @@ class ServiceMeta: @dataclass class Role: - config: dict[str, Any] | None = None + config: dict[str, Any] = field(default_factory=dict) imports: list[str] = field(default_factory=list) machines: list[str] = field(default_factory=list) tags: list[str] = field(default_factory=list) @@ -104,7 +104,7 @@ class Role: class Service: meta: ServiceMeta roles: dict[str, Role] - config: dict[str, Any] | None = None + config: dict[str, Any] = field(default_factory=dict) imports: list[str] = field(default_factory=list) machines: dict[str, MachineServiceConfig] = field(default_factory=dict) @@ -121,7 +121,7 @@ class Service: if d.get("machines") else {} ), - config=d.get("config", None), + config=d.get("config", {}), imports=d.get("imports", []), ) From 076a5cad896617359ace1056eaee329e3324cb35 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 17 Jul 2024 12:06:23 +0200 Subject: [PATCH 6/7] Unit tests: fix template test - override the input in the flake template --- pkgs/clan-cli/tests/fixtures_flakes.py | 4 ++++ pkgs/clan-cli/tests/test_create_flake.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkgs/clan-cli/tests/fixtures_flakes.py b/pkgs/clan-cli/tests/fixtures_flakes.py index 336112811..ea43d070d 100644 --- a/pkgs/clan-cli/tests/fixtures_flakes.py +++ b/pkgs/clan-cli/tests/fixtures_flakes.py @@ -32,6 +32,10 @@ def substitute( line = line.replace( "git+https://git.clan.lol/clan/clan-core", str(clan_core_flake) ) + line = line.replace( + "https://git.clan.lol/clan/clan-core/archive/main.tar.gz", + str(clan_core_flake), + ) line = line.replace("__CLAN_SOPS_KEY_PATH__", sops_key) line = line.replace("__CLAN_SOPS_KEY_DIR__", str(flake)) print(line, end="") diff --git a/pkgs/clan-cli/tests/test_create_flake.py b/pkgs/clan-cli/tests/test_create_flake.py index ae09e79a6..db4c7c8ef 100644 --- a/pkgs/clan-cli/tests/test_create_flake.py +++ b/pkgs/clan-cli/tests/test_create_flake.py @@ -3,6 +3,7 @@ import subprocess from pathlib import Path import pytest +from fixtures_flakes import substitute from helpers import cli @@ -17,7 +18,15 @@ def test_create_flake( url = f"{clan_core}#default" cli.run(["flakes", "create", str(flake_dir), f"--url={url}"]) + assert (flake_dir / ".clan-flake").exists() + + # Replace the inputs.clan.url in the template flake.nix + substitute( + flake_dir / "flake.nix", + clan_core, + ) + monkeypatch.chdir(flake_dir) cli.run(["machines", "create", "machine1"]) capsys.readouterr() # flush cache @@ -55,6 +64,13 @@ def test_ui_template( flake_dir = temporary_home / "test-flake" url = f"{clan_core}#minimal" cli.run(["flakes", "create", str(flake_dir), f"--url={url}"]) + + # Replace the inputs.clan.url in the template flake.nix + substitute( + flake_dir / "flake.nix", + clan_core, + ) + monkeypatch.chdir(flake_dir) cli.run(["machines", "create", "machine1"]) capsys.readouterr() # flush cache From 69874a240586838288c1ea576c0b3f962961db4e Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 17 Jul 2024 12:12:42 +0200 Subject: [PATCH 7/7] Fix eval tests --- lib/inventory/tests/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/inventory/tests/default.nix b/lib/inventory/tests/default.nix index 2fda0e321..35e993b1f 100644 --- a/lib/inventory/tests/default.nix +++ b/lib/inventory/tests/default.nix @@ -85,9 +85,9 @@ not_used_machine = builtins.length configs.not_used_machine; }; expected = { - client_1_machine = 3; - client_2_machine = 3; - not_used_machine = 1; + client_1_machine = 4; + client_2_machine = 4; + not_used_machine = 2; }; };