Skip to content

Commit 54fc95a

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 54fc95a

File tree

11 files changed

+482
-209
lines changed

11 files changed

+482
-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: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,27 @@
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+
# Helper to iterate over systems
20+
eachSystem =
21+
f:
22+
privateInputs.nixos-unstable-small.lib.genAttrs systems (
23+
system: f privateInputs.nixos-unstable-small.legacyPackages.${system} system
24+
);
25+
in
626
{
727

828
nixosModules =
@@ -395,5 +415,40 @@
395415
common-pc-laptop-ssd = import ./common/pc/ssd;
396416
common-pc-ssd = import ./common/pc/ssd;
397417
};
418+
419+
# Add formatter for `nix fmt`
420+
formatter = eachSystem (
421+
pkgs: _system:
422+
(privateInputs.treefmt-nix.lib.evalModule pkgs ./tests/treefmt.nix).config.build.wrapper
423+
);
424+
425+
# Add packages
426+
packages = eachSystem (
427+
pkgs: _system: {
428+
run-tests = pkgs.callPackage ./tests/run-tests.nix {
429+
inherit self;
430+
};
431+
}
432+
);
433+
434+
# Add checks for `nix run .#run-tests`
435+
checks = eachSystem (
436+
pkgs: system:
437+
let
438+
treefmtEval = privateInputs.treefmt-nix.lib.evalModule pkgs ./tests/treefmt.nix;
439+
nixosTests = import ./tests/nixos-tests.nix {
440+
inherit
441+
self
442+
privateInputs
443+
system
444+
pkgs
445+
;
446+
};
447+
in
448+
{
449+
formatting = treefmtEval.config.build.check self;
450+
}
451+
// nixosTests
452+
);
398453
};
399454
}

0 commit comments

Comments
 (0)