introduce flake parts module for clan nixos tests
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
self,
|
self,
|
||||||
inputs,
|
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
@@ -14,7 +13,7 @@ in
|
|||||||
wifi = module;
|
wifi = module;
|
||||||
};
|
};
|
||||||
perSystem =
|
perSystem =
|
||||||
{ pkgs, ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
1. Prepare the test vars
|
1. Prepare the test vars
|
||||||
@@ -23,15 +22,10 @@ in
|
|||||||
2. To run the test
|
2. To run the test
|
||||||
nix build .#checks.x86_64-linux.hello-service
|
nix build .#checks.x86_64-linux.hello-service
|
||||||
*/
|
*/
|
||||||
checks =
|
clan.nixosTests.wifi-service = {
|
||||||
# Currently we don't support nixos-integration tests on darwin
|
imports = [ ./tests/vm/default.nix ];
|
||||||
lib.optionalAttrs (pkgs.stdenv.isLinux) {
|
|
||||||
wifi-service = import ./tests/vm/default.nix {
|
clan.modules."@clan/wifi" = module;
|
||||||
inherit module;
|
|
||||||
inherit inputs pkgs;
|
|
||||||
clan-core = self;
|
|
||||||
nixosLib = import (self.inputs.nixpkgs + "/nixos/lib") { };
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,9 @@
|
|||||||
{
|
{
|
||||||
pkgs,
|
|
||||||
nixosLib,
|
|
||||||
clan-core,
|
|
||||||
module,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
nixosLib.runTest (
|
|
||||||
{ ... }:
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
clan-core.modules.nixosVmTest.clanTest
|
|
||||||
];
|
|
||||||
|
|
||||||
hostPkgs = pkgs;
|
|
||||||
|
|
||||||
name = "wifi-service";
|
name = "wifi-service";
|
||||||
|
|
||||||
clan = {
|
clan = {
|
||||||
directory = ./.;
|
directory = ./.;
|
||||||
test.useContainers = false;
|
test.useContainers = false;
|
||||||
modules."@clan/wifi" = module;
|
|
||||||
inventory = {
|
inventory = {
|
||||||
|
|
||||||
machines.test = { };
|
machines.test = { };
|
||||||
@@ -43,4 +27,3 @@ nixosLib.runTest (
|
|||||||
assert "password-eins" in psk, "Password is incorrect"
|
assert "password-eins" in psk, "Password is incorrect"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|||||||
@@ -71,6 +71,7 @@
|
|||||||
./flakeModules/demo_iso.nix
|
./flakeModules/demo_iso.nix
|
||||||
./lib/filter-clan-core/flake-module.nix
|
./lib/filter-clan-core/flake-module.nix
|
||||||
./lib/flake-module.nix
|
./lib/flake-module.nix
|
||||||
|
./lib/flake-parts/clan-nixos-test.nix
|
||||||
./nixosModules/clanCore/vars/flake-module.nix
|
./nixosModules/clanCore/vars/flake-module.nix
|
||||||
./nixosModules/flake-module.nix
|
./nixosModules/flake-module.nix
|
||||||
./pkgs/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