pub-solar-os/lib/pkgs-lib/tests/default.nix

55 lines
1.4 KiB
Nix
Raw Normal View History

2021-04-18 01:46:20 +00:00
{ pkgs, system, deploy, nixpkgs, lib, ... }:
let
mkChecks = { hosts, nodes, homes ? { } }:
let
deployHosts = lib.filterAttrs
(n: _: hosts.${n}.config.nixpkgs.system == system)
nodes;
2021-04-18 01:46:20 +00:00
deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; };
tests =
lib.optionalAttrs (deployHosts != { }) {
profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))});
} // lib.mapAttrs (n: v: v.activationPackage) homes;
in
lib.recursiveUpdate tests deployChecks;
mkTest = host:
let
nixosTesting =
2021-04-02 02:10:24 +00:00
(import "${nixpkgs}/nixos/lib/testing-python.nix" {
inherit system;
inherit (host.config.lib) specialArgs;
inherit pkgs;
extraConfigurations = [
host.config.lib.testModule
];
});
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;
profilesTest = host: mkTest host {
name = "profiles";
machine = { suites, ... }: {
imports = suites.allProfiles ++ suites.allUsers;
};
testScript = ''
machine.systemctl("is-system-running --wait")
'';
};
in
{ inherit mkTest profilesTest mkChecks; }