Generate flake.nix from module options. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ dendrix.oeiuwq.com/Dendritic.html
dendritic nix inputs
at main 305 lines 8.7 kB view raw
1{ 2 pkgs ? import <nixpkgs> { }, 3 outdir ? ".", 4 ... 5}@args: 6let 7 8 bootstrap = 9 modules: 10 import ./.. ( 11 args 12 // { 13 inherit modules; 14 } 15 ); 16 17 empty = bootstrap { 18 inputs.empty.url = "github:vic/empty-flake"; 19 outputs = _: { }; 20 }; 21 22 all-inputs-schemes = bootstrap { 23 inputs.simple.url = "github:vic/empty-flake"; 24 inputs.withBranch.url = "github:vic/empty-flake/main"; 25 inputs.noflake = { 26 url = "github:vic/empty-flake/main"; 27 flake = false; 28 }; 29 inputs.gitHttps.url = "git+https://github.com/vic/empty-flake"; 30 inputs.tarball.url = "https://github.com/vic/empty-flake/archive/main.tar.gz"; 31 inputs.tarballPlus.url = "tarball+https://github.com/vic/empty-flake/archive/main.tar.gz"; 32 inputs.fileHttps.url = "file+https://github.com/vic/empty-flake/archive/main.tar.gz"; 33 inputs.attrGh = { 34 type = "github"; 35 owner = "vic"; 36 repo = "empty-flake"; 37 }; 38 inputs.attrGhRef = { 39 type = "github"; 40 owner = "vic"; 41 repo = "empty-flake"; 42 ref = "main"; 43 }; 44 inputs.followsSimple.follows = "simple"; 45 }; 46 47 flake-parts = bootstrap { 48 inputs.flake-parts.url = "github:hercules-ci/flake-parts"; 49 }; 50 51 flake-parts-follows = bootstrap { 52 inputs.nixpkgs-lib.url = "github:vic/empty-flake"; 53 inputs.flake-parts.url = "github:hercules-ci/flake-parts"; 54 inputs.flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs-lib"; 55 }; 56 57 flake-parts-skip = bootstrap { 58 inputs.flake-parts.url = "github:hercules-ci/flake-parts"; 59 inputs.flake-parts.inputs.nixpkgs-lib.follows = ""; 60 }; 61 62 test-inputs = pkgs.writeShellApplication { 63 name = "test-inputs"; 64 runtimeInputs = [ 65 (empty.flake-file.apps.write-inputs pkgs) 66 ]; 67 text = '' 68 write-inputs 69 cat ${outdir}/inputs.nix 70 grep github:vic/empty-flake ${outdir}/inputs.nix 71 ''; 72 }; 73 74 test-flake = pkgs.writeShellApplication { 75 name = "test-flake"; 76 runtimeInputs = [ 77 pkgs.nix 78 (empty.flake-file.apps.write-flake pkgs) 79 ]; 80 text = '' 81 write-flake 82 cat ${outdir}/flake.nix 83 grep github:vic/empty-flake ${outdir}/flake.nix 84 ''; 85 }; 86 87 test-npins = pkgs.writeShellApplication { 88 name = "test-npins"; 89 runtimeInputs = [ 90 (empty.flake-file.apps.write-npins pkgs) 91 pkgs.jq 92 ]; 93 text = '' 94 write-npins 95 cat ${outdir}/npins/sources.json 96 jq -e '.pins | has("empty")' ${outdir}/npins/sources.json 97 ''; 98 }; 99 100 test-npins-transitive = pkgs.writeShellApplication { 101 name = "test-npins-transitive"; 102 runtimeInputs = [ 103 (flake-parts.flake-file.apps.write-npins pkgs) 104 pkgs.jq 105 ]; 106 text = '' 107 write-npins 108 cat ${outdir}/npins/sources.json 109 jq -e '.pins."flake-parts".url | contains("hercules-ci/flake-parts")' ${outdir}/npins/sources.json 110 jq -e '.pins."nixpkgs-lib".url | contains("nix-community/nixpkgs.lib")' ${outdir}/npins/sources.json 111 ''; 112 }; 113 114 test-npins-follows = pkgs.writeShellApplication { 115 name = "test-npins-follows"; 116 runtimeInputs = [ 117 (flake-parts-follows.flake-file.apps.write-npins pkgs) 118 pkgs.jq 119 ]; 120 text = '' 121 write-npins 122 cat ${outdir}/npins/sources.json 123 jq -e '.pins."flake-parts".url | contains("hercules-ci/flake-parts")' ${outdir}/npins/sources.json 124 jq -e '.pins."nixpkgs-lib".url | contains("vic/empty")' ${outdir}/npins/sources.json 125 ''; 126 }; 127 128 test-npins-skip = pkgs.writeShellApplication { 129 name = "test-npins-skip"; 130 runtimeInputs = [ 131 (flake-parts-skip.flake-file.apps.write-npins pkgs) 132 pkgs.jq 133 ]; 134 text = '' 135 write-npins 136 cat ${outdir}/npins/sources.json 137 jq -e '.pins."flake-parts".url | contains("hercules-ci/flake-parts")' ${outdir}/npins/sources.json 138 jq -e '.pins | has("nixpkgs-lib") | not' ${outdir}/npins/sources.json 139 ''; 140 }; 141 142 test-npins-schemes = pkgs.writeShellApplication { 143 name = "test-npins-schemes"; 144 runtimeInputs = [ 145 (all-inputs-schemes.flake-file.apps.write-npins pkgs) 146 pkgs.jq 147 ]; 148 text = '' 149 write-npins 150 cat ${outdir}/npins/sources.json 151 jq -e '.pins | has("simple")' ${outdir}/npins/sources.json 152 jq -e '.pins | has("withBranch")' ${outdir}/npins/sources.json 153 jq -e '.pins | has("noflake")' ${outdir}/npins/sources.json 154 jq -e '.pins | has("gitHttps")' ${outdir}/npins/sources.json 155 jq -e '.pins | has("tarball")' ${outdir}/npins/sources.json 156 jq -e '.pins | has("tarballPlus")' ${outdir}/npins/sources.json 157 jq -e '.pins | has("fileHttps")' ${outdir}/npins/sources.json 158 jq -e '.pins | has("attrGh")' ${outdir}/npins/sources.json 159 jq -e '.pins | has("attrGhRef")' ${outdir}/npins/sources.json 160 jq -e '.pins | has("followsSimple") | not' ${outdir}/npins/sources.json 161 ''; 162 }; 163 164 test-unflake = pkgs.writeShellApplication { 165 name = "test-unflake"; 166 runtimeInputs = [ 167 (empty.flake-file.apps.write-unflake pkgs) 168 ]; 169 text = '' 170 write-unflake --backend nix 171 grep unflake_github_vic_empty-flake ${outdir}/unflake.nix 172 ''; 173 }; 174 175 test-nixlock-update = pkgs.writeShellApplication { 176 name = "test-nixlock-update"; 177 runtimeInputs = [ 178 (empty.flake-file.apps.write-nixlock pkgs) 179 ]; 180 text = '' 181 write-nixlock lock 182 grep empty ${outdir}/nixlock.lock.nix 183 write-nixlock update 184 grep empty ${outdir}/nixlock.lock.nix 185 ''; 186 }; 187 188 test-nixlock-update-one = pkgs.writeShellApplication { 189 name = "test-nixlock-update-one"; 190 runtimeInputs = [ 191 (empty.flake-file.apps.write-nixlock pkgs) 192 ]; 193 text = '' 194 write-nixlock lock 195 write-nixlock update empty 196 grep empty ${outdir}/nixlock.lock.nix 197 if write-nixlock update nonexistent 2>/dev/null; then exit 1; fi 198 ''; 199 }; 200 201 test-nixlock = pkgs.writeShellApplication { 202 name = "test-nixlock"; 203 runtimeInputs = [ 204 (empty.flake-file.apps.write-nixlock pkgs) 205 ]; 206 text = '' 207 write-nixlock 208 grep empty ${outdir}/nixlock.lock.nix 209 ''; 210 }; 211 212 test-write-lock-flake = pkgs.writeShellApplication { 213 name = "test-write-lock-flake"; 214 runtimeInputs = [ 215 (empty.flake-file.apps.write-lock pkgs) 216 ]; 217 text = '' 218 echo "{ }" > ${outdir}/flake.lock 219 write-lock 220 [ -e ${outdir}/flake.nix ] 221 grep github:vic/empty-flake ${outdir}/flake.nix 222 ''; 223 }; 224 225 test-write-lock-npins = pkgs.writeShellApplication { 226 name = "test-write-lock-npins"; 227 runtimeInputs = [ 228 (empty.flake-file.apps.write-lock pkgs) 229 pkgs.jq 230 ]; 231 text = '' 232 mkdir -p ${outdir}/npins 233 echo '{"pins":{},"version":7}' > ${outdir}/npins/sources.json 234 write-lock 235 jq -e '.pins | has("empty")' ${outdir}/npins/sources.json 236 ''; 237 }; 238 239 test-write-lock-nixlock = pkgs.writeShellApplication { 240 name = "test-write-lock-nixlock"; 241 runtimeInputs = [ 242 (empty.flake-file.apps.write-lock pkgs) 243 ]; 244 text = '' 245 echo '{ }' > ${outdir}/nixlock.lock.nix 246 write-lock 247 grep empty ${outdir}/nixlock.lock.nix 248 ''; 249 }; 250 251 test-write-lock-unflake = pkgs.writeShellApplication { 252 name = "test-write-lock-unflake"; 253 runtimeInputs = [ 254 (empty.flake-file.apps.write-lock pkgs) 255 ]; 256 text = '' 257 echo '{ }' > ${outdir}/unflake.nix 258 write-lock --backend nix 259 grep unflake_github_vic_empty-flake ${outdir}/unflake.nix 260 ''; 261 }; 262 263 test-nixlock-schemes = pkgs.writeShellApplication { 264 name = "test-nixlock-schemes"; 265 runtimeInputs = [ 266 (all-inputs-schemes.flake-file.apps.write-nixlock pkgs) 267 ]; 268 text = '' 269 write-nixlock 270 cat ${outdir}/nixlock.lock.nix 271 grep '"simple"' ${outdir}/nixlock.lock.nix 272 grep '"withBranch"' ${outdir}/nixlock.lock.nix 273 grep '"noflake"' ${outdir}/nixlock.lock.nix 274 grep '"gitHttps"' ${outdir}/nixlock.lock.nix 275 grep '"tarball"' ${outdir}/nixlock.lock.nix 276 grep '"tarballPlus"' ${outdir}/nixlock.lock.nix 277 grep '"fileHttps"' ${outdir}/nixlock.lock.nix 278 grep '"attrGh"' ${outdir}/nixlock.lock.nix 279 grep '"attrGhRef"' ${outdir}/nixlock.lock.nix 280 if grep '"followsSimple"' ${outdir}/nixlock.lock.nix; then exit 1; fi 281 grep vic/empty-flake ${outdir}/nixlock.lock.nix 282 ''; 283 }; 284 285in 286pkgs.mkShell { 287 buildInputs = [ 288 test-inputs 289 test-flake 290 test-unflake 291 test-npins 292 test-npins-schemes 293 test-npins-skip 294 test-npins-follows 295 test-npins-transitive 296 test-nixlock 297 test-nixlock-update 298 test-nixlock-update-one 299 test-nixlock-schemes 300 test-write-lock-flake 301 test-write-lock-npins 302 test-write-lock-nixlock 303 test-write-lock-unflake 304 ]; 305}