Skip to content

Commit

Permalink
test modules only once
Browse files Browse the repository at this point in the history
before that we may have been running tests twice, the second time being
in `legacyPackages`. But there's no need to expose tests another time,
once can just access them via `checks` if needed.
  • Loading branch information
fricklerhandwerk committed Nov 17, 2024
1 parent fde6800 commit 18568d2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
28 changes: 1 addition & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -167,32 +167,6 @@
.options;
};
in rec {
# This is omitted in `nix flake show`.
legacyPackages = {
# Run interactive tests with:
#
# nix run .#legacyPackages.x86_64-linux.nixosTests.<project>.<test>.driverInteractive
#
nixosTests = let
nixosTest = test: let
# Amenities for interactive tests
tools = {pkgs, ...}: {
environment.systemPackages = with pkgs; [vim tmux jq];
# Use kmscon <https://www.freedesktop.org/wiki/Software/kmscon/>
# to provide a slightly nicer console.
# kmscon allows zooming with [Ctrl] + [+] and [Ctrl] + [-]
services.kmscon = {
enable = true;
autologinUser = "root";
};
};
debugging.interactive.nodes = mapAttrs (_: _: tools) test.nodes;
in
pkgs.nixosTest (debugging // test);
in
mapAttrs (_: project: mapAttrs (_: nixosTest) project.nixos.tests) ngiProjects;
};

packages =
ngipkgs
// {
Expand Down Expand Up @@ -224,7 +198,7 @@
checksForProject = projectName: project: let
checksForNixosTests =
concatMapAttrs
(testName: test: {"projects/${projectName}/nixos/tests/${testName}" = pkgs.nixosTest test;})
(testName: test: {"projects/${projectName}/nixos/tests/${testName}" = test;})
project.nixos.tests;

checksForNixosExamples =
Expand Down
30 changes: 29 additions & 1 deletion projects/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
in
concatMapAttrs names (readDir baseDirectory);

nixosTest = test: let
# Amenities for interactive tests
tools = {pkgs, ...}: {
environment.systemPackages = with pkgs; [vim tmux jq];
# Use kmscon <https://www.freedesktop.org/wiki/Software/kmscon/>
# to provide a slightly nicer console.
# kmscon allows zooming with [Ctrl] + [+] and [Ctrl] + [-]
services.kmscon = {
enable = true;
autologinUser = "root";
};
};
debugging.interactive.nodes = mapAttrs (_: _: tools) test.nodes;
in
pkgs.nixosTest (debugging // test);

hydrate = let
empty-if-null = x:
if x != null
Expand All @@ -41,7 +57,19 @@
packages = empty-if-null (project.packages or {});
nixos.modules = empty-if-null (project.nixos.modules or {});
nixos.examples = empty-if-null (project.nixos.examples or {});
nixos.tests = empty-if-null (project.nixos.tests or {});
nixos.tests =
mapAttrs
(
_: test:
if lib.isString test
then
(import test {
inherit pkgs;
inherit (pkgs) system;
})
else nixosTest test
)
(empty-if-null (project.nixos.tests or {}));
};
in
mapAttrs
Expand Down

0 comments on commit 18568d2

Please sign in to comment.