devos/lib/pkgs-lib/tests/default.nix
Pacman99 eab0bf074c lib: one line for arguments, drop userFlake*
Also format all files and add a flake.lock for lib
for a folder thats meant to work on other flakes theres never a reason
it should need to refer to itself, only other flakes. So "self" and
"inputs" are better namings for these variables. The userFlake* is
redundant and confusing, when trying to call the functions its hard to
figure out how to use them when there are now two lines of arguments to
figure out.
2021-04-23 23:46:56 -07:00

55 lines
1.4 KiB
Nix

{ lib, nixpkgs, pkgs, deploy, system }:
let
mkChecks = { hosts, nodes, homes ? { } }:
let
deployHosts = lib.filterAttrs
(n: _: hosts.${n}.config.nixpkgs.system == system)
nodes;
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 =
(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; }