···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://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>
1011-# flake-file — Generate flake.nix from flake-parts modules.
1213> `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)
1415-**flake-file** lets you generate a clean, maintainable `flake.nix` from modular options, using [flake-parts](https://flake.parts/).
1617It 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.
001920<table><tr><td>
2122## Features
2324-- 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.
03435</td><td>
36···59## Who is this for?
6061- 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
6465---
···147148> 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.
14900000150### Flake Templates
151152-#### `default` template
153154A more basic, explicit setup.
155···177> [!TIP]
178> You can use the `write-flake` app as part of a devshell or git hook.
179180-#### `dendritic` template
181182A template for dendritic setups; includes `flakeModules.dendritic`.
183184-#### `parts` template
185186A template that uses `lib.flakeModules.flake-parts-builder`.
0000187188---
189···317This section outlines the recommended steps for adopting `flake-file` in your own repository.
3183191. **Prerequisite:** Ensure you have already adopted [flake-parts](https://flake.parts).
320-2. **Add Inputs:** In your current `flake.nix`, add the following input:
0321322 ```nix
323 flake-file.url = "github:vic/flake-file";
324 ```
325326-3. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`:
327328 ```nix
329 # outputs.nix -- this is the contents of your `outputs` function from the original flake.nix file.
···336 }
337 ```
338339-4. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`):
340341> [!IMPORTANT]
342> Make sure you `git add` so that new files are visible to Nix.
···360```
3613625. **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.
365366You are done! Now you can split dependencies from `modules/inputs.nix` into other flake-part modules as you see fit:
367···399400---
401402-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>
1112+# Generate `flake.nix`/`unflake.nix`/`npins` from inputs defined as module options.
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)
1516+**flake-file** lets you generate a clean, maintainable `flake.nix` from modular options. Use the _real_ Nix language to define your inputs.
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.
20+21+> Despite the original flake-oriented name, it NOW also works on _stable Nix_, [_non flakes_](templates/unflake) environments.
2223<table><tr><td>
2425## Features
2627+- 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.
3839</td><td>
40···63## Who is this for?
6465- 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
6869---
···151152> 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.
153154+#### [`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
160161+#### [`default`](templates/default) template
162163A more basic, explicit setup.
164···186> [!TIP]
187> You can use the `write-flake` app as part of a devshell or git hook.
188189+#### [`dendritic`](templates/dendritic) template
190191A template for dendritic setups; includes `flakeModules.dendritic`.
192193+#### [`parts`](templates/parts) template
194195A 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.
200201---
202···330This section outlines the recommended steps for adopting `flake-file` in your own repository.
3313321. **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:
335336 ```nix
337 flake-file.url = "github:vic/flake-file";
338 ```
339340+1. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`:
341342 ```nix
343 # outputs.nix -- this is the contents of your `outputs` function from the original flake.nix file.
···350 }
351 ```
352353+1. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`):
354355> [!IMPORTANT]
356> Make sure you `git add` so that new files are visible to Nix.
···374```
3753765. **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.
379380You are done! Now you can split dependencies from `modules/inputs.nix` into other flake-part modules as you see fit:
381···413414---
415416+Made with \<3 by [@vic](https://x.com/oeiuwq)
···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+```