Skip to content

Commit

Permalink
refactor: move test helpers into flake (#370)
Browse files Browse the repository at this point in the history
* refactor: move test helpers into flake

collecting projects should not deal with debugging workflows.

this change makes the derivation for running CI checks slightly smaller,
at the cost of having a slightly different environment for interactive
tests. it should be okay as long as those differences stay tightly scoped.

* formatting
  • Loading branch information
fricklerhandwerk authored Sep 24, 2024
1 parent 66ff2de commit faf6738
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
34 changes: 29 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@
mapAttrs (_: project: mapAttrs (_: example: example.path) project.nixos.examples) rawNgiProjects
);

rawNixosModules = flattenAttrsDot (lib.foldl recursiveUpdate {} (attrValues (
mapAttrs (_: project: project.nixos.modules) rawNgiProjects
)));
rawNixosModules = flattenAttrsDot (
lib.foldl recursiveUpdate {} (attrValues (
mapAttrs (_: project: project.nixos.modules) rawNgiProjects
))
);

nixosModules =
{
Expand Down Expand Up @@ -175,8 +177,30 @@
.options;
};
in rec {
# This is omitted in `nix flake show`.
legacyPackages = {
nixosTests = mapAttrs (_: project: project.nixos.tests) ngiProjects;
# 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 =
Expand Down Expand Up @@ -205,7 +229,7 @@
checks = let
checksForNixosTests = projectName: tests:
concatMapAttrs
(testName: test: {"projects/${projectName}/nixos/tests/${testName}" = test;})
(testName: test: {"projects/${projectName}/nixos/tests/${testName}" = pkgs.nixosTest test;})
tests;

checksForNixosExamples = projectName: examples:
Expand Down
18 changes: 1 addition & 17 deletions projects/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,11 @@
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 = project: {
packages = project.packages or {};
nixos.modules = project.nixos.modules or {};
nixos.examples = project.nixos.examples or {};
nixos.tests = mapAttrs (_: nixosTest) project.nixos.tests or {};
nixos.tests = project.nixos.tests or {};
};
in
mapAttrs
Expand Down

0 comments on commit faf6738

Please sign in to comment.