···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">
34 <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"/>
45 </a>
···89 <a href="LICENSE"> <img src="https://img.shields.io/github/license/vic/flake-file" alt="License"/> </a>
910</p>
10111111-# flake-file โ Generate flake.nix from flake-parts modules.
1212+# Generate `flake.nix`/`unflake.nix`/`npins` from inputs defined as module options.
12131314> `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)
14151515-**flake-file** lets you generate a clean, maintainable `flake.nix` from modular options, using [flake-parts](https://flake.parts/).
1616+**flake-file** lets you generate a clean, maintainable `flake.nix` from modular options. Use the _real_ Nix language to define your inputs.
16171718It makes your flake configuration modular and based on the Nix module system. This means you can use
1819`lib.mkDefault` or anything you normally do with Nix modules, and have them reflected in flake schema values.
2020+2121+> Despite the original flake-oriented name, it NOW also works on _stable Nix_, [_non flakes_](templates/unflake) environments.
19222023<table><tr><td>
21242225## Features
23262424-- Flake definition aggregated from all flake-parts modules.
2727+- Flake definition aggregated from Nix modules.
2528- Schema as [options](https://github.com/vic/flake-file/blob/main/modules/options/default.nix).
2629- Syntax for nixConfig and follows is the same as in flakes.
2730- `flake check` ensures files are up to date.
2828-- App for generator: `nix run .#write-flake`
3131+- App for `flake.nix` generator: `nix run .#write-flake`
2932- Custom do-not-edit header.
3033- Automatic flake.lock [flattening](#automatic-flakelock-flattening).
3134- Incrementally add [flake-parts-builder](#parts_templates) templates.
3235- Pick flakeModules for different feature sets.
3336- [Dendritic](https://vic.github.io/dendrix/Dendritic.html) flake template.
3737+- Works on stable Nix, [unflake](templates/unflake) environments.
34383539</td><td>
3640···5963## Who is this for?
60646165- Nix users who want to keep their `flake.nix` modular and maintainable
6262-- Anyone using [flake-parts](https://flake.parts/) and looking to automate or simplify flake input management
6666+- Anyone using Nix modules and looking to automate or simplify flake input management
6367- Teams or individuals who want to share and reuse flake modules across projects
64686569---
···147151148152> 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.
149153154154+#### [`flakeModules.unflake`](https://github.com/vic/flake-file/tree/main/modules/unflake.nix)
155155+156156+- Defines `flake-file` options.
157157+- Exposes `write-unflake` to generate `unflake.nix` or `npins`. See [templates/unflake](templates/unflake) for usage.
158158+150159### Flake Templates
151160152152-#### `default` template
161161+#### [`default`](templates/default) template
153162154163A more basic, explicit setup.
155164···177186> [!TIP]
178187> You can use the `write-flake` app as part of a devshell or git hook.
179188180180-#### `dendritic` template
189189+#### [`dendritic`](templates/dendritic) template
181190182191A template for dendritic setups; includes `flakeModules.dendritic`.
183192184184-#### `parts` template
193193+#### [`parts`](templates/parts) template
185194186195A template that uses `lib.flakeModules.flake-parts-builder`.
196196+197197+#### [`unflake`](templates/unflake) template
198198+199199+Uses [goldstein/unflake](https://codeberg.org/goldstein/unflake) to pin and fetch inputs that were defined as options for non-flakes stable Nix environments.
187200188201---
189202···317330This section outlines the recommended steps for adopting `flake-file` in your own repository.
3183313193321. **Prerequisite:** Ensure you have already adopted [flake-parts](https://flake.parts).
320320-2. **Add Inputs:** In your current `flake.nix`, add the following input:
333333+334334+1. **Add Inputs:** In your current `flake.nix`, add the following input:
321335322336 ```nix
323337 flake-file.url = "github:vic/flake-file";
324338 ```
325339326326-3. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`:
340340+1. **Move Outputs:** Copy the contents of your `outputs` function into a file `./outputs.nix`:
327341328342 ```nix
329343 # outputs.nix -- this is the contents of your `outputs` function from the original flake.nix file.
···336350 }
337351 ```
338352339339-4. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`):
353353+1. **Move Inputs:** Copy your current flake.nix file as a flake-parts module (e.g., `modules/inputs.nix`):
340354341355> [!IMPORTANT]
342356> Make sure you `git add` so that new files are visible to Nix.
···360374```
3613753623765. **Backup:** Back up your flake.nix into flake.nix.bak before regenerating it.
363363-6. **Generate:** Execute `nix run .#write-flake` to generate flake.nix.
364364-7. **Verify:** Check flake.nix and if everything is okay, remove the backup file.
377377+1. **Generate:** Execute `nix run .#write-flake` to generate flake.nix.
378378+1. **Verify:** Check flake.nix and if everything is okay, remove the backup file.
365379366380You are done! Now you can split dependencies from `modules/inputs.nix` into other flake-part modules as you see fit:
367381···399413400414---
401415402402-Made with <3 by [@vic](https://x.com/oeiuwq)
416416+Made with \<3 by [@vic](https://x.com/oeiuwq)
···11+# Unflake
22+33+This template is an example of using `flake-file.inputs` in a non-flakes project.
44+55+It uses [unflake](https://codeberg.org/goldstein/unflake) to pin and fetch inputs defined as options inside `./modules`.
66+77+## Generate `unflake.nix`
88+99+The following command is a convenience for generating `unflake.nix` by
1010+first producing a temporary `inputs.nix` from your config and then
1111+running unflake on it.
1212+1313+```shell
1414+nix-shell . -A unflake.env --run write-unflake
1515+```
1616+1717+You can also pass any unflake option:
1818+1919+```shell
2020+nix-shell . -A unflake.env --run 'write-unflake --verbose --backend nix'
2121+```
2222+2323+If you need to see the file that is being passed as `--inputs inputs.nix`
2424+to the unflake command, you can generate it with:
2525+2626+```shell
2727+# (only recommended for debugging)
2828+nix-shell . -A unflake.env --run write-inputs
2929+3030+# then, you can run unflake yourself:
3131+nix-shell https://ln-s.sh/unflake -A unflake-shell --run unflake
3232+```
3333+3434+## Using with [npins](https://github.com/andir/npins)
3535+3636+Unflake has an npins backend to use it run:
3737+3838+```shell
3939+nix-shell . -A unflake.env --run 'write-unflake --backend npins'
4040+```