···1# These are supported funding model platforms
2-3github: [vic] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4patreon: # Replace with a single Patreon username
5open_collective: # Replace with a single Open Collective username
···1# These are supported funding model platforms
02github: [vic] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
3patreon: # Replace with a single Patreon username
4open_collective: # Replace with a single Open Collective username
···1<!-- Badges -->
02<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>
004 <a href="https://github.com/vic/flake-file/actions">
5 <img src="https://github.com/vic/flake-file/workflows/flake-check/badge.svg" alt="CI Status"/> </a>
6 <a href="LICENSE"> <img src="https://img.shields.io/github/license/vic/flake-file" alt="License"/> </a>
···89# flake-file โ Generate flake.nix from flake-parts modules.
100011**flake-file** lets you generate a clean, maintainable `flake.nix` from modular options, using [flake-parts](https://flake.parts/).
1213It makes your flake configuration modular and based on the Nix module system. This means you can use
14`lib.mkDefault` or anything you normally do with Nix modules, and have them reflected in flake schema values.
1516<table><tr><td>
17-18## Features
1920- Flake definition aggregated from all flake-parts modules.
···99 # That's it! Importing this module will add dendritic-setup inputs to your flake.
100 imports = [ inputs.flake-file.flakeModules.dendritic ];
101102- # Define flake attributes on any flake-pars module:
103 flake-file = {
104 description = "My Awesome Flake";
105 inputs.nixpkgs.url = lib.mkDefault "github:NixOS/nixpkgs/nixpkgs-unstable";
···138139- Includes flakeModules.default.
140- Includes flakeModules.import-tree.
141-- Includes flakeModules.nix-auto-follow.
142- 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`.
148149### Flake Templates
150···190191Options use the same attributes as the flake schema. See below for details.
192193-| 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 |
00000000000000000000200201Example:
202203```nix
204flake-file = {
205 description = "my awesome flake";
206- nixConfig = {}; # an attrset. currently not typed.
207 inputs.<name>.url = "github:foo/bar";
208 inputs.<name>.flake = false;
209 inputs.<name>.inputs.nixpkgs.follows = "nixpkgs";
···215216---
217218-## About the Flake `output` function
219220-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.
221222It defaults to:
223···269270## Automatic flake.lock flattening
271272-You can use the `prune-lock` [options](https://github.com/vic/flake-file/blob/main/modules/options.nix)
273to specify a command that `flake-file` will use whenever your flake.nix file is generated
274to flatten your flake.lock dependency tree.
275···284 imports = [
285 inputs.flake-file.flakeModules.nix-auto-follow
286 # or optionally
287- #inputs.flake-file.flakeModules.allfollow
288 ];
289}
290```
···296This section outlines the recommended steps for adopting `flake-file` in your own repository.
2972981. **Prerequisite:** Ensure you have already adopted [flake-parts](https://flake.parts).
299-2. **Add Inputs:** In your current `flake.nix`, add the following input:
0300301 ```nix
302 flake-file.url = "github:vic/flake-file";
303 ```
304305-3. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`:
306307 ```nix
308 # outputs.nix -- this is the contents of your `outputs` function from the original flake.nix file.
···315 }
316 ```
317318-4. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`):
319320> [!IMPORTANT]
321> Make sure you `git add` so that new files are visible to Nix.
···339```
3403415. **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.
344345You are done! Now you can split dependencies from `modules/inputs.nix` into other flake-part modules as you see fit:
346···378379---
380381-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>
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>
7 <a href="https://github.com/vic/flake-file/actions">
8 <img src="https://github.com/vic/flake-file/workflows/flake-check/badge.svg" alt="CI Status"/> </a>
9 <a href="LICENSE"> <img src="https://img.shields.io/github/license/vic/flake-file" alt="License"/> </a>
···1112# flake-file โ Generate flake.nix from flake-parts modules.
1314+> `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, using [flake-parts](https://flake.parts/).
1718It 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.
2021<table><tr><td>
22+23## Features
2425- Flake definition aggregated from all flake-parts modules.
···104 # That's it! Importing this module will add dendritic-setup inputs to your flake.
105 imports = [ inputs.flake-file.flakeModules.dendritic ];
106107+ # Define flake attributes on any flake-parts module:
108 flake-file = {
109 description = "My Awesome Flake";
110 inputs.nixpkgs.url = lib.mkDefault "github:NixOS/nixpkgs/nixpkgs-unstable";
···143144- Includes flakeModules.default.
145- Includes flakeModules.import-tree.
0146- Enables [`flake-parts`](https://github.com/hercules-ci/flake-parts).
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.
00150151### Flake Templates
152···192193Options use the same attributes as the flake schema. See below for details.
194195+| 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 |
222223Example:
224225```nix
226flake-file = {
227 description = "my awesome flake";
228+ nixConfig = {}; # attrset (free-form, typed as attrs)
229 inputs.<name>.url = "github:foo/bar";
230 inputs.<name>.flake = false;
231 inputs.<name>.inputs.nixpkgs.follows = "nixpkgs";
···237238---
239240+## About the Flake `outputs` function
241242+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.
243244It defaults to:
245···291292## Automatic flake.lock flattening
293294+You can use the `prune-lock` [options](https://github.com/vic/flake-file/blob/main/modules/options/prune-lock.nix)
295to specify a command that `flake-file` will use whenever your flake.nix file is generated
296to flatten your flake.lock dependency tree.
297···306 imports = [
307 inputs.flake-file.flakeModules.nix-auto-follow
308 # or optionally
309+ # inputs.flake-file.flakeModules.allfollow
310 ];
311}
312```
···318This section outlines the recommended steps for adopting `flake-file` in your own repository.
3193201. **Prerequisite:** Ensure you have already adopted [flake-parts](https://flake.parts).
321+322+1. **Add Inputs:** In your current `flake.nix`, add the following input:
323324 ```nix
325 flake-file.url = "github:vic/flake-file";
326 ```
327328+1. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`:
329330 ```nix
331 # outputs.nix -- this is the contents of your `outputs` function from the original flake.nix file.
···338 }
339 ```
340341+1. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`):
342343> [!IMPORTANT]
344> Make sure you `git add` so that new files are visible to Nix.
···362```
3633645. **Backup:** Back up your flake.nix into flake.nix.bak before regenerating it.
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.
367368You are done! Now you can split dependencies from `modules/inputs.nix` into other flake-part modules as you see fit:
369···401402---
403404+Made with \<3 by [@vic](https://x.com/oeiuwq)