inventory test framework: init

Add nixos test module checks/lib/test-inventory-nix

accepts new option `inventory` and creates machines accordingly with correct imports
This commit is contained in:
DavHau
2025-03-31 13:39:23 +07:00
parent dcb2231332
commit d53b62170a
7 changed files with 116 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
test:
{ pkgs, self, ... }:
let
inherit (pkgs) lib;
inherit (lib) mkOption flip mapAttrs;
inherit (lib.types) raw;
inherit (self.lib.inventory) buildInventory;
nixos-lib = import (pkgs.path + "/nixos/lib") { };
in
(nixos-lib.runTest (
{ config, ... }:
{
imports = [ test ];
options = {
inventory = mkOption {
description = "Inventory of machines and services";
type = raw;
};
serviceConfigs = mkOption {
description = "Result of the evaluated inventory";
type = raw;
readOnly = true;
};
};
config = {
serviceConfigs = buildInventory {
inventory = config.inventory;
# TODO: make directory argument optional in buildInventory
directory = ./.;
};
nodes = flip mapAttrs config.serviceConfigs.machines (
_machineName: attrs: {
imports = attrs.machineImports ++ [ self.nixosModules.clanCore ];
clan.core.settings.directory = builtins.toString ./.;
}
);
hostPkgs = pkgs;
# speed-up evaluation
defaults = (
{ config, ... }:
{
imports = [
./minify.nix
];
documentation.enable = lib.mkDefault false;
nix.settings.min-free = 0;
system.stateVersion = config.system.nixos.release;
}
);
_module.args = { inherit self; };
# to accept external dependencies such as disko
node.specialArgs.self = self;
};
}
)).config.result