summary refs log tree commit diff
path: root/flake.nix
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@internetsafetylabs.org>2025-09-09 20:19:12 -0700
committerIrene Knapp <ireneista@internetsafetylabs.org>2025-09-09 20:26:57 -0700
commitb7887228c4866b16b3d5cf7d923739ed9d7ea104 (patch)
tree393c24b32c8663bf9b5f7b4cc64ac10361ef36cf /flake.nix
parentcd82f4a96839ad4b7907e0355a87ded23b5fe584 (diff)
make a really fancy test harness for nix module evaluation
I've never done this before and am really proud of the code; I hope the
comments help but feel free to ask questions.

As you can see by looking at the diffs to `options.nix`, it did catch
several issues that had gotten through up to this point. I'm pretty
pleased with that. As before, `nix flake check` is all you need to do to
run it.

Change-Id: I99a550e92d7b4770e52b6aba763cff2bdc4c9287
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix46
1 files changed, 8 insertions, 38 deletions
diff --git a/flake.nix b/flake.nix
index 8df1039..c101218 100644
--- a/flake.nix
+++ b/flake.nix
@@ -28,6 +28,9 @@
   in {
     nixosModules.default = { ... }: {
       imports = [
+        # Please note that checks.nix also directly references options.nix,
+        # so if you add anything else to these imports, also add it in
+        # checks.nix.
         ./options.nix
       ];
     };
@@ -47,44 +50,11 @@
       };
     });
 
+    # The checks are quite verbose, so they're in a separate file.
     checks = forAllSystems (system:
-        let pkgs = nixpkgsFor.${system};
-            mkNixEvalCheck = name: input: expected: pkgs.stdenv.mkDerivation {
-              name = "smalltech-nix-test-${name}";
-
-              src = pkgs.symlinkJoin {
-                name = "smalltech-nix-test-${name}-src";
-                paths = [
-                  (pkgs.writeTextDir "input" input)
-                  (pkgs.writeTextDir "expected" "${expected}\n")
-                ];
-              };
-
-              dontUnpack = true;
-
-              nativeBuildInputs = with pkgs; [ diffutils nix ];
-
-              buildPhase = ''
-                mkdir nix-store
-                ${pkgs.nix}/bin/nix \
-                    --extra-experimental-features nix-command \
-                    --store dummy:// \
-                    eval --json --file $src/input > $out
-
-                if ! ${pkgs.diffutils}/bin/diff $src/expected $out; then
-                  echo
-                  echo "This is a nix evaluation test case. The expected eval"
-                  echo "output differed from the actual output. In an ideal"
-                  echo "world, the above diff would help you understand why."
-                  echo
-                  false
-                fi
-              '';
-            };
-        in {
-          nix-trivial = mkNixEvalCheck "trivial" "1 + 2" "3";
-
-          rust = self.packages.${system}.default;
-        });
+                 let pkgs = nixpkgsFor.${system};
+                 in import ./checks.nix {
+                   inherit pkgs self system;
+                 });
   };
 }