···11# These are supported funding model platforms
22-32github: [vic] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
43patreon: # Replace with a single Patreon username
54open_collective: # Replace with a single Open Collective username
···11<!-- Badges -->
22+23<p align="right">
33- <a href="https://nixos.org/"> <img src="https://img.shields.io/badge/Nix-Flake-informational?logo=nixos&logoColor=white" alt="Nix Flake"/> </a>
44+ <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"/>
55+ </a>
66+ <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>
47 <a href="https://github.com/vic/flake-file/actions">
58 <img src="https://github.com/vic/flake-file/workflows/flake-check/badge.svg" alt="CI Status"/> </a>
69 <a href="LICENSE"> <img src="https://img.shields.io/github/license/vic/flake-file" alt="License"/> </a>
···811912# flake-file โ Generate flake.nix from flake-parts modules.
10131414+> `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)
1515+1116**flake-file** lets you generate a clean, maintainable `flake.nix` from modular options, using [flake-parts](https://flake.parts/).
12171318It makes your flake configuration modular and based on the Nix module system. This means you can use
1419`lib.mkDefault` or anything you normally do with Nix modules, and have them reflected in flake schema values.
15201621<table><tr><td>
1717-2222+1823## Features
19242025- Flake definition aggregated from all flake-parts modules.
···99104 # That's it! Importing this module will add dendritic-setup inputs to your flake.
100105 imports = [ inputs.flake-file.flakeModules.dendritic ];
101106102102- # Define flake attributes on any flake-pars module:
107107+ # Define flake attributes on any flake-parts module:
103108 flake-file = {
104109 description = "My Awesome Flake";
105110 inputs.nixpkgs.url = lib.mkDefault "github:NixOS/nixpkgs/nixpkgs-unstable";
···138143139144- Includes flakeModules.default.
140145- Includes flakeModules.import-tree.
141141-- Includes flakeModules.nix-auto-follow.
142146- Enables [`flake-parts`](https://github.com/hercules-ci/flake-parts).
143143-- Enables [`flake-aspects`](https://github.com/vic/flake-aspects).
144144-- Enables [`den`](https://github.com/vic/den).
145145-- Sets `output` function to `import-tree ./modules`.
146146-- Adds `treefmt-nix` input.
147147-- Enables formatters: `nixfmt`, `deadnix`, and `nixf-diagnose`.
147147+- Sets `outputs` to `inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules)`.
148148+149149+> 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.
148150149151### Flake Templates
150152···190192191193Options use the same attributes as the flake schema. See below for details.
192194193193-| Option | Description |
194194-| ----------------------------------------------- | --------------------------------- |
195195-| `flake-file.description` | Sets the flake description |
196196-| `flake-file.nixConfig` | Attrset for flake-level nixConfig |
197197-| `flake-file.inputs.<name>.url` | URL for a flake input |
198198-| `flake-file.inputs.<name>.flake` | Boolean, is input a flake? |
199199-| `flake-file.inputs.<name>.inputs.<dep>.follows` | Tree of dependencies to follow |
195195+| Option | Description |
196196+| ------------------------------------------------- | ----------------------------------------------------------- |
197197+| `flake-file.description` | Sets the flake description |
198198+| `flake-file.nixConfig` | Flake-level `nixConfig` (typed attrset) |
199199+| `flake-file.outputs` | Literal Nix code for `outputs` function |
200200+| `flake-file.formatter` | Function: `pkgs -> program` to format generated `flake.nix` |
201201+| `flake-file.do-not-edit` | Header comment added atop generated file |
202202+| `flake-file.inputs.<name>.url` | Source URL (e.g. `github:owner/repo`) |
203203+| `flake-file.inputs.<name>.type` | Reference type (`github`, `path`, etc.) |
204204+| `flake-file.inputs.<name>.owner` | Owner (for typed VCS refs) |
205205+| `flake-file.inputs.<name>.repo` | Repo name |
206206+| `flake-file.inputs.<name>.path` | Local path reference |
207207+| `flake-file.inputs.<name>.id` | Flake registry id |
208208+| `flake-file.inputs.<name>.dir` | Subdirectory within repo/path |
209209+| `flake-file.inputs.<name>.narHash` | NAR hash pin |
210210+| `flake-file.inputs.<name>.rev` | Commit hash pin |
211211+| `flake-file.inputs.<name>.ref` | Branch or tag pin |
212212+| `flake-file.inputs.<name>.host` | Custom host for git forges |
213213+| `flake-file.inputs.<name>.submodules` | Whether to fetch git submodules |
214214+| `flake-file.inputs.<name>.flake` | Boolean: is it a flake? (default true) |
215215+| `flake-file.inputs.<name>.follows` | Follow another input's value |
216216+| `flake-file.inputs.<name>.inputs.<dep>.follows` | Nested input follow tree |
217217+| `flake-file.inputs.<name>.inputs.<dep>.inputs...` | Recursively follow deeper deps |
218218+| `flake-file.write-hooks` | List of ordered hooks (by `index`) after writing |
219219+| `flake-file.check-hooks` | List of ordered hooks (by `index`) during check |
220220+| `flake-file.prune-lock.enable` | Enable automatic flake.lock pruning |
221221+| `flake-file.prune-lock.program` | Function building pruning executable |
200222201223Example:
202224203225```nix
204226flake-file = {
205227 description = "my awesome flake";
206206- nixConfig = {}; # an attrset. currently not typed.
228228+ nixConfig = {}; # attrset (free-form, typed as attrs)
207229 inputs.<name>.url = "github:foo/bar";
208230 inputs.<name>.flake = false;
209231 inputs.<name>.inputs.nixpkgs.follows = "nixpkgs";
···215237216238---
217239218218-## About the Flake `output` function
240240+## About the Flake `outputs` function
219241220220-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.
242242+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.
221243222244It defaults to:
223245···269291270292## Automatic flake.lock flattening
271293272272-You can use the `prune-lock` [options](https://github.com/vic/flake-file/blob/main/modules/options.nix)
294294+You can use the `prune-lock` [options](https://github.com/vic/flake-file/blob/main/modules/options/prune-lock.nix)
273295to specify a command that `flake-file` will use whenever your flake.nix file is generated
274296to flatten your flake.lock dependency tree.
275297···284306 imports = [
285307 inputs.flake-file.flakeModules.nix-auto-follow
286308 # or optionally
287287- #inputs.flake-file.flakeModules.allfollow
309309+ # inputs.flake-file.flakeModules.allfollow
288310 ];
289311}
290312```
···296318This section outlines the recommended steps for adopting `flake-file` in your own repository.
2973192983201. **Prerequisite:** Ensure you have already adopted [flake-parts](https://flake.parts).
299299-2. **Add Inputs:** In your current `flake.nix`, add the following input:
321321+322322+1. **Add Inputs:** In your current `flake.nix`, add the following input:
300323301324 ```nix
302325 flake-file.url = "github:vic/flake-file";
303326 ```
304327305305-3. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`:
328328+1. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`:
306329307330 ```nix
308331 # outputs.nix -- this is the contents of your `outputs` function from the original flake.nix file.
···315338 }
316339 ```
317340318318-4. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`):
341341+1. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`):
319342320343> [!IMPORTANT]
321344> Make sure you `git add` so that new files are visible to Nix.
···339362```
3403633413645. **Backup:** Back up your flake.nix into flake.nix.bak before regenerating it.
342342-6. **Generate:** Execute `nix run .#write-flake` to generate flake.nix.
343343-7. **Verify:** Check flake.nix and if everything is okay, remove the backup file.
365365+1. **Generate:** Execute `nix run .#write-flake` to generate flake.nix.
366366+1. **Verify:** Check flake.nix and if everything is okay, remove the backup file.
344367345368You are done! Now you can split dependencies from `modules/inputs.nix` into other flake-part modules as you see fit:
346369···378401379402---
380403381381-Made with <3 by [@vic](https://x.com/oeiuwq)
404404+Made with \<3 by [@vic](https://x.com/oeiuwq)