chore(checks/inventory): doogfood 'clan' flake-parts module into the test, instead of custom inventory logic

This commit is contained in:
Johannes Kirschbauer
2025-04-11 13:47:20 +02:00
parent f94e3a20a4
commit 762cc5e7cb
2 changed files with 78 additions and 48 deletions

View File

@@ -7,8 +7,11 @@
# - clan.service modules
name = "dummy-inventory-test";
inventory.directory = ./.;
inventory.inventory = {
clanSettings = {
self = ./.;
};
clan = {
inventory = {
machines.peer1 = { };
machines.admin1 = { };
services = {
@@ -47,6 +50,7 @@
};
};
};
};
testScript =
{ nodes, ... }:

View File

@@ -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; };
};
};
};
clan = mkOption {
default = { };
type = types.submoduleWith {
specialArgs = {
inherit (config.clanSettings)
clan-core
self
nixpkgs
nix-darwin
;
};
modules = [
self.clanLib.buildClanModule.flakePartsModule
];
};
inventory.directory = mkOption {
description = "Directory which contains the vars";
type = path;
};
};
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