Skip to content

Commit 93d25a2

Browse files
committed
Refactor tests to load flake inputs with flake-compat
This makes `nix fmt` just works and we no longer have to override flake inputs.
1 parent 26ed7a0 commit 93d25a2

File tree

11 files changed

+490
-209
lines changed

11 files changed

+490
-209
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v4
1313
- uses: cachix/install-nix-action@v31
14-
- run: cd tests && nix fmt .. -- --fail-on-change
14+
- run: nix build .#checks.x86_64-linux.formatting
1515
tests:
1616
needs: nixfmt
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v4
2020
- uses: cachix/install-nix-action@v31
21-
- run: nix run ./tests#run .
21+
- run: nix run .#run-tests

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Link the profile in the table in README.md and in flake.nix.
4242

4343
## 3. Testing
4444

45-
Run `nix run ./tests#run .` to evaluate all hardware profiles.
45+
Run `nix run .#run-tests` to evaluate all hardware profiles.
4646
Because profiles can only be tested with the appropriate hardware, quality
4747
assurance is up to *you*.
4848

flake.lock

Lines changed: 1 addition & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,35 @@
22
description = "nixos-hardware";
33

44
outputs =
5-
{ ... }:
5+
{ self, ... }:
6+
let
7+
# Import private inputs (for development)
8+
privateInputs =
9+
(import ./tests/flake-compat.nix {
10+
src = ./tests;
11+
}).defaultNix;
12+
13+
systems = [
14+
"aarch64-linux"
15+
"x86_64-linux"
16+
"riscv64-linux"
17+
];
18+
19+
formatSystems = [ "aarch64-linux" "riscv64-linux" ];
20+
21+
# Helper to iterate over systems
22+
eachSystem =
23+
f:
24+
privateInputs.nixos-unstable-small.lib.genAttrs systems (
25+
system: f privateInputs.nixos-unstable-small.legacyPackages.${system} system
26+
);
27+
28+
eachSystemFormat =
29+
f:
30+
privateInputs.nixos-unstable-small.lib.genAttrs formatSystems (
31+
system: f privateInputs.nixos-unstable-small.legacyPackages.${system} system
32+
);
33+
in
634
{
735

836
nixosModules =
@@ -395,5 +423,40 @@
395423
common-pc-laptop-ssd = import ./common/pc/ssd;
396424
common-pc-ssd = import ./common/pc/ssd;
397425
};
426+
427+
# Add formatter for `nix fmt`
428+
formatter = eachSystemFormat (
429+
pkgs: _system:
430+
(privateInputs.treefmt-nix.lib.evalModule pkgs ./tests/treefmt.nix).config.build.wrapper
431+
);
432+
433+
# Add packages
434+
packages = eachSystem (
435+
pkgs: _system: {
436+
run-tests = pkgs.callPackage ./tests/run-tests.nix {
437+
inherit self;
438+
};
439+
}
440+
);
441+
442+
# Add checks for `nix run .#run-tests`
443+
checks = eachSystem (
444+
pkgs: system:
445+
let
446+
treefmtEval = privateInputs.treefmt-nix.lib.evalModule pkgs ./tests/treefmt.nix;
447+
nixosTests = import ./tests/nixos-tests.nix {
448+
inherit
449+
self
450+
privateInputs
451+
system
452+
pkgs
453+
;
454+
};
455+
in
456+
pkgs.lib.optionalAttrs (self.formatter ? system) {
457+
formatting = treefmtEval.config.build.check self;
458+
}
459+
// nixosTests
460+
);
398461
};
399462
}

0 commit comments

Comments
 (0)