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:
56
checks/lib/test-inventory.nix
Normal file
56
checks/lib/test-inventory.nix
Normal 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
|
||||
Reference in New Issue
Block a user