From 18aeb7b6f8d52467cc61908f0d272b082be1e157 Mon Sep 17 00:00:00 2001 From: Emile Clark-Boman Date: Tue, 27 Jan 2026 08:38:02 +1000 Subject: [PATCH] add nt.units --- nt/default.nix | 1 + nt/units/README.md | 1 + nt/units/default.nix | 52 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 nt/units/README.md create mode 100644 nt/units/default.nix diff --git a/nt/default.nix b/nt/default.nix index 89c329f..c03e0be 100644 --- a/nt/default.nix +++ b/nt/default.nix @@ -5,5 +5,6 @@ mix.newMixture inputs (mixture: { ]; submods.public = [ ./mix + ./units ]; }) diff --git a/nt/units/README.md b/nt/units/README.md new file mode 100644 index 0000000..5ca105a --- /dev/null +++ b/nt/units/README.md @@ -0,0 +1 @@ +# Unit Testing For Nix diff --git a/nt/units/default.nix b/nt/units/default.nix new file mode 100644 index 0000000..c3d4bad --- /dev/null +++ b/nt/units/default.nix @@ -0,0 +1,52 @@ +{ + flake, + this, + ... +}: let + inherit + (builtins) + derivation + getFlake + ; + + inherit + (this) + genAttrs + ; + + # TODO: rewrite nix-unit to lose dependency + nix-unit-flake = getFlake "github.com:nix-community/nix-unit?rev=5e224c19c7087daebb7f7ac95acdfdcc08ea7433"; + + forAllSystems = genAttrs [ + "aarch64-darwin" + "aarch64-linux" + "x86_64-darwin" + "x86_64-linux" + ]; +in { + tests.testPass = { + expr = 3; + expected = 4; + }; + + checks = forAllSystems (system: let + nix-unit = "${nix-unit-flake.packages.${system}.default}/bin/nix-unit"; + in { + default = derivation { + inherit system; + name = "nt-units"; + builder = "/bin/sh"; + + args = [ + "-c" + ''export HOME="$(realpath .)"; ${nix-unit} --eval-store "$HOME" --flake ${flake}#tests --extra-experimental-features flakes --extra-experimental-features nix-command --extra-experimental-features pipe-operators; touch $out'' + ]; + + # XXX: TODO: is nix-unit-flake built in the sandbox (probably not right?) + # fixed-output-derivation by using output* options + # outputHashMode = "flat"; + # outputHashAlgo = "sha256"; + # outputHash = ""; + }; + }); +}