introduce flake parts module for clan nixos tests
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
{
|
||||
self,
|
||||
inputs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
@@ -14,7 +13,7 @@ in
|
||||
wifi = module;
|
||||
};
|
||||
perSystem =
|
||||
{ pkgs, ... }:
|
||||
{ ... }:
|
||||
{
|
||||
/**
|
||||
1. Prepare the test vars
|
||||
@@ -23,15 +22,10 @@ in
|
||||
2. To run the test
|
||||
nix build .#checks.x86_64-linux.hello-service
|
||||
*/
|
||||
checks =
|
||||
# Currently we don't support nixos-integration tests on darwin
|
||||
lib.optionalAttrs (pkgs.stdenv.isLinux) {
|
||||
wifi-service = import ./tests/vm/default.nix {
|
||||
inherit module;
|
||||
inherit inputs pkgs;
|
||||
clan-core = self;
|
||||
nixosLib = import (self.inputs.nixpkgs + "/nixos/lib") { };
|
||||
};
|
||||
};
|
||||
clan.nixosTests.wifi-service = {
|
||||
imports = [ ./tests/vm/default.nix ];
|
||||
|
||||
clan.modules."@clan/wifi" = module;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,46 +1,29 @@
|
||||
{
|
||||
pkgs,
|
||||
nixosLib,
|
||||
clan-core,
|
||||
module,
|
||||
...
|
||||
}:
|
||||
nixosLib.runTest (
|
||||
{ ... }:
|
||||
{
|
||||
imports = [
|
||||
clan-core.modules.nixosVmTest.clanTest
|
||||
];
|
||||
name = "wifi-service";
|
||||
|
||||
hostPkgs = pkgs;
|
||||
clan = {
|
||||
directory = ./.;
|
||||
test.useContainers = false;
|
||||
inventory = {
|
||||
|
||||
name = "wifi-service";
|
||||
machines.test = { };
|
||||
|
||||
clan = {
|
||||
directory = ./.;
|
||||
test.useContainers = false;
|
||||
modules."@clan/wifi" = module;
|
||||
inventory = {
|
||||
instances = {
|
||||
wg-test-one = {
|
||||
module.name = "@clan/wifi";
|
||||
|
||||
machines.test = { };
|
||||
|
||||
instances = {
|
||||
wg-test-one = {
|
||||
module.name = "@clan/wifi";
|
||||
|
||||
roles.default.machines = {
|
||||
test.settings.networks.one = { };
|
||||
};
|
||||
roles.default.machines = {
|
||||
test.settings.networks.one = { };
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
start_all()
|
||||
test.wait_for_unit("NetworkManager.service")
|
||||
psk = test.succeed("cat /run/NetworkManager/system-connections/one.nmconnection")
|
||||
assert "password-eins" in psk, "Password is incorrect"
|
||||
'';
|
||||
}
|
||||
)
|
||||
testScript = ''
|
||||
start_all()
|
||||
test.wait_for_unit("NetworkManager.service")
|
||||
psk = test.succeed("cat /run/NetworkManager/system-connections/one.nmconnection")
|
||||
assert "password-eins" in psk, "Password is incorrect"
|
||||
'';
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@
|
||||
./flakeModules/demo_iso.nix
|
||||
./lib/filter-clan-core/flake-module.nix
|
||||
./lib/flake-module.nix
|
||||
./lib/flake-parts/clan-nixos-test.nix
|
||||
./nixosModules/clanCore/vars/flake-module.nix
|
||||
./nixosModules/flake-module.nix
|
||||
./pkgs/flake-module.nix
|
||||
|
||||
90
lib/flake-parts/clan-nixos-test.nix
Normal file
90
lib/flake-parts/clan-nixos-test.nix
Normal file
@@ -0,0 +1,90 @@
|
||||
{
|
||||
lib,
|
||||
flake-parts-lib,
|
||||
self,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib)
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
inherit (flake-parts-lib)
|
||||
mkPerSystemOption
|
||||
;
|
||||
nixosLib = import (inputs.nixpkgs + "/nixos/lib") { };
|
||||
in
|
||||
{
|
||||
options = {
|
||||
perSystem = mkPerSystemOption (
|
||||
{ config, pkgs, ... }:
|
||||
let
|
||||
cfg = config.clan.nixosTests;
|
||||
in
|
||||
{
|
||||
options.clan.nixosTests = mkOption {
|
||||
description = "Clan NixOS tests configuration";
|
||||
type = types.attrsOf types.unspecified;
|
||||
default = { };
|
||||
};
|
||||
|
||||
config.checks = lib.optionalAttrs (pkgs.stdenv.isLinux) (
|
||||
let
|
||||
# Build all individual vars-check derivations
|
||||
varsChecks = lib.mapAttrs' (
|
||||
name: testModule:
|
||||
lib.nameValuePair "vars-check-${name}" (
|
||||
let
|
||||
test = nixosLib.runTest (
|
||||
{ ... }:
|
||||
{
|
||||
imports = [
|
||||
self.modules.nixosVmTest.clanTest
|
||||
testModule
|
||||
];
|
||||
|
||||
hostPkgs = pkgs;
|
||||
}
|
||||
);
|
||||
in
|
||||
test.config.result.vars-check
|
||||
)
|
||||
) cfg;
|
||||
in
|
||||
lib.mkMerge [
|
||||
# Add the VM tests as checks
|
||||
(lib.mapAttrs (
|
||||
_name: testModule:
|
||||
nixosLib.runTest (
|
||||
{ ... }:
|
||||
{
|
||||
imports = [
|
||||
self.modules.nixosVmTest.clanTest
|
||||
testModule
|
||||
];
|
||||
|
||||
hostPkgs = pkgs;
|
||||
}
|
||||
)
|
||||
) cfg)
|
||||
|
||||
# Add a single vars-check that depends on all others XXX if we ever
|
||||
# optimize buildbot to perform better with many builds we can
|
||||
# remove this and just run the individual vars-checks to speed up
|
||||
# parallel evaluation.
|
||||
(lib.optionalAttrs (varsChecks != {}) {
|
||||
vars-check = pkgs.runCommand "vars-check-all" {
|
||||
buildInputs = lib.attrValues varsChecks;
|
||||
} ''
|
||||
echo "All vars checks passed:"
|
||||
${lib.concatMapStringsSep "\n" (name: "echo ' ✓ ${name}'") (lib.attrNames varsChecks)}
|
||||
touch $out
|
||||
'';
|
||||
})
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user