Refactor tests to load flake inputs with flake-compat

This makes `nix fmt` just works and we no longer have to override flake
inputs.
This commit is contained in:
Jörg Thalheim
2025-08-17 11:20:09 +02:00
parent 2379bc4099
commit 4bafcc2454
10 changed files with 491 additions and 190 deletions

View File

@@ -2,7 +2,35 @@
description = "nixos-hardware";
outputs =
{ ... }:
{ self, ... }:
let
# Import private inputs (for development)
privateInputs =
(import ./tests/flake-compat.nix {
src = ./tests;
}).defaultNix;
systems = [
"aarch64-linux"
"riscv64-linux"
"x86_64-linux"
];
formatSystems = [ "aarch64-linux" "x86_64-linux" ];
# Helper to iterate over systems
eachSystem =
f:
privateInputs.nixos-unstable-small.lib.genAttrs systems (
system: f privateInputs.nixos-unstable-small.legacyPackages.${system} system
);
eachSystemFormat =
f:
privateInputs.nixos-unstable-small.lib.genAttrs formatSystems (
system: f privateInputs.nixos-unstable-small.legacyPackages.${system} system
);
in
{
nixosModules =
@@ -420,5 +448,40 @@
common-pc-laptop-ssd = import ./common/pc/ssd;
common-pc-ssd = import ./common/pc/ssd;
};
# Add formatter for `nix fmt`
formatter = eachSystemFormat (
pkgs: _system:
(privateInputs.treefmt-nix.lib.evalModule pkgs ./tests/treefmt.nix).config.build.wrapper
);
# Add packages
packages = eachSystem (
pkgs: _system: {
run-tests = pkgs.callPackage ./tests/run-tests.nix {
inherit self;
};
}
);
# Add checks for `nix run .#run-tests`
checks = eachSystem (
pkgs: system:
let
treefmtEval = privateInputs.treefmt-nix.lib.evalModule pkgs ./tests/treefmt.nix;
nixosTests = import ./tests/nixos-tests.nix {
inherit
self
privateInputs
system
pkgs
;
};
in
pkgs.lib.optionalAttrs (self.formatter ? ${system}) {
formatting = treefmtEval.config.build.check self;
}
// nixosTests
);
};
}