2021-04-10 19:59:10 +02:00
|
|
|
{ pkgs-lib, pkgs, system, inputs, nixos, lib, ... }:
|
2021-03-14 08:10:51 +01:00
|
|
|
let
|
2021-04-10 19:59:10 +02:00
|
|
|
mkChecks = { hosts, nodes, homes ? { } }:
|
|
|
|
let
|
|
|
|
deployHosts = lib.filterAttrs
|
|
|
|
(n: _: hosts.${n}.config.nixpkgs.system == system)
|
|
|
|
nodes;
|
|
|
|
deployChecks = inputs.deploy.lib.${system}.deployChecks { nodes = deployHosts; };
|
|
|
|
tests =
|
|
|
|
{ libTests = libTests; }
|
|
|
|
// lib.optionalAttrs (deployHosts != { }) {
|
|
|
|
profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))});
|
2021-04-11 07:13:54 +02:00
|
|
|
} // lib.mapAttrs (n: v: v.activationPackage) homes;
|
2021-04-10 19:59:10 +02:00
|
|
|
|
|
|
|
in
|
|
|
|
lib.recursiveUpdate tests deployChecks;
|
2021-03-14 08:10:51 +01:00
|
|
|
|
2021-04-10 19:59:10 +02:00
|
|
|
mkTest = host:
|
2021-03-14 08:10:51 +01:00
|
|
|
let
|
|
|
|
nixosTesting =
|
2021-03-16 22:49:33 +01:00
|
|
|
(import "${nixos}/nixos/lib/testing-python.nix" {
|
2021-04-10 19:59:10 +02:00
|
|
|
inherit system;
|
|
|
|
inherit (host.config.lib) specialArgs;
|
2021-03-14 08:10:51 +01:00
|
|
|
inherit pkgs;
|
|
|
|
extraConfigurations = [
|
2021-04-10 19:59:10 +02:00
|
|
|
host.config.lib.testModule
|
2021-03-14 08:10:51 +01:00
|
|
|
];
|
|
|
|
});
|
|
|
|
in
|
|
|
|
test:
|
|
|
|
let
|
|
|
|
loadedTest =
|
|
|
|
if builtins.typeOf test == "path"
|
|
|
|
then import test
|
|
|
|
else test;
|
|
|
|
calledTest =
|
|
|
|
if pkgs.lib.isFunction loadedTest
|
|
|
|
then pkgs.callPackage loadedTest { }
|
|
|
|
else loadedTest;
|
|
|
|
in
|
|
|
|
nixosTesting.makeTest calledTest;
|
2021-04-10 19:59:10 +02:00
|
|
|
|
|
|
|
profilesTest = host: mkTest host {
|
2021-03-15 03:14:51 +01:00
|
|
|
name = "profiles";
|
2021-03-14 08:10:51 +01:00
|
|
|
|
2021-03-15 03:14:51 +01:00
|
|
|
machine = { suites, ... }: {
|
|
|
|
imports = suites.allProfiles ++ suites.allUsers;
|
2021-03-14 08:10:51 +01:00
|
|
|
};
|
|
|
|
|
2021-03-15 03:14:51 +01:00
|
|
|
testScript = ''
|
2021-04-24 09:08:49 +02:00
|
|
|
${host.config.networking.hostName}.systemctl("is-system-running --wait")
|
2021-03-14 08:10:51 +01:00
|
|
|
'';
|
|
|
|
};
|
2021-03-15 03:14:51 +01:00
|
|
|
|
|
|
|
libTests = pkgs.runCommandNoCC "devos-lib-tests"
|
|
|
|
{
|
|
|
|
buildInputs = [
|
|
|
|
pkgs.nix
|
|
|
|
(
|
2021-04-10 19:59:10 +02:00
|
|
|
let tests = pkgs-lib.callLibs ./lib.nix;
|
2021-03-15 03:14:51 +01:00
|
|
|
in
|
|
|
|
if tests == [ ]
|
|
|
|
then null
|
|
|
|
else throw (builtins.toJSON tests)
|
|
|
|
)
|
|
|
|
];
|
|
|
|
} ''
|
|
|
|
datadir="${pkgs.nix}/share"
|
|
|
|
export TEST_ROOT=$(pwd)/test-tmp
|
|
|
|
export NIX_BUILD_HOOK=
|
|
|
|
export NIX_CONF_DIR=$TEST_ROOT/etc
|
|
|
|
export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
|
|
|
|
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
|
|
|
|
export NIX_STATE_DIR=$TEST_ROOT/var/nix
|
|
|
|
export NIX_STORE_DIR=$TEST_ROOT/store
|
|
|
|
export PAGER=cat
|
|
|
|
cacheDir=$TEST_ROOT/binary-cache
|
|
|
|
nix-store --init
|
|
|
|
|
|
|
|
touch $out
|
|
|
|
'';
|
2021-04-10 19:59:10 +02:00
|
|
|
in
|
|
|
|
{ inherit mkTest libTests profilesTest mkChecks; }
|