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.

+366 -92
-1
.github/FUNDING.yml
··· 1 # These are supported funding model platforms 2 - 3 github: [vic] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 patreon: # Replace with a single Patreon username 5 open_collective: # Replace with a single Open Collective username
··· 1 # These are supported funding model platforms 2 github: [vic] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 3 patreon: # Replace with a single Patreon username 4 open_collective: # Replace with a single Open Collective username
+16
.github/workflows/flake-check.yaml
··· 23 strategy: 24 matrix: 25 template: ${{ fromJSON(needs.find-templates.outputs.templates) }} 26 steps: 27 - uses: wimpysworld/nothing-but-nix@main 28 - uses: cachix/install-nix-action@v31 ··· 44 nix flake metadata 45 nix run .#write-flake -L --show-trace 46 nix flake check -L --show-trace 47 dev: 48 name: Check flake dev 49 runs-on: ubuntu-latest
··· 23 strategy: 24 matrix: 25 template: ${{ fromJSON(needs.find-templates.outputs.templates) }} 26 + exclude: 27 + - template: "unflake" 28 steps: 29 - uses: wimpysworld/nothing-but-nix@main 30 - uses: cachix/install-nix-action@v31 ··· 46 nix flake metadata 47 nix run .#write-flake -L --show-trace 48 nix flake check -L --show-trace 49 + unflake: 50 + name: Check unflake 51 + runs-on: ubuntu-latest 52 + steps: 53 + - uses: actions/checkout@v4 54 + - uses: wimpysworld/nothing-but-nix@main 55 + - uses: cachix/install-nix-action@v31 56 + - uses: DeterminateSystems/magic-nix-cache-action@main 57 + - run: | 58 + set -e -o pipefail 59 + cd templates/unflake 60 + sed -i 's/# flake-file = import/flake-file = import/' default.nix 61 + echo "{ inputs, ... }: { unflake.pkgs = import inputs.nixpkgs {}; }" | tee modules/pkgs.nix 62 + nix-shell . -A unflake.env --run 'write-unflake --verbose' 63 dev: 64 name: Check flake dev 65 runs-on: ubuntu-latest
-11
.github/workflows/tangled.yaml
··· 1 - on: 2 - workflow_dispatch: 3 - push: 4 - concurrency: 5 - group: tangled 6 - cancel-in-progress: true 7 - jobs: 8 - tangled: 9 - uses: vic/vic/.github/workflows/tangled.yml@main 10 - secrets: 11 - TANGLED_SSH_KEY: ${{secrets.TANGLED_SSH_KEY}}
···
+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
+28 -14
README.md
··· 1 <!-- Badges --> 2 <p align="right"> 3 <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"/> 4 </a> ··· 8 <a href="LICENSE"> <img src="https://img.shields.io/github/license/vic/flake-file" alt="License"/> </a> 9 </p> 10 11 - # flake-file — Generate flake.nix from flake-parts modules. 12 13 > `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) 14 15 - **flake-file** lets you generate a clean, maintainable `flake.nix` from modular options, using [flake-parts](https://flake.parts/). 16 17 It makes your flake configuration modular and based on the Nix module system. This means you can use 18 `lib.mkDefault` or anything you normally do with Nix modules, and have them reflected in flake schema values. 19 20 <table><tr><td> 21 22 ## Features 23 24 - - Flake definition aggregated from all flake-parts modules. 25 - Schema as [options](https://github.com/vic/flake-file/blob/main/modules/options/default.nix). 26 - Syntax for nixConfig and follows is the same as in flakes. 27 - `flake check` ensures files are up to date. 28 - - App for generator: `nix run .#write-flake` 29 - Custom do-not-edit header. 30 - Automatic flake.lock [flattening](#automatic-flakelock-flattening). 31 - Incrementally add [flake-parts-builder](#parts_templates) templates. 32 - Pick flakeModules for different feature sets. 33 - [Dendritic](https://vic.github.io/dendrix/Dendritic.html) flake template. 34 35 </td><td> 36 ··· 59 ## Who is this for? 60 61 - Nix users who want to keep their `flake.nix` modular and maintainable 62 - - Anyone using [flake-parts](https://flake.parts/) and looking to automate or simplify flake input management 63 - Teams or individuals who want to share and reuse flake modules across projects 64 65 --- ··· 147 148 > 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. 149 150 ### Flake Templates 151 152 - #### `default` template 153 154 A more basic, explicit setup. 155 ··· 177 > [!TIP] 178 > You can use the `write-flake` app as part of a devshell or git hook. 179 180 - #### `dendritic` template 181 182 A template for dendritic setups; includes `flakeModules.dendritic`. 183 184 - #### `parts` template 185 186 A template that uses `lib.flakeModules.flake-parts-builder`. 187 188 --- 189 ··· 317 This section outlines the recommended steps for adopting `flake-file` in your own repository. 318 319 1. **Prerequisite:** Ensure you have already adopted [flake-parts](https://flake.parts). 320 - 2. **Add Inputs:** In your current `flake.nix`, add the following input: 321 322 ```nix 323 flake-file.url = "github:vic/flake-file"; 324 ``` 325 326 - 3. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`: 327 328 ```nix 329 # outputs.nix -- this is the contents of your `outputs` function from the original flake.nix file. ··· 336 } 337 ``` 338 339 - 4. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`): 340 341 > [!IMPORTANT] 342 > Make sure you `git add` so that new files are visible to Nix. ··· 360 ``` 361 362 5. **Backup:** Back up your flake.nix into flake.nix.bak before regenerating it. 363 - 6. **Generate:** Execute `nix run .#write-flake` to generate flake.nix. 364 - 7. **Verify:** Check flake.nix and if everything is okay, remove the backup file. 365 366 You are done! Now you can split dependencies from `modules/inputs.nix` into other flake-part modules as you see fit: 367 ··· 399 400 --- 401 402 - Made with <3 by [@vic](https://x.com/oeiuwq)
··· 1 <!-- Badges --> 2 + 3 <p align="right"> 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> ··· 9 <a href="LICENSE"> <img src="https://img.shields.io/github/license/vic/flake-file" alt="License"/> </a> 10 </p> 11 12 + # Generate `flake.nix`/`unflake.nix`/`npins` from inputs defined as module options. 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 16 + **flake-file** lets you generate a clean, maintainable `flake.nix` from modular options. Use the _real_ Nix language to define your inputs. 17 18 It makes your flake configuration modular and based on the Nix module system. This means you can use 19 `lib.mkDefault` or anything you normally do with Nix modules, and have them reflected in flake schema values. 20 + 21 + > Despite the original flake-oriented name, it NOW also works on _stable Nix_, [_non flakes_](templates/unflake) environments. 22 23 <table><tr><td> 24 25 ## Features 26 27 + - Flake definition aggregated from Nix modules. 28 - Schema as [options](https://github.com/vic/flake-file/blob/main/modules/options/default.nix). 29 - Syntax for nixConfig and follows is the same as in flakes. 30 - `flake check` ensures files are up to date. 31 + - App for `flake.nix` generator: `nix run .#write-flake` 32 - Custom do-not-edit header. 33 - Automatic flake.lock [flattening](#automatic-flakelock-flattening). 34 - Incrementally add [flake-parts-builder](#parts_templates) templates. 35 - Pick flakeModules for different feature sets. 36 - [Dendritic](https://vic.github.io/dendrix/Dendritic.html) flake template. 37 + - Works on stable Nix, [unflake](templates/unflake) environments. 38 39 </td><td> 40 ··· 63 ## Who is this for? 64 65 - Nix users who want to keep their `flake.nix` modular and maintainable 66 + - Anyone using Nix modules and looking to automate or simplify flake input management 67 - Teams or individuals who want to share and reuse flake modules across projects 68 69 --- ··· 151 152 > 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. 153 154 + #### [`flakeModules.unflake`](https://github.com/vic/flake-file/tree/main/modules/unflake.nix) 155 + 156 + - Defines `flake-file` options. 157 + - Exposes `write-unflake` to generate `unflake.nix` or `npins`. See [templates/unflake](templates/unflake) for usage. 158 + 159 ### Flake Templates 160 161 + #### [`default`](templates/default) template 162 163 A more basic, explicit setup. 164 ··· 186 > [!TIP] 187 > You can use the `write-flake` app as part of a devshell or git hook. 188 189 + #### [`dendritic`](templates/dendritic) template 190 191 A template for dendritic setups; includes `flakeModules.dendritic`. 192 193 + #### [`parts`](templates/parts) template 194 195 A template that uses `lib.flakeModules.flake-parts-builder`. 196 + 197 + #### [`unflake`](templates/unflake) template 198 + 199 + Uses [goldstein/unflake](https://codeberg.org/goldstein/unflake) to pin and fetch inputs that were defined as options for non-flakes stable Nix environments. 200 201 --- 202 ··· 330 This section outlines the recommended steps for adopting `flake-file` in your own repository. 331 332 1. **Prerequisite:** Ensure you have already adopted [flake-parts](https://flake.parts). 333 + 334 + 1. **Add Inputs:** In your current `flake.nix`, add the following input: 335 336 ```nix 337 flake-file.url = "github:vic/flake-file"; 338 ``` 339 340 + 1. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`: 341 342 ```nix 343 # outputs.nix -- this is the contents of your `outputs` function from the original flake.nix file. ··· 350 } 351 ``` 352 353 + 1. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`): 354 355 > [!IMPORTANT] 356 > Make sure you `git add` so that new files are visible to Nix. ··· 374 ``` 375 376 5. **Backup:** Back up your flake.nix into flake.nix.bak before regenerating it. 377 + 1. **Generate:** Execute `nix run .#write-flake` to generate flake.nix. 378 + 1. **Verify:** Check flake.nix and if everything is okay, remove the backup file. 379 380 You are done! Now you can split dependencies from `modules/inputs.nix` into other flake-part modules as you see fit: 381 ··· 413 414 --- 415 416 + Made with \<3 by [@vic](https://x.com/oeiuwq)
+7 -10
dev/flake.lock
··· 136 }, 137 "nixpkgs": { 138 "locked": { 139 - "lastModified": 1763618868, 140 - "narHash": "sha256-v5afmLjn/uyD9EQuPBn7nZuaZVV9r+JerayK/4wvdWA=", 141 - "owner": "nixos", 142 - "repo": "nixpkgs", 143 - "rev": "a8d610af3f1a5fb71e23e08434d8d61a466fc942", 144 - "type": "github" 145 }, 146 "original": { 147 - "owner": "nixos", 148 - "ref": "nixpkgs-unstable", 149 - "repo": "nixpkgs", 150 - "type": "github" 151 } 152 }, 153 "root": {
··· 136 }, 137 "nixpkgs": { 138 "locked": { 139 + "lastModified": 1770843696, 140 + "narHash": "sha256-9SFCZkVcpDOV6unH5hVEy4+dB0rxMuUoBnDAO6vshac=", 141 + "rev": "2343bbb58f99267223bc2aac4fc9ea301a155a16", 142 + "type": "tarball", 143 + "url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.05pre944764.2343bbb58f99/nixexprs.tar.xz" 144 }, 145 "original": { 146 + "type": "tarball", 147 + "url": "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz" 148 } 149 }, 150 "root": {
+1 -1
dev/flake.nix
··· 27 }; 28 url = "github:nix-community/nix-unit"; 29 }; 30 - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 31 nixpkgs-lib.follows = "nixpkgs"; 32 systems.url = "github:nix-systems/default"; 33 treefmt-nix = {
··· 27 }; 28 url = "github:nix-community/nix-unit"; 29 }; 30 + nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; 31 nixpkgs-lib.follows = "nixpkgs"; 32 systems.url = "github:nix-systems/default"; 33 treefmt-nix = {
+43 -2
dev/modules/_lib/default.nix
··· 6 isEmpty = 7 x: 8 ( 9 - (builtins.isNull x) 10 || (lib.isStringLike x && lib.stringLength (lib.trim x) == 0) 11 || (lib.isList x && lib.length x == 0) 12 || (lib.isAttrs x && x == { }) ··· 75 } 76 ); 77 78 in 79 { 80 - inherit inputsExpr isNonEmptyString; 81 }
··· 6 isEmpty = 7 x: 8 ( 9 + (isNull x) 10 || (lib.isStringLike x && lib.stringLength (lib.trim x) == 0) 11 || (lib.isList x && lib.length x == 0) 12 || (lib.isAttrs x && x == { }) ··· 75 } 76 ); 77 78 + nixAttr = 79 + name: value: 80 + let 81 + childIsAttr = builtins.isAttrs value; 82 + childIsOne = builtins.length (builtins.attrNames value) == 1; 83 + nested = lib.head (lib.mapAttrsToList nixAttr value); 84 + in 85 + if childIsAttr && childIsOne then 86 + { 87 + name = "${name}.${nested.name}"; 88 + value = nested.value; 89 + } 90 + else 91 + { 92 + inherit name; 93 + value = value; 94 + }; 95 + 96 + # expr to code 97 + nixCode = 98 + x: 99 + if lib.isStringLike x then 100 + lib.strings.escapeNixString x 101 + else if lib.isAttrs x then 102 + lib.pipe x [ 103 + (lib.mapAttrsToList nixAttr) 104 + (map ({ name, value }: "${name} = ${nixCode value}; ")) 105 + (values: "{ ${lib.concatStringsSep " " values} }") 106 + ] 107 + else if lib.isList x then 108 + lib.pipe x [ 109 + (lib.map nixCode) 110 + (values: "[ ${lib.concatStringsSep " " values} ]") 111 + ] 112 + else if x == true then 113 + "true" 114 + else if x == false then 115 + "false" 116 + else 117 + toString x; 118 + 119 in 120 { 121 + inherit inputsExpr isNonEmptyString nixCode; 122 }
+2
dev/modules/formatter.nix
··· 31 ".envrc" 32 ".direnv/*" 33 "*/.gitignore" 34 ]; 35 }; 36 };
··· 31 ".envrc" 32 ".direnv/*" 33 "*/.gitignore" 34 + "**/unflake.nix" # generated by: nix-shell . -A unflake.env --run write-unflake 35 + "**/inputs.nix" # generated by: nix-shell . -A unflake.env --run write-inputs 36 ]; 37 }; 38 };
+11
modules/default.nix
··· 6 nix-auto-follow 7 dendritic 8 import-tree 9 ; 10 }; 11 12 default.imports = [ 13 ./options ··· 34 templates.default = { 35 description = "default template"; 36 path = ./../templates/default; 37 }; 38 39 templates.dendritic = {
··· 6 nix-auto-follow 7 dendritic 8 import-tree 9 + unflake 10 ; 11 }; 12 + 13 + unflake.imports = [ 14 + ./options 15 + ./unflake.nix 16 + ]; 17 18 default.imports = [ 19 ./options ··· 40 templates.default = { 41 description = "default template"; 42 path = ./../templates/default; 43 + }; 44 + 45 + templates.unflake = { 46 + description = "unflake template"; 47 + path = ./../templates/unflake; 48 }; 49 50 templates.dendritic = {
+1 -1
modules/dendritic/dendritic.nix
··· 11 flake-parts.inputs.nixpkgs-lib.follows = lib.mkDefault "nixpkgs-lib"; 12 }; 13 14 - flake-file.outputs = '' 15 inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules) 16 ''; 17
··· 11 flake-parts.inputs.nixpkgs-lib.follows = lib.mkDefault "nixpkgs-lib"; 12 }; 13 14 + flake-file.outputs = lib.mkDefault '' 15 inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules) 16 ''; 17
+1 -1
modules/dendritic/nixpkgs.nix
··· 2 { 3 4 flake-file.inputs = { 5 - nixpkgs.url = lib.mkDefault "github:nixos/nixpkgs/nixpkgs-unstable"; 6 nixpkgs-lib.follows = lib.mkDefault "nixpkgs"; 7 }; 8
··· 2 { 3 4 flake-file.inputs = { 5 + nixpkgs.url = lib.mkDefault "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; 6 nixpkgs-lib.follows = lib.mkDefault "nixpkgs"; 7 }; 8
+33 -1
modules/options/flake-file.nix
··· 13 nixConfig = lib.mkOption { 14 default = { }; 15 description = "nix config"; 16 - type = lib.types.attrs; 17 }; 18 }; 19 };
··· 13 nixConfig = lib.mkOption { 14 default = { }; 15 description = "nix config"; 16 + type = lib.types.submodule { 17 + freeformType = lib.types.attrsOf lib.types.anything; 18 + 19 + options = { 20 + substituters = lib.mkOption { 21 + type = lib.types.listOf lib.types.str; 22 + description = '' 23 + List of binary cache URLs used to obtain pre-built binaries 24 + of Nix packages. 25 + ''; 26 + }; 27 + 28 + extra-substituters = lib.mkOption { 29 + type = lib.types.listOf lib.types.str; 30 + description = '' 31 + List of binary cache URLs used to obtain pre-built binaries 32 + of Nix packages. 33 + ''; 34 + }; 35 + 36 + trusted-public-keys = lib.mkOption { 37 + type = lib.types.listOf lib.types.str; 38 + example = [ "hydra.nixos.org-1:CNHJZBh9K4tP3EKF6FkkgeVYsS3ohTl+oS0Qa8bezVs=" ]; 39 + description = "List of public keys used to sign binary caches."; 40 + }; 41 + 42 + extra-trusted-public-keys = lib.mkOption { 43 + type = lib.types.listOf lib.types.str; 44 + example = [ "hydra.nixos.org-1:CNHJZBh9K4tP3EKF6FkkgeVYsS3ohTl+oS0Qa8bezVs=" ]; 45 + description = "List of public keys used to sign binary caches."; 46 + }; 47 + }; 48 + }; 49 }; 50 }; 51 };
+1 -1
modules/options/formatter.nix
··· 9 The command takes flake.nix as first argument. 10 ''; 11 type = lib.types.functionTo lib.types.unspecified; 12 - default = pkgs: pkgs.nixfmt-rfc-style; 13 example = lib.literalExample '' 14 pkgs: pkgs.nixfmt-rfc-style 15 '';
··· 9 The command takes flake.nix as first argument. 10 ''; 11 type = lib.types.functionTo lib.types.unspecified; 12 + default = pkgs: pkgs.nixfmt; 13 example = lib.literalExample '' 14 pkgs: pkgs.nixfmt-rfc-style 15 '';
+65
modules/unflake.nix
···
··· 1 + { lib, config, ... }: 2 + let 3 + inherit (config.unflake) pkgs; 4 + inherit (import ./../dev/modules/_lib lib) inputsExpr nixCode; 5 + 6 + inputsString = '' 7 + # DO-NOT-EDIT: Generated by github:vic/flake-file for unflake. 8 + # To re-generate use: nix-shell . -A unflake.env --run write-inputs 9 + '' 10 + + (nixCode (inputsExpr config.flake-file.inputs)); 11 + 12 + inputsFile = pkgs.stdenvNoCC.mkDerivation { 13 + name = "inputs"; 14 + passAsFile = [ "inputsString" ]; 15 + inherit inputsString; 16 + phases = [ "copy" ]; 17 + copy = '' 18 + cp $inputsStringPath $out 19 + ''; 20 + }; 21 + 22 + write-inputs = pkgs.writeShellApplication { 23 + name = "write-inputs"; 24 + text = '' 25 + cp ${inputsFile} "''${1:-inputs.nix}" 26 + ${lib.getExe pkgs.nixfmt} "''${1:-inputs.nix}" 27 + ''; 28 + }; 29 + 30 + write-unflake = pkgs.writeShellApplication { 31 + name = "write-unflake"; 32 + text = '' 33 + nix-shell "${config.unflake.url}" -A unflake-shell --run "unflake -i ${inputsFile} $*" 34 + ''; 35 + }; 36 + 37 + env = pkgs.mkShell { 38 + buildInputs = [ 39 + write-inputs 40 + write-unflake 41 + ]; 42 + }; 43 + in 44 + { 45 + options.unflake = { 46 + url = lib.mkOption { 47 + type = lib.types.str; 48 + description = "unflake archive url"; 49 + default = "https://codeberg.org/goldstein/unflake/archive/main.tar.gz"; 50 + }; 51 + 52 + pkgs = lib.mkOption { 53 + type = lib.types.raw; 54 + description = "nixpkgs instance for unflake generator"; 55 + default = import <nixpkgs> { }; 56 + }; 57 + 58 + env = lib.mkOption { 59 + type = lib.types.raw; 60 + readOnly = true; 61 + internal = true; 62 + default = env; 63 + }; 64 + }; 65 + }
+11 -44
modules/write-flake.nix
··· 1 { 2 lib, 3 config, 4 inputs, 5 ... 6 }: 7 let 8 - inherit (import ./../dev/modules/_lib lib) inputsExpr isNonEmptyString; 9 10 flake-file = config.flake-file; 11 ··· 26 addHeader 27 ]; 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 - 47 - # expr to code 48 - nixCode = 49 - x: 50 - if lib.isStringLike x then 51 - lib.strings.escapeNixString x 52 - else if lib.isAttrs x then 53 - lib.pipe x [ 54 - (lib.mapAttrsToList nixAttr) 55 - (map ({ name, value }: ''${name} = ${nixCode value}; '')) 56 - (values: ''{ ${lib.concatStringsSep " " values} }'') 57 - ] 58 - else if lib.isList x then 59 - lib.pipe x [ 60 - (lib.map nixCode) 61 - (values: ''[ ${lib.concatStringsSep " " values} ]'') 62 - ] 63 - else if x == true then 64 - "true" 65 - else if x == false then 66 - "false" 67 - else 68 - toString x; 69 - 70 description = 71 if isNonEmptyString flake-file.description then 72 '' ··· 80 ''; 81 82 nixConfig = 83 - if flake-file.nixConfig != { } then 84 '' 85 - nixConfig = ${nixCode flake-file.nixConfig}; 86 '' 87 else 88 "";
··· 1 { 2 lib, 3 + options, 4 config, 5 inputs, 6 ... 7 }: 8 let 9 + inherit (import ./../dev/modules/_lib lib) inputsExpr isNonEmptyString nixCode; 10 11 flake-file = config.flake-file; 12 ··· 27 addHeader 28 ]; 29 30 description = 31 if isNonEmptyString flake-file.description then 32 '' ··· 40 ''; 41 42 nixConfig = 43 + let 44 + nixConfigOptions = 45 + options.flake-file.valueMeta.configuration.options.nixConfig.valueMeta.configuration.options; 46 + filteredConfig = lib.filterAttrs ( 47 + name: _: !(nixConfigOptions ? ${name}) || nixConfigOptions.${name}.isDefined 48 + ) flake-file.nixConfig; 49 + in 50 + if filteredConfig != { } then 51 '' 52 + nixConfig = ${nixCode filteredConfig}; 53 '' 54 else 55 "";
+1 -1
templates/default/flake.nix
··· 7 inputs = { 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"; 12 }; 13
··· 7 inputs = { 8 flake-file.url = "github:vic/flake-file"; 9 flake-parts.url = "github:hercules-ci/flake-parts"; 10 + nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; 11 systems.url = "github:nix-systems/default"; 12 }; 13
+1 -1
templates/default/modules/default.nix
··· 10 flake-file.inputs = { 11 flake-file.url = "github:vic/flake-file"; 12 flake-parts.url = "github:hercules-ci/flake-parts"; 13 - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 14 systems.url = "github:nix-systems/default"; 15 }; 16
··· 10 flake-file.inputs = { 11 flake-file.url = "github:vic/flake-file"; 12 flake-parts.url = "github:hercules-ci/flake-parts"; 13 + nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; 14 systems.url = "github:nix-systems/default"; 15 }; 16
+1 -1
templates/dendritic/flake.nix
··· 11 url = "github:hercules-ci/flake-parts"; 12 }; 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"; 17 };
··· 11 url = "github:hercules-ci/flake-parts"; 12 }; 13 import-tree.url = "github:vic/import-tree"; 14 + nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; 15 nixpkgs-lib.follows = "nixpkgs"; 16 systems.url = "github:nix-systems/default"; 17 };
+1 -1
templates/parts/flake.nix
··· 12 inputs = { 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"; 18 };
··· 12 inputs = { 13 flake-file.url = "github:vic/flake-file"; 14 flake-parts.url = "github:hercules-ci/flake-parts"; 15 + nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; 16 systems.url = "github:nix-systems/default"; 17 treefmt-nix.url = "github:numtide/treefmt-nix"; 18 };
+1 -1
templates/parts/outputs.nix
··· 3 flake-file.inputs = { 4 flake-file.url = "github:vic/flake-file"; 5 flake-parts.url = "github:hercules-ci/flake-parts"; 6 - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 7 }; 8 9 imports = [
··· 3 flake-file.inputs = { 4 flake-file.url = "github:vic/flake-file"; 5 flake-parts.url = "github:hercules-ci/flake-parts"; 6 + nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; 7 }; 8 9 imports = [
+40
templates/unflake/README.md
···
··· 1 + # Unflake 2 + 3 + This template is an example of using `flake-file.inputs` in a non-flakes project. 4 + 5 + It uses [unflake](https://codeberg.org/goldstein/unflake) to pin and fetch inputs defined as options inside `./modules`. 6 + 7 + ## Generate `unflake.nix` 8 + 9 + The following command is a convenience for generating `unflake.nix` by 10 + first producing a temporary `inputs.nix` from your config and then 11 + running unflake on it. 12 + 13 + ```shell 14 + nix-shell . -A unflake.env --run write-unflake 15 + ``` 16 + 17 + You can also pass any unflake option: 18 + 19 + ```shell 20 + nix-shell . -A unflake.env --run 'write-unflake --verbose --backend nix' 21 + ``` 22 + 23 + If you need to see the file that is being passed as `--inputs inputs.nix` 24 + to the unflake command, you can generate it with: 25 + 26 + ```shell 27 + # (only recommended for debugging) 28 + nix-shell . -A unflake.env --run write-inputs 29 + 30 + # then, you can run unflake yourself: 31 + nix-shell https://ln-s.sh/unflake -A unflake-shell --run unflake 32 + ``` 33 + 34 + ## Using with [npins](https://github.com/andir/npins) 35 + 36 + Unflake has an npins backend to use it run: 37 + 38 + ```shell 39 + nix-shell . -A unflake.env --run 'write-unflake --backend npins' 40 + ```
+21
templates/unflake/default.nix
···
··· 1 + let 2 + 3 + outputs = 4 + inputs: 5 + (inputs.nixpkgs.lib.evalModules { 6 + modules = [ (inputs.import-tree ./modules) ]; 7 + specialArgs = { inherit inputs; }; 8 + }).config; 9 + 10 + withInputs = 11 + inputs: outputs: 12 + outputs ( 13 + inputs 14 + // { 15 + # uncomment to use local checkout on CI 16 + # flake-file = import ./../../modules; 17 + } 18 + ); 19 + 20 + in 21 + (import ./unflake.nix withInputs) outputs
+10
templates/unflake/modules/default.nix
···
··· 1 + { inputs, ... }: 2 + { 3 + imports = [ inputs.flake-file.flakeModules.unflake ]; 4 + 5 + flake-file.inputs = { 6 + flake-file.url = "github:vic/flake-file"; 7 + import-tree.url = "github:vic/import-tree"; 8 + nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; 9 + }; 10 + }
+58
templates/unflake/unflake.nix
···
··· 1 + # @generated by https://codeberg.org/goldstein/unflake 2 + let 3 + deps = rec { 4 + unflake_github_vic_flake-file = builtins.fetchTree { 5 + type = "github"; 6 + owner = "vic"; 7 + repo = "flake-file"; 8 + rev = "982bec8f58dc56360df4dbb246f9d3b846e89dfa"; 9 + lastModified = 1771017115; 10 + narHash = "sha256-2Cef4MEBKL8YWe0ZEuEV5U/x4aWz9IM8hrxxiD8X3f4="; 11 + }; 12 + unflake_github_vic_import-tree = builtins.fetchTree { 13 + type = "github"; 14 + owner = "vic"; 15 + repo = "import-tree"; 16 + rev = "3c23749d8013ec6daa1d7255057590e9ca726646"; 17 + lastModified = 1763762820; 18 + narHash = "sha256-ZvYKbFib3AEwiNMLsejb/CWs/OL/srFQ8AogkebEPF0="; 19 + }; 20 + unflake_tarball_https---channels-nixos-org-nixpkgs-unstable-nixexprs-tar-xz = builtins.fetchTree { 21 + type = "tarball"; 22 + url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; 23 + lastModified = 1770843696; 24 + narHash = "sha256-9SFCZkVcpDOV6unH5hVEy4+dB0rxMuUoBnDAO6vshac="; 25 + }; 26 + }; 27 + universe = rec { 28 + unflake_github_vic_flake-file = ((import "${deps.unflake_github_vic_flake-file.outPath}/flake.nix").outputs { 29 + self = unflake_github_vic_flake-file; 30 + }) // deps.unflake_github_vic_flake-file // { 31 + _flake = true; 32 + outPath = "${deps.unflake_github_vic_flake-file.outPath}"; 33 + sourceInfo = deps.unflake_github_vic_flake-file; 34 + }; 35 + unflake_github_vic_import-tree = ((import "${deps.unflake_github_vic_import-tree.outPath}/flake.nix").outputs { 36 + self = unflake_github_vic_import-tree; 37 + }) // deps.unflake_github_vic_import-tree // { 38 + _flake = true; 39 + outPath = "${deps.unflake_github_vic_import-tree.outPath}"; 40 + sourceInfo = deps.unflake_github_vic_import-tree; 41 + }; 42 + unflake_tarball_https---channels-nixos-org-nixpkgs-unstable-nixexprs-tar-xz = ((import "${deps.unflake_tarball_https---channels-nixos-org-nixpkgs-unstable-nixexprs-tar-xz.outPath}/flake.nix").outputs { 43 + self = unflake_tarball_https---channels-nixos-org-nixpkgs-unstable-nixexprs-tar-xz; 44 + }) // deps.unflake_tarball_https---channels-nixos-org-nixpkgs-unstable-nixexprs-tar-xz // { 45 + _flake = true; 46 + outPath = "${deps.unflake_tarball_https---channels-nixos-org-nixpkgs-unstable-nixexprs-tar-xz.outPath}"; 47 + sourceInfo = deps.unflake_tarball_https---channels-nixos-org-nixpkgs-unstable-nixexprs-tar-xz; 48 + }; 49 + }; 50 + inputs = { 51 + flake-file = universe.unflake_github_vic_flake-file; 52 + import-tree = universe.unflake_github_vic_import-tree; 53 + nixpkgs = universe.unflake_tarball_https---channels-nixos-org-nixpkgs-unstable-nixexprs-tar-xz; 54 + self = throw "to use inputs.self, write `import ./unflake.nix (inputs: ...)`"; 55 + withInputs = outputs: let self = outputs (inputs // { inherit self; }); in self; 56 + __functor = self: self.withInputs; 57 + }; 58 + in inputs