tests(clan): move test-inventory.nix to clanLib. And name it 'makeTestClan'
Exposing the function via clanLib makes it more accessible to clan modules This allows each module to define its own test without needing to depend on any fileSystem path assumptions in the clan-core repo
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
(import ../lib/test-inventory.nix) (
|
||||
{
|
||||
pkgs,
|
||||
self,
|
||||
clanLib,
|
||||
...
|
||||
}:
|
||||
clanLib.test.makeTestClan {
|
||||
inherit pkgs self;
|
||||
nixosTest = (
|
||||
{ lib, ... }:
|
||||
let
|
||||
|
||||
machines = [
|
||||
"admin"
|
||||
"peer"
|
||||
@@ -75,4 +82,5 @@
|
||||
})
|
||||
'';
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
(import ../lib/test-inventory.nix) (
|
||||
{
|
||||
pkgs,
|
||||
self,
|
||||
clanLib,
|
||||
...
|
||||
}:
|
||||
clanLib.test.makeTestClan {
|
||||
inherit pkgs self;
|
||||
nixosTest = (
|
||||
{ ... }:
|
||||
{
|
||||
# This tests the compatibility of the inventory
|
||||
@@ -64,4 +72,5 @@
|
||||
peer1.succeed("cat ${nodes.peer1.clan.core.vars.generators.new-service.files.hello.path}")
|
||||
'';
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,9 +27,10 @@ in
|
||||
let
|
||||
nixosTestArgs = {
|
||||
# reference to nixpkgs for the current system
|
||||
inherit pkgs;
|
||||
inherit pkgs lib;
|
||||
# this gives us a reference to our flake but also all flake inputs
|
||||
inherit self;
|
||||
inherit (self) clanLib;
|
||||
};
|
||||
nixosTests = lib.optionalAttrs (pkgs.stdenv.isLinux) {
|
||||
# import our test
|
||||
|
||||
@@ -99,7 +99,7 @@ in
|
||||
imports = [
|
||||
(modulesPath + "/testing/test-instrumentation.nix") # we need these 2 modules always to be able to run the tests
|
||||
(modulesPath + "/profiles/qemu-guest.nix")
|
||||
../lib/minify.nix
|
||||
self.clanLib.test.minifyModule
|
||||
];
|
||||
|
||||
networking.hostName = "test-install-machine";
|
||||
|
||||
@@ -13,7 +13,7 @@ in
|
||||
{ config, options, ... }:
|
||||
{
|
||||
imports = [
|
||||
./minify.nix
|
||||
self.clanLib.test.minifyModule
|
||||
];
|
||||
config = lib.mkMerge [
|
||||
(lib.optionalAttrs (options ? clan) {
|
||||
|
||||
@@ -11,7 +11,7 @@ in
|
||||
{ config, options, ... }:
|
||||
{
|
||||
imports = [
|
||||
./minify.nix
|
||||
self.clanLib.test.minifyModule
|
||||
];
|
||||
config = lib.mkMerge [
|
||||
(lib.optionalAttrs (options ? clan) {
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
test:
|
||||
{ pkgs, self, ... }:
|
||||
let
|
||||
inherit (pkgs) lib;
|
||||
inherit (lib)
|
||||
mkOption
|
||||
flip
|
||||
mapAttrs
|
||||
types
|
||||
;
|
||||
nixos-lib = import (pkgs.path + "/nixos/lib") { };
|
||||
in
|
||||
(nixos-lib.runTest (
|
||||
{ config, ... }:
|
||||
let
|
||||
clanFlakeResult = config.clan;
|
||||
in
|
||||
{
|
||||
imports = [ test ];
|
||||
options = {
|
||||
clanSettings = mkOption {
|
||||
default = { };
|
||||
type = types.submodule {
|
||||
options = {
|
||||
clan-core = mkOption { default = self; };
|
||||
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
|
||||
nixpkgs
|
||||
nix-darwin
|
||||
;
|
||||
};
|
||||
modules = [
|
||||
self.clanLib.buildClanModule.flakePartsModule
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
config = {
|
||||
nodes = flip mapAttrs clanFlakeResult.clanInternals.inventoryClass.machines (
|
||||
machineName: attrs: {
|
||||
imports = attrs.machineImports ++ [ self.nixosModules.clanCore ];
|
||||
clan.core.settings.directory = "${config.clan.directory}";
|
||||
clan.core.settings.machine.name = machineName;
|
||||
}
|
||||
);
|
||||
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;
|
||||
boot.initrd.systemd.enable = false;
|
||||
|
||||
# setup for sops
|
||||
sops.age.keyFile = "/run/age-key.txt";
|
||||
system.activationScripts =
|
||||
{
|
||||
setupSecrets.deps = [ "age-key" ];
|
||||
age-key.text = ''
|
||||
echo AGE-SECRET-KEY-1PL0M9CWRCG3PZ9DXRTTLMCVD57U6JDFE8K7DNVQ35F4JENZ6G3MQ0RQLRV > /run/age-key.txt
|
||||
'';
|
||||
}
|
||||
// lib.optionalAttrs (lib.filterAttrs (_: v: v.neededForUsers) config.sops.secrets != { }) {
|
||||
setupSecretsForUsers.deps = [ "age-key" ];
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
_module.args = { inherit self; };
|
||||
# to accept external dependencies such as disko
|
||||
node.specialArgs.self = self;
|
||||
};
|
||||
}
|
||||
)).config.result
|
||||
@@ -25,6 +25,7 @@ lib.fix (clanLib: {
|
||||
buildClanModule = clanLib.callLib ./build-clan { };
|
||||
inventory = clanLib.callLib ./inventory { };
|
||||
modules = clanLib.callLib ./inventory/frontmatter { };
|
||||
test = clanLib.callLib ./tests { };
|
||||
|
||||
# Plain imports.
|
||||
values = import ./introspection { inherit lib; };
|
||||
|
||||
92
lib/tests/default.nix
Normal file
92
lib/tests/default.nix
Normal file
@@ -0,0 +1,92 @@
|
||||
{ lib, clanLib }:
|
||||
let
|
||||
inherit (lib)
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
in
|
||||
{
|
||||
minifyModule = ./minify.nix;
|
||||
# A function that returns an extension to runTest
|
||||
makeTestClan =
|
||||
{
|
||||
nixosTest,
|
||||
pkgs,
|
||||
self,
|
||||
...
|
||||
}:
|
||||
let
|
||||
nixos-lib = import (pkgs.path + "/nixos/lib") { };
|
||||
in
|
||||
(nixos-lib.runTest (
|
||||
{ config, ... }:
|
||||
let
|
||||
clanFlakeResult = config.clan;
|
||||
in
|
||||
{
|
||||
imports = [ nixosTest ];
|
||||
options = {
|
||||
clanSettings = mkOption {
|
||||
default = { };
|
||||
type = types.submodule {
|
||||
options = {
|
||||
clan-core = mkOption { default = self; };
|
||||
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
|
||||
nixpkgs
|
||||
nix-darwin
|
||||
;
|
||||
};
|
||||
modules = [
|
||||
clanLib.buildClanModule.flakePartsModule
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
config = {
|
||||
nodes = clanFlakeResult.clanInternals.nixosModules;
|
||||
hostPkgs = pkgs;
|
||||
# speed-up evaluation
|
||||
defaults = (
|
||||
{ config, ... }:
|
||||
{
|
||||
imports = [
|
||||
clanLib.test.minifyModule
|
||||
];
|
||||
documentation.enable = lib.mkDefault false;
|
||||
nix.settings.min-free = 0;
|
||||
system.stateVersion = config.system.nixos.release;
|
||||
boot.initrd.systemd.enable = false;
|
||||
|
||||
# setup for sops
|
||||
sops.age.keyFile = "/run/age-key.txt";
|
||||
system.activationScripts =
|
||||
{
|
||||
setupSecrets.deps = [ "age-key" ];
|
||||
age-key.text = ''
|
||||
echo AGE-SECRET-KEY-1PL0M9CWRCG3PZ9DXRTTLMCVD57U6JDFE8K7DNVQ35F4JENZ6G3MQ0RQLRV > /run/age-key.txt
|
||||
'';
|
||||
}
|
||||
// lib.optionalAttrs (lib.filterAttrs (_: v: v.neededForUsers) config.sops.secrets != { }) {
|
||||
setupSecretsForUsers.deps = [ "age-key" ];
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
# to accept external dependencies such as disko
|
||||
_module.args = { inherit self; };
|
||||
node.specialArgs.self = self;
|
||||
};
|
||||
}
|
||||
)).config.result;
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
# This is a module to reduce the size of the NixOS configuration
|
||||
# Used by the tests
|
||||
# It unsets some unnecessary options
|
||||
{ lib, ... }:
|
||||
{
|
||||
nixpkgs.flake.setFlakeRegistry = false;
|
||||
Reference in New Issue
Block a user