summary refs log tree commit diff
path: root/flake.nix
diff options
context:
space:
mode:
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix52
1 files changed, 46 insertions, 6 deletions
diff --git a/flake.nix b/flake.nix
index 9e73b80..8df1039 100644
--- a/flake.nix
+++ b/flake.nix
@@ -26,18 +26,18 @@
       forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
       nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
   in {
-    packages = forAllSystems (system: let pkgs = nixpkgsFor.${system}; in {
-      default = (crane.mkLib pkgs).buildPackage {
-        src = ./.;
-      };
-    });
-
     nixosModules.default = { ... }: {
       imports = [
         ./options.nix
       ];
     };
 
+    packages = forAllSystems (system: let pkgs = nixpkgsFor.${system}; in {
+      default = (crane.mkLib pkgs).buildPackage {
+        src = ./.;
+      };
+    });
+
     devShells = forAllSystems (system: let pkgs = nixpkgsFor.${system}; in {
       default = pkgs.mkShell {
         nativeBuildInputs = with pkgs; [
@@ -46,5 +46,45 @@
         ];
       };
     });
+
+    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;
+        });
   };
 }