Generate flake.nix from module options. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ dendrix.oeiuwq.com/Dendritic.html
dendritic nix inputs

Compare changes

Choose any two refs to compare.

+218 -239
-1
.github/FUNDING.yml
··· 1 1 # These are supported funding model platforms 2 - 3 2 github: [vic] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 3 patreon: # Replace with a single Patreon username 5 4 open_collective: # Replace with a single Open Collective username
+3 -3
.github/workflows/flake-check.yaml
··· 25 25 template: ${{ fromJSON(needs.find-templates.outputs.templates) }} 26 26 steps: 27 27 - uses: wimpysworld/nothing-but-nix@main 28 - - uses: DeterminateSystems/nix-installer-action@main 28 + - uses: cachix/install-nix-action@v31 29 29 - uses: DeterminateSystems/magic-nix-cache-action@main 30 30 - run: | 31 31 set -uveo pipefail ··· 50 50 steps: 51 51 - uses: actions/checkout@v4 52 52 - uses: wimpysworld/nothing-but-nix@main 53 - - uses: DeterminateSystems/nix-installer-action@main 53 + - uses: cachix/install-nix-action@v31 54 54 - uses: DeterminateSystems/magic-nix-cache-action@main 55 55 - run: cd dev && nix flake check && nix flake metadata && nix flake check 56 56 nix-fmt: ··· 59 59 steps: 60 60 - uses: actions/checkout@v4 61 61 - uses: wimpysworld/nothing-but-nix@main 62 - - uses: DeterminateSystems/nix-installer-action@main 62 + - uses: cachix/install-nix-action@v31 63 63 - uses: DeterminateSystems/magic-nix-cache-action@main 64 64 - run: nix run -L ./dev#fmt -- --ci
+12
.tangled/workflows/mirror.yml
··· 1 + when: 2 + - event: ["push"] 3 + branch: ["*"] 4 + engine: "nixery" 5 + clone: 6 + skip: true 7 + dependencies: 8 + nixpkgs: 9 + - gh 10 + steps: 11 + - name: mirror 12 + command: gh -R vic/vic issue comment 3 -b flake-file
+50 -27
README.md
··· 1 1 <!-- Badges --> 2 + 2 3 <p align="right"> 3 - <a href="https://nixos.org/"> <img src="https://img.shields.io/badge/Nix-Flake-informational?logo=nixos&logoColor=white" alt="Nix Flake"/> </a> 4 + <a href="https://github.com/sponsors/vic"><img src="https://img.shields.io/badge/sponsor-vic-white?logo=githubsponsors&logoColor=white&labelColor=%23FF0000" alt="Sponsor Vic"/> 5 + </a> 6 + <a href="https://vic.github.io/dendrix/Dendritic-Ecosystem.html#vics-dendritic-libraries"> <img src="https://img.shields.io/badge/Dendritic-Nix-informational?logo=nixos&logoColor=white" alt="Dendritic Nix"/> </a> 4 7 <a href="https://github.com/vic/flake-file/actions"> 5 8 <img src="https://github.com/vic/flake-file/workflows/flake-check/badge.svg" alt="CI Status"/> </a> 6 9 <a href="LICENSE"> <img src="https://img.shields.io/github/license/vic/flake-file" alt="License"/> </a> ··· 8 11 9 12 # flake-file โ€” Generate flake.nix from flake-parts modules. 10 13 14 + > `flake-file` and [vic](https://bsky.app/profile/oeiuwq.bsky.social)'s [dendritic libs](https://vic.github.io/dendrix/Dendritic-Ecosystem.html#vics-dendritic-libraries) made for you with Love++ and AI--. If you like my work, consider [sponsoring](https://github.com/sponsors/vic) 15 + 11 16 **flake-file** lets you generate a clean, maintainable `flake.nix` from modular options, using [flake-parts](https://flake.parts/). 12 17 13 18 It makes your flake configuration modular and based on the Nix module system. This means you can use 14 19 `lib.mkDefault` or anything you normally do with Nix modules, and have them reflected in flake schema values. 15 20 16 21 <table><tr><td> 17 - 22 + 18 23 ## Features 19 24 20 25 - Flake definition aggregated from all flake-parts modules. ··· 99 104 # That's it! Importing this module will add dendritic-setup inputs to your flake. 100 105 imports = [ inputs.flake-file.flakeModules.dendritic ]; 101 106 102 - # Define flake attributes on any flake-pars module: 107 + # Define flake attributes on any flake-parts module: 103 108 flake-file = { 104 109 description = "My Awesome Flake"; 105 110 inputs.nixpkgs.url = lib.mkDefault "github:NixOS/nixpkgs/nixpkgs-unstable"; ··· 138 143 139 144 - Includes flakeModules.default. 140 145 - Includes flakeModules.import-tree. 141 - - Includes flakeModules.nix-auto-follow. 142 146 - Enables [`flake-parts`](https://github.com/hercules-ci/flake-parts). 143 - - Enables [`flake-aspects`](https://github.com/vic/flake-aspects). 144 - - Enables [`den`](https://github.com/vic/den). 145 - - Sets `output` function to `import-tree ./modules`. 146 - - Adds `treefmt-nix` input. 147 - - Enables formatters: `nixfmt`, `deadnix`, and `nixf-diagnose`. 147 + - Sets `outputs` to `inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules)`. 148 + 149 + > Previously, this module included `flake-aspects` and `den` as dependencies. It now provides a pure flake-parts Dendritic setup. If you need the complete [den](https://github.com/vic/den) functionality, use den's `flakeModules.dendritic` instead. 148 150 149 151 ### Flake Templates 150 152 ··· 190 192 191 193 Options use the same attributes as the flake schema. See below for details. 192 194 193 - | Option | Description | 194 - | ----------------------------------------------- | --------------------------------- | 195 - | `flake-file.description` | Sets the flake description | 196 - | `flake-file.nixConfig` | Attrset for flake-level nixConfig | 197 - | `flake-file.inputs.<name>.url` | URL for a flake input | 198 - | `flake-file.inputs.<name>.flake` | Boolean, is input a flake? | 199 - | `flake-file.inputs.<name>.inputs.<dep>.follows` | Tree of dependencies to follow | 195 + | Option | Description | 196 + | ------------------------------------------------- | ----------------------------------------------------------- | 197 + | `flake-file.description` | Sets the flake description | 198 + | `flake-file.nixConfig` | Flake-level `nixConfig` (typed attrset) | 199 + | `flake-file.outputs` | Literal Nix code for `outputs` function | 200 + | `flake-file.formatter` | Function: `pkgs -> program` to format generated `flake.nix` | 201 + | `flake-file.do-not-edit` | Header comment added atop generated file | 202 + | `flake-file.inputs.<name>.url` | Source URL (e.g. `github:owner/repo`) | 203 + | `flake-file.inputs.<name>.type` | Reference type (`github`, `path`, etc.) | 204 + | `flake-file.inputs.<name>.owner` | Owner (for typed VCS refs) | 205 + | `flake-file.inputs.<name>.repo` | Repo name | 206 + | `flake-file.inputs.<name>.path` | Local path reference | 207 + | `flake-file.inputs.<name>.id` | Flake registry id | 208 + | `flake-file.inputs.<name>.dir` | Subdirectory within repo/path | 209 + | `flake-file.inputs.<name>.narHash` | NAR hash pin | 210 + | `flake-file.inputs.<name>.rev` | Commit hash pin | 211 + | `flake-file.inputs.<name>.ref` | Branch or tag pin | 212 + | `flake-file.inputs.<name>.host` | Custom host for git forges | 213 + | `flake-file.inputs.<name>.submodules` | Whether to fetch git submodules | 214 + | `flake-file.inputs.<name>.flake` | Boolean: is it a flake? (default true) | 215 + | `flake-file.inputs.<name>.follows` | Follow another input's value | 216 + | `flake-file.inputs.<name>.inputs.<dep>.follows` | Nested input follow tree | 217 + | `flake-file.inputs.<name>.inputs.<dep>.inputs...` | Recursively follow deeper deps | 218 + | `flake-file.write-hooks` | List of ordered hooks (by `index`) after writing | 219 + | `flake-file.check-hooks` | List of ordered hooks (by `index`) during check | 220 + | `flake-file.prune-lock.enable` | Enable automatic flake.lock pruning | 221 + | `flake-file.prune-lock.program` | Function building pruning executable | 200 222 201 223 Example: 202 224 203 225 ```nix 204 226 flake-file = { 205 227 description = "my awesome flake"; 206 - nixConfig = {}; # an attrset. currently not typed. 228 + nixConfig = {}; # attrset (free-form, typed as attrs) 207 229 inputs.<name>.url = "github:foo/bar"; 208 230 inputs.<name>.flake = false; 209 231 inputs.<name>.inputs.nixpkgs.follows = "nixpkgs"; ··· 215 237 216 238 --- 217 239 218 - ## About the Flake `output` function 240 + ## About the Flake `outputs` function 219 241 220 - The `flake-file.output` option is a literal Nix expression. You cannot convert a Nix function value into a string for including in the generated flake file. 242 + The `flake-file.outputs` option is a literal Nix expression. You cannot convert a Nix function value into a string for including in the generated flake file. 221 243 222 244 It defaults to: 223 245 ··· 269 291 270 292 ## Automatic flake.lock flattening 271 293 272 - You can use the `prune-lock` [options](https://github.com/vic/flake-file/blob/main/modules/options.nix) 294 + You can use the `prune-lock` [options](https://github.com/vic/flake-file/blob/main/modules/options/prune-lock.nix) 273 295 to specify a command that `flake-file` will use whenever your flake.nix file is generated 274 296 to flatten your flake.lock dependency tree. 275 297 ··· 284 306 imports = [ 285 307 inputs.flake-file.flakeModules.nix-auto-follow 286 308 # or optionally 287 - #inputs.flake-file.flakeModules.allfollow 309 + # inputs.flake-file.flakeModules.allfollow 288 310 ]; 289 311 } 290 312 ``` ··· 296 318 This section outlines the recommended steps for adopting `flake-file` in your own repository. 297 319 298 320 1. **Prerequisite:** Ensure you have already adopted [flake-parts](https://flake.parts). 299 - 2. **Add Inputs:** In your current `flake.nix`, add the following input: 321 + 322 + 1. **Add Inputs:** In your current `flake.nix`, add the following input: 300 323 301 324 ```nix 302 325 flake-file.url = "github:vic/flake-file"; 303 326 ``` 304 327 305 - 3. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`: 328 + 1. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`: 306 329 307 330 ```nix 308 331 # outputs.nix -- this is the contents of your `outputs` function from the original flake.nix file. ··· 315 338 } 316 339 ``` 317 340 318 - 4. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`): 341 + 1. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`): 319 342 320 343 > [!IMPORTANT] 321 344 > Make sure you `git add` so that new files are visible to Nix. ··· 339 362 ``` 340 363 341 364 5. **Backup:** Back up your flake.nix into flake.nix.bak before regenerating it. 342 - 6. **Generate:** Execute `nix run .#write-flake` to generate flake.nix. 343 - 7. **Verify:** Check flake.nix and if everything is okay, remove the backup file. 365 + 1. **Generate:** Execute `nix run .#write-flake` to generate flake.nix. 366 + 1. **Verify:** Check flake.nix and if everything is okay, remove the backup file. 344 367 345 368 You are done! Now you can split dependencies from `modules/inputs.nix` into other flake-part modules as you see fit: 346 369 ··· 378 401 379 402 --- 380 403 381 - Made with <3 by [@vic](https://x.com/oeiuwq) 404 + Made with \<3 by [@vic](https://x.com/oeiuwq)
+40 -50
dev/flake.lock
··· 1 1 { 2 2 "nodes": { 3 - "den": { 4 - "locked": { 5 - "lastModified": 1761530965, 6 - "narHash": "sha256-ieTMY6bsJbl87/XugjWFid6EN9q1C0rFdaPoYCfm1Kk=", 7 - "owner": "vic", 8 - "repo": "den", 9 - "rev": "ef58a62952eaf82f391dbe24ec693996d5abc505", 10 - "type": "github" 11 - }, 12 - "original": { 13 - "owner": "vic", 14 - "repo": "den", 15 - "type": "github" 16 - } 17 - }, 18 3 "devshell": { 19 4 "inputs": { 20 5 "nixpkgs": [ ··· 22 7 ] 23 8 }, 24 9 "locked": { 25 - "lastModified": 1741473158, 26 - "narHash": "sha256-kWNaq6wQUbUMlPgw8Y+9/9wP0F8SHkjy24/mN3UAppg=", 10 + "lastModified": 1762521437, 11 + "narHash": "sha256-RXN+lcx4DEn3ZS+LqEJSUu/HH+dwGvy0syN7hTo/Chg=", 27 12 "owner": "numtide", 28 13 "repo": "devshell", 29 - "rev": "7c9e793ebe66bcba8292989a68c0419b737a22a0", 14 + "rev": "07bacc9531f5f4df6657c0a02a806443685f384a", 30 15 "type": "github" 31 16 }, 32 17 "original": { ··· 35 20 "type": "github" 36 21 } 37 22 }, 38 - "flake-aspects": { 39 - "locked": { 40 - "lastModified": 1761515738, 41 - "narHash": "sha256-uW/vyyZDt9UvJbC0xghkjZhuuSnJui/fevMbKsvXV6k=", 42 - "owner": "vic", 43 - "repo": "flake-aspects", 44 - "rev": "0fb045faceaeefa83a85173fd0c4ebf4d47a6d9d", 45 - "type": "github" 46 - }, 47 - "original": { 48 - "owner": "vic", 49 - "repo": "flake-aspects", 50 - "type": "github" 51 - } 52 - }, 53 23 "flake-file": { 54 24 "locked": { 55 25 "path": "..", ··· 68 38 ] 69 39 }, 70 40 "locked": { 71 - "lastModified": 1760948891, 72 - "narHash": "sha256-TmWcdiUUaWk8J4lpjzu4gCGxWY6/Ok7mOK4fIFfBuU4=", 41 + "lastModified": 1762980239, 42 + "narHash": "sha256-8oNVE8TrD19ulHinjaqONf9QWCKK+w4url56cdStMpM=", 73 43 "owner": "hercules-ci", 74 44 "repo": "flake-parts", 75 - "rev": "864599284fc7c0ba6357ed89ed5e2cd5040f0c04", 45 + "rev": "52a2caecc898d0b46b2b905f058ccc5081f842da", 76 46 "type": "github" 77 47 }, 78 48 "original": { ··· 83 53 }, 84 54 "import-tree": { 85 55 "locked": { 86 - "lastModified": 1761120675, 87 - "narHash": "sha256-TEbh9zISiQcU82VwVoEbmXHnSGlUxTwvjJA9g9ErSDA=", 56 + "lastModified": 1763695721, 57 + "narHash": "sha256-tMfN/JkwWJ129cXDW+lK2gUcjklJ+LpTHj9LlneJRXg=", 88 58 "owner": "vic", 89 59 "repo": "import-tree", 90 - "rev": "a037ed2a58fc0ebed9e93b9ef79b0646e648f719", 60 + "rev": "ca69d64711265c68cf71f6c029ab9f1a55a767f8", 91 61 "type": "github" 92 62 }, 93 63 "original": { ··· 116 86 "type": "github" 117 87 } 118 88 }, 89 + "nix-github-actions": { 90 + "inputs": { 91 + "nixpkgs": [ 92 + "nix-unit", 93 + "nixpkgs" 94 + ] 95 + }, 96 + "locked": { 97 + "lastModified": 1737420293, 98 + "narHash": "sha256-F1G5ifvqTpJq7fdkT34e/Jy9VCyzd5XfJ9TO8fHhJWE=", 99 + "owner": "nix-community", 100 + "repo": "nix-github-actions", 101 + "rev": "f4158fa080ef4503c8f4c820967d946c2af31ec9", 102 + "type": "github" 103 + }, 104 + "original": { 105 + "owner": "nix-community", 106 + "repo": "nix-github-actions", 107 + "type": "github" 108 + } 109 + }, 119 110 "nix-unit": { 120 111 "inputs": { 121 112 "flake-parts": [ 122 113 "flake-parts" 123 114 ], 115 + "nix-github-actions": "nix-github-actions", 124 116 "nixpkgs": [ 125 117 "nixpkgs" 126 118 ], ··· 129 121 ] 130 122 }, 131 123 "locked": { 132 - "lastModified": 1757781724, 133 - "narHash": "sha256-DP5SCFx0AsbPnT7KzEl3gQNWPF70Tlcc+jtLkqupabI=", 124 + "lastModified": 1762774186, 125 + "narHash": "sha256-hRADkHjNt41+JUHw2EiSkMaL4owL83g5ZppjYUdF/Dc=", 134 126 "owner": "nix-community", 135 127 "repo": "nix-unit", 136 - "rev": "7a952131cbef9cb21953ae70ad09249541848f07", 128 + "rev": "1c9ab50554eed0b768f9e5b6f646d63c9673f0f7", 137 129 "type": "github" 138 130 }, 139 131 "original": { ··· 144 136 }, 145 137 "nixpkgs": { 146 138 "locked": { 147 - "lastModified": 1761349956, 148 - "narHash": "sha256-tH3wHnOJms+U4k/rK2Nn1RfBrhffX92jLP/2VndSn0w=", 139 + "lastModified": 1763618868, 140 + "narHash": "sha256-v5afmLjn/uyD9EQuPBn7nZuaZVV9r+JerayK/4wvdWA=", 149 141 "owner": "nixos", 150 142 "repo": "nixpkgs", 151 - "rev": "02f2cb8e0feb4596d20cc52fda73ccee960e3538", 143 + "rev": "a8d610af3f1a5fb71e23e08434d8d61a466fc942", 152 144 "type": "github" 153 145 }, 154 146 "original": { ··· 160 152 }, 161 153 "root": { 162 154 "inputs": { 163 - "den": "den", 164 155 "devshell": "devshell", 165 - "flake-aspects": "flake-aspects", 166 156 "flake-file": "flake-file", 167 157 "flake-parts": "flake-parts", 168 158 "import-tree": "import-tree", ··· 198 188 ] 199 189 }, 200 190 "locked": { 201 - "lastModified": 1761311587, 202 - "narHash": "sha256-Msq86cR5SjozQGCnC6H8C+0cD4rnx91BPltZ9KK613Y=", 191 + "lastModified": 1762938485, 192 + "narHash": "sha256-AlEObg0syDl+Spi4LsZIBrjw+snSVU4T8MOeuZJUJjM=", 203 193 "owner": "numtide", 204 194 "repo": "treefmt-nix", 205 - "rev": "2eddae033e4e74bf581c2d1dfa101f9033dbd2dc", 195 + "rev": "5b4ee75aeefd1e2d5a1cc43cf6ba65eba75e83e4", 206 196 "type": "github" 207 197 }, 208 198 "original": {
+12 -50
dev/flake.nix
··· 5 5 outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules); 6 6 7 7 inputs = { 8 - den = { 9 - url = "github:vic/den"; 10 - }; 11 8 devshell = { 12 - inputs = { 13 - nixpkgs = { 14 - follows = "nixpkgs"; 15 - }; 16 - }; 9 + inputs.nixpkgs.follows = "nixpkgs"; 17 10 url = "github:numtide/devshell"; 18 11 }; 19 - flake-aspects = { 20 - url = "github:vic/flake-aspects"; 21 - }; 22 - flake-file = { 23 - url = "path:.."; 24 - }; 12 + flake-file.url = "path:.."; 25 13 flake-parts = { 26 - inputs = { 27 - nixpkgs-lib = { 28 - follows = "nixpkgs-lib"; 29 - }; 30 - }; 14 + inputs.nixpkgs-lib.follows = "nixpkgs-lib"; 31 15 url = "github:hercules-ci/flake-parts"; 32 16 }; 33 - import-tree = { 34 - url = "github:vic/import-tree"; 35 - }; 17 + import-tree.url = "github:vic/import-tree"; 36 18 nix-auto-follow = { 37 - inputs = { 38 - nixpkgs = { 39 - follows = "nixpkgs"; 40 - }; 41 - }; 19 + inputs.nixpkgs.follows = "nixpkgs"; 42 20 url = "github:fzakaria/nix-auto-follow"; 43 21 }; 44 22 nix-unit = { 45 23 inputs = { 46 - flake-parts = { 47 - follows = "flake-parts"; 48 - }; 49 - nixpkgs = { 50 - follows = "nixpkgs"; 51 - }; 52 - treefmt-nix = { 53 - follows = "treefmt-nix"; 54 - }; 24 + flake-parts.follows = "flake-parts"; 25 + nixpkgs.follows = "nixpkgs"; 26 + treefmt-nix.follows = "treefmt-nix"; 55 27 }; 56 28 url = "github:nix-community/nix-unit"; 57 29 }; 58 - nixpkgs = { 59 - url = "github:nixos/nixpkgs/nixpkgs-unstable"; 60 - }; 61 - nixpkgs-lib = { 62 - follows = "nixpkgs"; 63 - }; 64 - systems = { 65 - url = "github:nix-systems/default"; 66 - }; 30 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 31 + nixpkgs-lib.follows = "nixpkgs"; 32 + systems.url = "github:nix-systems/default"; 67 33 treefmt-nix = { 68 - inputs = { 69 - nixpkgs = { 70 - follows = "nixpkgs"; 71 - }; 72 - }; 34 + inputs.nixpkgs.follows = "nixpkgs"; 73 35 url = "github:numtide/treefmt-nix"; 74 36 }; 75 37 };
+5 -2
dev/modules/_lib/default.nix
··· 41 41 _: input: 42 42 mergeNonEmptyAttrs input { 43 43 follows = { 44 - testEmpty = v: v == null; # allow empty follows string 44 + testEmpty = v: !builtins.isString v; 45 45 }; 46 46 inputs = nonEmptyInputs input; 47 47 } ··· 52 52 mergeNonEmptyAttrs input { 53 53 url = { }; 54 54 type = { }; 55 + submodules = { }; 55 56 owner = { }; 56 57 repo = { }; 57 58 path = { }; ··· 67 68 flake = false; 68 69 }; 69 70 }; 70 - follows = { }; 71 + follows = { 72 + testEmpty = x: !builtins.isString x; 73 + }; 71 74 inputs = nonEmptyInputs input; 72 75 } 73 76 );
+36 -2
dev/modules/formatter.nix
··· 1 - { inputs, ... }: 1 + { inputs, lib, ... }: 2 2 { 3 - perSystem.treefmt.projectRoot = inputs.flake-file; 3 + 4 + imports = [ 5 + inputs.flake-file.flakeModules.nix-auto-follow 6 + inputs.treefmt-nix.flakeModule 7 + ]; 8 + 9 + flake-file.inputs = { 10 + treefmt-nix.url = lib.mkDefault "github:numtide/treefmt-nix"; 11 + treefmt-nix.inputs.nixpkgs.follows = lib.mkDefault "nixpkgs"; 12 + }; 13 + 14 + perSystem = 15 + { self', ... }: 16 + { 17 + packages.fmt = self'.formatter; 18 + treefmt = { 19 + projectRoot = inputs.flake-file; 20 + programs = { 21 + nixfmt.enable = true; 22 + deadnix.enable = true; 23 + nixf-diagnose.enable = true; 24 + prettier.enable = true; 25 + }; 26 + settings.on-unmatched = lib.mkDefault "fatal"; 27 + settings.global.excludes = [ 28 + "LICENSE" 29 + "flake.lock" 30 + "*/flake.lock" 31 + ".envrc" 32 + ".direnv/*" 33 + "*/.gitignore" 34 + ]; 35 + }; 36 + }; 37 + 4 38 }
+1 -1
dev/modules/regen.nix
··· 3 3 perSystem = 4 4 { pkgs, ... }: 5 5 let 6 - exe = name: pkgs.lib.getExe inputs.self.packages.${pkgs.system}.${name}; 6 + exe = name: pkgs.lib.getExe inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.${name}; 7 7 puke = exe "puke"; 8 8 oneach = exe "oneach"; 9 9 each = exe "each";
+11
dev/modules/unit-tests/inputsExpr.nix
··· 68 68 }; 69 69 }; 70 70 71 + tests.inputsExpr."test top-input follows empty" = { 72 + expr = inputsExpr { 73 + foo.url = "foo"; 74 + bar.follows = ""; 75 + }; 76 + expected = { 77 + foo.url = "foo"; 78 + bar.follows = ""; 79 + }; 80 + }; 81 + 71 82 in 72 83 { 73 84 flake = { inherit tests; };
-1
modules/dendritic/basic.nix
··· 4 4 imports = [ 5 5 inputs.flake-file.flakeModules.default 6 6 inputs.flake-file.flakeModules.import-tree 7 - inputs.flake-file.flakeModules.nix-auto-follow 8 7 ]; 9 8 10 9 flake-file.inputs = {
-1
modules/dendritic/default.nix
··· 3 3 imports = [ 4 4 ./dendritic.nix 5 5 ./basic.nix 6 - ./formatter.nix 7 6 ./nixpkgs.nix 8 7 ./systems.nix 9 8 ];
+2 -4
modules/dendritic/dendritic.nix
··· 4 4 imports = [ 5 5 (inputs.flake-parts.flakeModules.modules or { }) 6 6 (inputs.flake-file.flakeModules.import-tree or { }) 7 - (inputs.flake-aspects.flakeModule or { }) 8 - (inputs.den.flakeModule or { }) 9 7 ]; 10 8 11 9 flake-file.inputs = { 12 10 flake-parts.url = lib.mkDefault "github:hercules-ci/flake-parts"; 13 11 flake-parts.inputs.nixpkgs-lib.follows = lib.mkDefault "nixpkgs-lib"; 14 - flake-aspects.url = lib.mkDefault "github:vic/flake-aspects"; 15 - den.url = lib.mkDefault "github:vic/den"; 16 12 }; 17 13 18 14 flake-file.outputs = '' 19 15 inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules) 20 16 ''; 17 + 18 + flake.modules = { }; 21 19 22 20 }
-36
modules/dendritic/formatter.nix
··· 1 - { inputs, lib, ... }: 2 - { 3 - 4 - imports = [ 5 - inputs.treefmt-nix.flakeModule 6 - ]; 7 - 8 - flake-file.inputs = { 9 - treefmt-nix.url = lib.mkDefault "github:numtide/treefmt-nix"; 10 - treefmt-nix.inputs.nixpkgs.follows = lib.mkDefault "nixpkgs"; 11 - }; 12 - 13 - perSystem = 14 - { self', ... }: 15 - { 16 - packages.fmt = self'.formatter; 17 - treefmt = { 18 - programs = { 19 - nixfmt.enable = true; 20 - deadnix.enable = true; 21 - nixf-diagnose.enable = true; 22 - prettier.enable = true; 23 - }; 24 - settings.on-unmatched = lib.mkDefault "fatal"; 25 - settings.global.excludes = [ 26 - "LICENSE" 27 - "flake.lock" 28 - "*/flake.lock" 29 - ".envrc" 30 - ".direnv/*" 31 - "*/.gitignore" 32 - ]; 33 - }; 34 - }; 35 - 36 - }
+7 -2
modules/options/inputs.nix
··· 2 2 let 3 3 follows-option = lib.mkOption { 4 4 description = "flake input path to follow"; 5 - default = ""; 6 - type = lib.types.str; 5 + default = null; 6 + type = lib.types.nullOr lib.types.str; 7 7 }; 8 8 9 9 inputs-follow-option = lib.mkOption { ··· 46 46 "sourcehut" 47 47 ] 48 48 ); 49 + }; 50 + submodules = lib.mkOption { 51 + description = "Whether to checkout git submodules"; 52 + default = null; 53 + type = lib.types.nullOr lib.types.bool; 49 54 }; 50 55 owner = lib.mkOption { 51 56 description = "owner of the repository";
+1 -1
modules/options/prune-lock.nix
··· 44 44 runtimeInputs = [ pkgs.diffutils ]; 45 45 text = '' 46 46 ${prune-cmd pkgs} "$1"/flake.lock pruned.lock 47 - diff -u pruned.lock "$1"/flake.lock 47 + diff -u "$1"/flake.lock pruned.lock 48 48 ''; 49 49 }; 50 50
+1 -1
modules/prune-lock/allfollow.nix
··· 6 6 pkgs: 7 7 pkgs.writeShellApplication { 8 8 name = "allfollow"; 9 - runtimeInputs = [ inputs.allfollow.packages.${pkgs.system}.default ]; 9 + runtimeInputs = [ inputs.allfollow.packages.${pkgs.stdenv.hostPlatform.system}.default ]; 10 10 text = '' 11 11 allfollow prune --pretty "$1" -o "$2" 12 12 '';
+1 -1
modules/prune-lock/nix-auto-follow.nix
··· 10 10 pkgs: 11 11 pkgs.writeShellApplication { 12 12 name = "nix-auto-follow"; 13 - runtimeInputs = [ inputs.nix-auto-follow.packages.${pkgs.system}.default ]; 13 + runtimeInputs = [ inputs.nix-auto-follow.packages.${pkgs.stdenv.hostPlatform.system}.default ]; 14 14 text = '' 15 15 auto-follow "$1" > "$2" 16 16 '';
+21 -2
modules/write-flake.nix
··· 26 26 addHeader 27 27 ]; 28 28 29 + nixAttr = 30 + name: value: 31 + let 32 + childIsAttr = builtins.isAttrs value; 33 + childIsOne = builtins.length (builtins.attrNames value) == 1; 34 + nested = lib.head (lib.mapAttrsToList nixAttr value); 35 + in 36 + if childIsAttr && childIsOne then 37 + { 38 + name = "${name}.${nested.name}"; 39 + value = nested.value; 40 + } 41 + else 42 + { 43 + inherit name; 44 + value = value; 45 + }; 46 + 29 47 # expr to code 30 48 nixCode = 31 49 x: ··· 33 51 lib.strings.escapeNixString x 34 52 else if lib.isAttrs x then 35 53 lib.pipe x [ 36 - (lib.mapAttrsToList (name: value: ''${name} = ${nixCode value}; '')) 54 + (lib.mapAttrsToList nixAttr) 55 + (map ({ name, value }: ''${name} = ${nixCode value}; '')) 37 56 (values: ''{ ${lib.concatStringsSep " " values} }'') 38 57 ] 39 58 else if lib.isList x then ··· 125 144 } 126 145 '' 127 146 set -e 128 - diff -u ${formatted pkgs} ${inputs.self}/flake.nix 147 + diff -u ${inputs.self}/flake.nix ${formatted pkgs} 129 148 ${hooks} 130 149 touch $out 131 150 '';
+4 -12
templates/default/flake.nix
··· 5 5 outputs = inputs: import ./outputs.nix inputs; 6 6 7 7 inputs = { 8 - flake-file = { 9 - url = "github:vic/flake-file"; 10 - }; 11 - flake-parts = { 12 - url = "github:hercules-ci/flake-parts"; 13 - }; 14 - nixpkgs = { 15 - url = "github:nixos/nixpkgs/nixpkgs-unstable"; 16 - }; 17 - systems = { 18 - url = "github:nix-systems/default"; 19 - }; 8 + flake-file.url = "github:vic/flake-file"; 9 + flake-parts.url = "github:hercules-ci/flake-parts"; 10 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 11 + systems.url = "github:nix-systems/default"; 20 12 }; 21 13 22 14 }
+6 -27
templates/dendritic/flake.nix
··· 5 5 outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules); 6 6 7 7 inputs = { 8 - den = { 9 - url = "github:vic/den"; 10 - }; 11 - flake-aspects = { 12 - url = "github:vic/flake-aspects"; 13 - }; 14 - flake-file = { 15 - url = "github:vic/flake-file"; 16 - }; 8 + flake-file.url = "github:vic/flake-file"; 17 9 flake-parts = { 10 + inputs.nixpkgs-lib.follows = "nixpkgs-lib"; 18 11 url = "github:hercules-ci/flake-parts"; 19 12 }; 20 - import-tree = { 21 - url = "github:vic/import-tree"; 22 - }; 23 - nix-auto-follow = { 24 - url = "github:fzakaria/nix-auto-follow"; 25 - }; 26 - nixpkgs = { 27 - url = "github:nixos/nixpkgs/nixpkgs-unstable"; 28 - }; 29 - nixpkgs-lib = { 30 - follows = "nixpkgs"; 31 - }; 32 - systems = { 33 - url = "github:nix-systems/default"; 34 - }; 35 - treefmt-nix = { 36 - url = "github:numtide/treefmt-nix"; 37 - }; 13 + import-tree.url = "github:vic/import-tree"; 14 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 15 + nixpkgs-lib.follows = "nixpkgs"; 16 + systems.url = "github:nix-systems/default"; 38 17 }; 39 18 40 19 }
+5 -15
templates/parts/flake.nix
··· 10 10 }; 11 11 12 12 inputs = { 13 - flake-file = { 14 - url = "github:vic/flake-file"; 15 - }; 16 - flake-parts = { 17 - url = "github:hercules-ci/flake-parts"; 18 - }; 19 - nixpkgs = { 20 - url = "github:nixos/nixpkgs/nixpkgs-unstable"; 21 - }; 22 - systems = { 23 - url = "github:nix-systems/default"; 24 - }; 25 - treefmt-nix = { 26 - url = "github:numtide/treefmt-nix"; 27 - }; 13 + flake-file.url = "github:vic/flake-file"; 14 + flake-parts.url = "github:hercules-ci/flake-parts"; 15 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 16 + systems.url = "github:nix-systems/default"; 17 + treefmt-nix.url = "github:numtide/treefmt-nix"; 28 18 }; 29 19 30 20 }