Merge pull request 'checks: introduce check.<system> for faster local checks' (#4155) from dave into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4155
This commit is contained in:
DavHau
2025-06-30 13:08:33 +00:00
79 changed files with 113 additions and 80 deletions

View File

@@ -151,8 +151,8 @@
in
{
checks = pkgs.lib.mkIf pkgs.stdenv.isLinux {
backups = self.clanLib.test.containerTest {
name = "backups";
nixos-test-backups = self.clanLib.test.containerTest {
name = "nixos-test-backups";
nodes.machine = {
imports =
[

View File

@@ -13,7 +13,7 @@ nixosLib.runTest (
hostPkgs = pkgs;
name = "borgbackup";
name = "service-borgbackup";
clan = {
directory = ./.;

View File

@@ -20,7 +20,7 @@ nixosLib.runTest (
];
hostPkgs = pkgs;
name = "data-mesher";
name = "service-data-mesher";
clan = {
directory = ./.;

View File

@@ -1,7 +1,19 @@
{ self, lib, ... }:
{
self,
lib,
inputs,
...
}:
let
inherit (lib)
attrNames
attrValues
elem
filter
filterAttrs
flip
genAttrs
hasPrefix
pathExists
;
nixosLib = import (self.inputs.nixpkgs + "/nixos/lib") { };
@@ -19,6 +31,33 @@ in
./nixos-documentation/flake-module.nix
./dont-depend-on-repo-root.nix
];
flake.check = genAttrs [ "x86_64-linux" "aarch64-darwin" ] (
system:
let
checks = flip filterAttrs self.checks.${system} (
name: _check:
!(hasPrefix "nixos-test-" name)
&& !(hasPrefix "nixos-" name)
&& !(hasPrefix "darwin-test-" name)
&& !(hasPrefix "service-" name)
&& !(hasPrefix "vars-check-" name)
&& !(hasPrefix "devShell-" name)
&& !(elem name [
"clan-core-for-checks"
"clan-deps"
])
);
in
inputs.nixpkgs.legacyPackages.${system}.runCommand "fast-flake-checks-${system}"
{ passthru.checks = checks; }
''
echo "Executed the following checks for ${system}..."
echo " - ${lib.concatStringsSep "\n" (map (n: " - " + n) (attrNames checks))}"
echo ${toString (attrValues checks)} >/dev/null
echo "All checks succeeded"
touch $out
''
);
perSystem =
{
pkgs,
@@ -41,21 +80,21 @@ in
nixosTests = lib.optionalAttrs (pkgs.stdenv.isLinux) {
# Base Tests
secrets = self.clanLib.test.baseTest ./secrets nixosTestArgs;
borgbackup-legacy = self.clanLib.test.baseTest ./borgbackup-legacy nixosTestArgs;
wayland-proxy-virtwl = self.clanLib.test.baseTest ./wayland-proxy-virtwl nixosTestArgs;
nixos-test-secrets = self.clanLib.test.baseTest ./secrets nixosTestArgs;
nixos-test-borgbackup-legacy = self.clanLib.test.baseTest ./borgbackup-legacy nixosTestArgs;
nixos-test-wayland-proxy-virtwl = self.clanLib.test.baseTest ./wayland-proxy-virtwl nixosTestArgs;
# Container Tests
container = self.clanLib.test.containerTest ./container nixosTestArgs;
zt-tcp-relay = self.clanLib.test.containerTest ./zt-tcp-relay nixosTestArgs;
matrix-synapse = self.clanLib.test.containerTest ./matrix-synapse nixosTestArgs;
postgresql = self.clanLib.test.containerTest ./postgresql nixosTestArgs;
user-firewall-iptables = self.clanLib.test.containerTest ./user-firewall/iptables.nix nixosTestArgs;
user-firewall-nftables = self.clanLib.test.containerTest ./user-firewall/nftables.nix nixosTestArgs;
nixos-test-container = self.clanLib.test.containerTest ./container nixosTestArgs;
nixos-test-zt-tcp-relay = self.clanLib.test.containerTest ./zt-tcp-relay nixosTestArgs;
nixos-test-matrix-synapse = self.clanLib.test.containerTest ./matrix-synapse nixosTestArgs;
nixos-test-postgresql = self.clanLib.test.containerTest ./postgresql nixosTestArgs;
nixos-test-user-firewall-iptables = self.clanLib.test.containerTest ./user-firewall/iptables.nix nixosTestArgs;
nixos-test-user-firewall-nftables = self.clanLib.test.containerTest ./user-firewall/nftables.nix nixosTestArgs;
dummy-inventory-test = import ./dummy-inventory-test nixosTestArgs;
dummy-inventory-test-from-flake = import ./dummy-inventory-test-from-flake nixosTestArgs;
data-mesher = import ./data-mesher nixosTestArgs;
service-dummy-test = import ./service-dummy-test nixosTestArgs;
service-dummy-test-from-flake = import ./service-dummy-test-from-flake nixosTestArgs;
service-data-mesher = import ./data-mesher nixosTestArgs;
};
packagesToBuild = lib.removeAttrs self'.packages [
@@ -128,10 +167,10 @@ in
in
lib.optionalAttrs (pkgs.stdenv.isLinux) {
# import our test
secrets = import ./secrets nixosTestArgs;
container = import ./container nixosTestArgs;
nixos-test-secrets = import ./secrets nixosTestArgs;
nixos-test-container = import ./container nixosTestArgs;
# Clan app tests
app-ocr = self.clanLib.test.baseTest ./app-ocr nixosTestArgs;
nixos-test-app-ocr = self.clanLib.test.baseTest ./app-ocr nixosTestArgs;
};
};
};

View File

@@ -57,7 +57,7 @@
in
{
checks = pkgs.lib.mkIf pkgs.stdenv.isLinux {
flash = self.clanLib.test.baseTest {
nixos-test-flash = self.clanLib.test.baseTest {
name = "flash";
nodes.target = {
virtualisation.emptyDiskImages = [ 4096 ];

View File

@@ -183,7 +183,7 @@ in
# vm-test-run-test-installation-> target: Guest root shell did not produce any data yet...
# vm-test-run-test-installation-> target: To debug, enter the VM and run 'systemctl status backdoor.service'.
checks = pkgs.lib.mkIf (pkgs.stdenv.isLinux && !pkgs.stdenv.isAarch64) {
installation = self.clanLib.test.baseTest {
nixos-test-installation = self.clanLib.test.baseTest {
name = "installation";
nodes.target = {
services.openssh.enable = true;
@@ -210,7 +210,7 @@ in
'';
} { inherit pkgs self; };
update-hardware-configuration = self.clanLib.test.baseTest {
nixos-test-update-hardware-configuration = self.clanLib.test.baseTest {
name = "update-hardware-configuration";
nodes.installer = installer;

View File

@@ -24,7 +24,7 @@
}:
{
checks = pkgs.lib.mkIf (pkgs.stdenv.isLinux && !pkgs.stdenv.isAarch64) {
morph = self.clanLib.test.baseTest {
nixos-test-morph = self.clanLib.test.baseTest {
name = "morph";
nodes = {

View File

@@ -13,7 +13,7 @@ nixosLib.runTest (
hostPkgs = pkgs;
name = "mycelium";
name = "service-mycelium";
clan = {

View File

@@ -18,7 +18,7 @@ nixosLib.runTest (
# With the test framework
# - legacy-modules
# - clan.service modules
name = "dummy-inventory-test-from-flake";
name = "service-dummy-test-from-flake";
clan.test.fromFlake = ./.;

View File

@@ -40,7 +40,7 @@
perMachine = {
nixosModule = {
# This should be generated by:
# nix run .#generate-test-vars -- checks/dummy-inventory-test dummy-inventory-test
# nix run .#generate-test-vars -- checks/service-dummy-test service-dummy-test
clan.core.vars.generators.new-service = {
files.not-a-secret = {
secret = false;

View File

@@ -17,7 +17,7 @@ nixosLib.runTest (
# With the test framework
# - legacy-modules
# - clan.service modules
name = "dummy-inventory-test";
name = "service-dummy-test";
clan = {
directory = ./.;
@@ -48,7 +48,7 @@ nixosLib.runTest (
perMachine = {
nixosModule = {
# This should be generated by:
# nix run .#generate-test-vars -- checks/dummy-inventory-test dummy-inventory-test
# nix run .#generate-test-vars -- checks/service-dummy-test service-dummy-test
clan.core.vars.generators.new-service = {
files.not-a-secret = {
secret = false;

View File

@@ -14,7 +14,7 @@ nixosLib.runTest (
hostPkgs = pkgs;
name = "syncthing";
name = "service-syncthing";
clan = {
directory = ./.;

View File

@@ -2,7 +2,7 @@ let
public-key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAII6zj7ubTg6z/aDwRNwvM/WlQdUocMprQ8E92NWxl6t+ test@test";
in
{
name = "admin";
name = "service-admin";
clan = {
directory = ./.;

View File

@@ -1,10 +1,9 @@
{
module,
pkgs,
...
}:
{
name = "borgbackup";
name = "service-borgbackup";
clan = {
directory = ./.;

View File

@@ -1,10 +1,9 @@
{
module,
pkgs,
...
}:
{
name = "garage";
name = "service-garage";
clan = {
directory = ./.;

View File

@@ -1,9 +1,5 @@
{
module,
...
}:
{
name = "hello-service";
name = "service-hello-service";
clan = {
directory = ./.;

View File

@@ -1,10 +1,9 @@
{
module,
pkgs,
...
}:
{
name = "mycelium";
name = "service-mycelium";
clan = {

View File

@@ -1,5 +1,5 @@
{
name = "packages";
name = "service-packages";
clan = {
directory = ./.;

View File

@@ -1,10 +1,9 @@
{
module,
pkgs,
...
}:
{
name = "sshd";
name = "service-sshd";
clan = {
directory = ./.;

View File

@@ -1,5 +1,5 @@
{
name = "trusted-nix-caches";
name = "service-trusted-nix-caches";
clan = {
directory = ./.;

View File

@@ -1,5 +1,5 @@
{
name = "users";
name = "service-users";
clan = {
directory = ./.;

View File

@@ -1,5 +1,5 @@
{
name = "wifi";
name = "service-wifi";
clan = {
directory = ./.;

View File

@@ -1,5 +1,5 @@
{
name = "zerotier";
name = "service-zerotier";
clan = {
directory = ./.;

View File

@@ -234,16 +234,16 @@ Failing nix eval tests look like this:
> error: Tests failed
```
To locate the definition, find the flake attribute name of the failing test near the top of the CI Job page, like for example `gitea:clan/clan-core#checks.x86_64-linux.lib-values-eval/1242`.
To locate the definition, find the flake attribute name of the failing test near the top of the CI Job page, like for example `gitea:clan/clan-core#checks.x86_64-linux.eval-lib-values/1242`.
In this case `lib-values-eval` is the attribute we are looking for.
In this case `eval-lib-values` is the attribute we are looking for.
Find the attribute via ripgrep:
```shellSession
$ rg "lib-values-eval ="
$ rg "eval-lib-values ="
lib/values/flake-module.nix
21: lib-values-eval = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
21: eval-lib-values = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
grmpf@grmpf-nix ~/p/c/clan-core (test-docs)>
```

View File

@@ -62,8 +62,9 @@ in
in
lib.mkMerge [
# Add the VM tests as checks
(lib.mapAttrs (
_name: testModule:
(lib.mapAttrs' (
name: testModule:
lib.nameValuePair "service-${name}" (
nixosLib.runTest (
{ ... }:
{
@@ -83,6 +84,7 @@ in
};
}
)
)
) cfg)
varsChecks

View File

@@ -18,7 +18,7 @@ in
{
legacyPackages.evalTests-values = tests;
checks = {
lib-values-eval = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
eval-lib-values = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
export HOME="$(realpath .)"
nix-unit --eval-store "$HOME" \
--extra-experimental-features flakes \

View File

@@ -36,7 +36,7 @@ in
buildClan = self.clanLib.buildClan;
};
checks = {
lib-build-clan-eval = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
eval-lib-build-clan = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
export HOME="$(realpath .)"
nix-unit --eval-store "$HOME" \

View File

@@ -20,7 +20,7 @@ in
};
checks = {
lib-distributedServices-eval = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
eval-lib-distributedServices = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
export HOME="$(realpath .)"
nix-unit --eval-store "$HOME" \
--extra-experimental-features flakes \

View File

@@ -26,7 +26,7 @@ in
devShells.inventory-schema = pkgs.mkShell {
name = "clan-inventory-schema";
inputsFrom = with config.checks; [
lib-inventory-eval
eval-lib-inventory
self'.devShells.default
];
};
@@ -62,7 +62,7 @@ in
};
checks = {
lib-inventory-eval = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
eval-lib-inventory = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
export HOME="$(realpath .)"
export NIX_ABORT_ON_WARN=1
nix-unit --eval-store "$HOME" \

View File

@@ -5,7 +5,7 @@
{
clan.nixosTests.machine-id = {
name = "machine-id";
name = "service-machine-id";
clan = {
directory = ./.;

View File

@@ -5,7 +5,7 @@
{
clan.nixosTests.state-version = {
name = "state-version";
name = "service-state-version";
clan = {
directory = ./.;

View File

@@ -18,7 +18,7 @@ in
clan-core = self;
pkgs = inputs.nixpkgs.legacyPackages.${system};
};
checks.module-clan-vars-eval = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
checks.eval-module-clan-vars = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
export HOME="$(realpath .)"
nix-unit --eval-store "$HOME" \

View File

@@ -78,6 +78,6 @@ in
};
};
flake.checks.x86_64-linux.flash-installer-disk-test =
flake.checks.x86_64-linux.nixos-test-flash-installer-disk =
self.nixosConfigurations.flash-installer.config.system.build.installTest;
}