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

check

+47 -27
+1
.github/workflows/test.yml
··· 10 10 - uses: actions/checkout@v4 11 11 - uses: cachix/install-nix-action@v30 12 12 - run: nix run -L .#checkmate-treefmt -- --ci $PWD 13 + - run: nix flake check -L 13 14 - run: nix flake check -L --override-input target path:$PWD/example 14 15 - run: | 15 16 nix flake check -L --override-input target path:$PWD/failing-example || touch did-failed
+1 -1
README.md
··· 29 29 30 30 ``` 31 31 # On your github action 32 - nix check github:checkmate --override-input target path:$PWD 32 + nix check github:checkmate --override-input target path:$PWD -L --refresh 33 33 ```
+13 -9
default.nix
··· 1 1 { inputs, ... }: 2 + let 3 + flakeModule = { 4 + systems = import inputs.systems; 5 + imports = [ 6 + inputs.flake-parts.flakeModules.flakeModules 7 + ./perSystem-lib.nix 8 + ./tests.nix 9 + ./treefmt.nix 10 + ]; 11 + }; 12 + in 2 13 { 3 - imports = [ 4 - inputs.flake-parts.flakeModules.flakeModules 5 - ./perSystem-lib.nix 6 - ./tests.nix 7 - ./treefmt.nix 8 - ]; 9 - 10 - systems = import inputs.systems; 11 - flake.flakeModules.default = ./default.nix; 14 + imports = [ flakeModule ]; 15 + flake.flakeModules.default = flakeModule; 12 16 }
+5 -5
example/flake.nix
··· 1 1 { 2 - inputs.empty.url = "github:vic/empty-flake"; # example dependency 2 + inputs.dep.url = "github:nix-systems/x86_64-linux"; # example dependency 3 3 4 4 outputs = _inputs: { 5 5 6 6 # Example 7 7 flakeModules.nix-unit = 8 - { ... }: # you can access inputs.target.inputs.empty from here 8 + { inputs, ... }: 9 9 { 10 10 perSystem = ( 11 11 { lib, ... }: 12 12 { 13 13 nix-unit.tests = { 14 - checkmate."test lib works" = { 15 - expr = lib.removeSuffix ".nix" "hello.nix"; 16 - expected = "hello"; 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 17 }; 18 18 }; 19 19 }
+23 -5
flake.lock
··· 1 1 { 2 2 "nodes": { 3 + "empty": { 4 + "locked": { 5 + "lastModified": 1741993073, 6 + "narHash": "sha256-hTJPMh9Bwky2TlaWmLrkBHdUBmpxSCPRK+bmnFNpNQE=", 7 + "owner": "vic", 8 + "repo": "empty-flake", 9 + "rev": "a402c2c33ff3f5010eb0357d8228f27fb7083cbd", 10 + "type": "github" 11 + }, 12 + "original": { 13 + "owner": "vic", 14 + "repo": "empty-flake", 15 + "type": "github" 16 + } 17 + }, 3 18 "flake-parts": { 4 19 "inputs": { 5 20 "nixpkgs-lib": [ ··· 124 139 } 125 140 }, 126 141 "target": { 142 + "inputs": { 143 + "empty": "empty" 144 + }, 127 145 "locked": { 128 - "dir": "failing-example", 129 - "lastModified": 1742084732, 130 - "narHash": "sha256-yoe7izv/Cl/qkCyn3HzsPAwlWNlTTeI6waBiIJEoMaY=", 146 + "dir": "example", 147 + "lastModified": 1742085978, 148 + "narHash": "sha256-G4yl2Kdrx2vI0qJ7EUgFd6eaadcngjg37XDzDBbpSWg=", 131 149 "owner": "vic", 132 150 "repo": "checkmate", 133 - "rev": "9132a1ffd6cca2527aae6e669976940ae6e6f030", 151 + "rev": "af3b609faa00ef97b2fc2ca81f400249f80169af", 134 152 "type": "github" 135 153 }, 136 154 "original": { 137 - "dir": "failing-example", 155 + "dir": "example", 138 156 "owner": "vic", 139 157 "repo": "checkmate", 140 158 "type": "github"
+1 -1
flake.nix
··· 2 2 inputs = { 3 3 # example target flake to be tested 4 4 # override with something else. 5 - target.url = "github:vic/checkmate?dir=failing-example"; 5 + target.url = "github:vic/checkmate?dir=example"; 6 6 7 7 nixpkgs.url = "github:nixos/nixpkgs/24.11"; 8 8 systems.url = "github:nix-systems/default";
+2 -5
tests.nix
··· 3 3 imports = [ 4 4 # Tests are defined by target, and imported bellow by `inputs.target.flakeModules.nix-unit`. 5 5 # See example/flake.nix or https://github.com/vic/import-tree/tree/main/checks/default.nix 6 - inputs.target.flakeModules.nix-unit 6 + (inputs.target or inputs.self).flakeModules.nix-unit 7 7 inputs.nix-unit.modules.flake.default 8 8 ]; 9 9 10 10 perSystem = ( 11 11 { ... }: 12 - let 13 - fixedInputs = inputs // inputs.target.inputs; 14 - in 15 12 { 16 13 nix-unit.allowNetwork = true; 17 - nix-unit.inputs = fixedInputs; 14 + nix-unit.inputs = inputs; 18 15 } 19 16 ); 20 17 }
+1 -1
treefmt.nix
··· 12 12 programs.yamlfmt.enable = true; 13 13 }; 14 14 treefmt-wrapper = treefmt.config.build.wrapper; 15 - treefmt-check = treefmt.config.build.check inputs.target; 15 + treefmt-check = treefmt.config.build.check (inputs.target or inputs.self); 16 16 in 17 17 { 18 18 packages.checkmate-treefmt = treefmt-wrapper;