2021-04-10 17:59:10 +00:00
|
|
|
{ pkgs-lib, pkgs, system, inputs, nixos, lib, ... }:
|
2021-03-14 07:10:51 +00:00
|
|
|
let
|
2021-04-10 17:59:10 +00: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 05:13:54 +00:00
|
|
|
} // lib.mapAttrs (n: v: v.activationPackage) homes;
|
2021-04-10 17:59:10 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
lib.recursiveUpdate tests deployChecks;
|
2021-03-14 07:10:51 +00:00
|
|
|
|
2021-04-10 17:59:10 +00:00
|
|
|
mkTest = host:
|
2021-03-14 07:10:51 +00:00
|
|
|
let
|
|
|
|
nixosTesting =
|
2021-03-16 21:49:33 +00:00
|
|
|
(import "${nixos}/nixos/lib/testing-python.nix" {
|
2021-04-10 17:59:10 +00:00
|
|
|
inherit system;
|
|
|
|
inherit (host.config.lib) specialArgs;
|
2021-03-14 07:10:51 +00:00
|
|
|
inherit pkgs;
|
|
|
|
extraConfigurations = [
|
2021-04-10 17:59:10 +00:00
|
|
|
host.config.lib.testModule
|
2021-03-14 07:10:51 +00: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 17:59:10 +00:00
|
|
|
|
|
|
|
profilesTest = host: mkTest host {
|
2021-03-15 02:14:51 +00:00
|
|
|
name = "profiles";
|
2021-03-14 07:10:51 +00:00
|
|
|
|
2021-03-15 02:14:51 +00:00
|
|
|
machine = { suites, ... }: {
|
|
|
|
imports = suites.allProfiles ++ suites.allUsers;
|
2021-03-14 07:10:51 +00:00
|
|
|
};
|
|
|
|
|
2021-03-15 02:14:51 +00:00
|
|
|
testScript = ''
|
2021-04-24 07:08:49 +00:00
|
|
|
${host.config.networking.hostName}.systemctl("is-system-running --wait")
|
2021-03-14 07:10:51 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-03-15 02:14:51 +00:00
|
|
|
|
|
|
|
libTests = pkgs.runCommandNoCC "devos-lib-tests"
|
|
|
|
{
|
|
|
|
buildInputs = [
|
|
|
|
pkgs.nix
|
|
|
|
(
|
2021-04-10 17:59:10 +00:00
|
|
|
let tests = pkgs-lib.callLibs ./lib.nix;
|
2021-03-15 02:14:51 +00: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 17:59:10 +00:00
|
|
|
in
|
|
|
|
{ inherit mkTest libTests profilesTest mkChecks; }
|