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