A flake checker (treefmt & nix-unit) for testing other flakes with zero dependencies.

Expected flakeModule is checkmate

+53 -65
+11 -4
README.md
··· 4 4 5 5 - treefmt - nixfmt, deadnix, mdformat, yamlfmt. See `treefmt.nix`. 6 6 7 - - nix-unit - The flake being checked (ie, `inputs.target`) is expected to expose `flakeModules.nix-unit`: 7 + - nix-unit - The flake being checked (ie, `inputs.target`) is expected to expose `flakeModules.checkmate`: 8 8 9 9 ```nix 10 10 # Example 11 - flakeModules.nix-unit = 11 + flakeModules.checkmate = 12 12 { inputs, ... }: 13 + let 14 + self = inputs.target; # your flake being tested 15 + some-dep = self.inputs.some-dep; # access your flake dependencies via the target. 16 + in 13 17 { 14 18 perSystem = ( 15 - { lib, ... }: 19 + { lib, pkgs, ... }: 16 20 { 17 21 nix-unit.tests = { 18 - checkmate."test lib works" = { 22 + "test lib works" = { 19 23 expr = lib.removeSuffix ".nix" "hello.nix"; 20 24 expected = "hello"; 21 25 }; 22 26 }; 27 + 28 + # add any other derivations to check 29 + # checks.<name> = <derivation>; 23 30 } 24 31 ); 25 32 };
+18
example/checkmate.nix
··· 1 + { inputs, ... }: 2 + let 3 + self = inputs.target; 4 + dep = self.inputs.dep; # access dependencies using target 5 + in 6 + { 7 + perSystem = ( 8 + { lib, ... }: 9 + { 10 + nix-unit.tests = { 11 + checkmate."test access inputs via target" = { 12 + expr = lib.removePrefix "x86_64-" (lib.elemAt (import dep) 0); 13 + expected = "linux"; 14 + }; 15 + }; 16 + } 17 + ); 18 + }
+1 -22
example/flake.nix
··· 1 1 { 2 2 inputs.dep.url = "github:nix-systems/x86_64-linux"; # example dependency 3 - 4 - outputs = _inputs: { 5 - 6 - # Example 7 - flakeModules.nix-unit = 8 - { inputs, ... }: 9 - { 10 - perSystem = ( 11 - { lib, ... }: 12 - { 13 - nix-unit.tests = { 14 - checkmate."test access inputs via target" = { 15 - expr = lib.removePrefix "x86_64-" (lib.elemAt (import inputs.target.inputs.dep) 0); 16 - expected = "linux"; 17 - }; 18 - }; 19 - } 20 - ); 21 - }; 22 - 23 - }; 24 - 3 + outputs = _: { flakeModules.checkmate = ./checkmate.nix; }; 25 4 }
+14
failing-example/checkmate.nix
··· 1 + { ... }: 2 + { 3 + perSystem = ( 4 + { ... }: 5 + { 6 + nix-unit.tests = { 7 + checkmate."test fails" = { 8 + expr = 11; 9 + expected = 99; 10 + }; 11 + }; 12 + } 13 + ); 14 + }
+1 -21
failing-example/flake.nix
··· 1 1 { 2 - outputs = _: { 3 - 4 - # Example 5 - flakeModules.nix-unit = 6 - { ... }: 7 - { 8 - perSystem = ( 9 - { ... }: 10 - { 11 - nix-unit.tests = { 12 - checkmate."test fails" = { 13 - expr = 11; 14 - expected = 99; 15 - }; 16 - }; 17 - } 18 - ); 19 - }; 20 - 21 - }; 22 - 2 + outputs = _: { flakeModules.checkmate = ./checkmate.nix; }; 23 3 }
+4 -18
flakeModule.nix
··· 1 1 { inputs, ... }: 2 - let 3 - flakeModule = { 4 - systems = import inputs.systems; 5 - imports = [ 6 - ./perSystem-lib.nix 7 - ./tests.nix 8 - ./treefmt.nix 9 - ]; 10 - }; 11 - 12 - # Tests are defined by target, and imported bellow by `inputs.target.flakeModules.nix-unit`. 13 - # See example/flake.nix or https://github.com/vic/import-tree/tree/main/checks/default.nix 14 - targetTest = inputs.target.flakeModules.nix-unit or { }; 15 - in 16 2 { 3 + systems = import inputs.systems; 17 4 imports = [ 18 - flakeModule 19 - targetTest 5 + ./perSystem-lib.nix 6 + ./tests.nix 7 + ./treefmt.nix 20 8 ]; 21 - 22 - flake.flakeModules.default = flakeModule; 23 9 }
+4
tests.nix
··· 2 2 { 3 3 imports = [ 4 4 inputs.nix-unit.modules.flake.default 5 + 6 + # Tests are defined by target, and imported bellow by `inputs.target.flakeModules.nix-unit`. 7 + # See example/flake.nix or https://github.com/vic/import-tree/tree/main/checks/default.nix 8 + (inputs.target.flakeModules.checkmate or { }) 5 9 ]; 6 10 7 11 perSystem = (