Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions .github/workflows/flake-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- test-inputs
- test-flake
- test-unflake
- test-nixlock
- test-npins
- test-npins-follows
- test-npins-transitive
Expand Down Expand Up @@ -82,12 +83,14 @@ jobs:
cd templates/npins
sed -i 's/# flake-file = import/flake-file = import/' default.nix
echo "{ inputs, ... }: { npins.pkgs = import inputs.nixpkgs {}; }" | tee modules/pkgs.nix
nix-shell . -A npins.env --run write-npins
nix-shell . -A flake-file.sh --run write-npins
unflake:
needs: [dev]
name: Check unflake
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'unflake') }}
env:
NIX_PATH: "nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"
steps:
- uses: actions/checkout@v4
- uses: wimpysworld/nothing-but-nix@main
Expand All @@ -97,8 +100,24 @@ jobs:
set -e -o pipefail
cd templates/unflake
sed -i 's/# flake-file = import/flake-file = import/' default.nix
echo "{ inputs, ... }: { unflake.pkgs = import inputs.nixpkgs {}; }" | tee modules/pkgs.nix
nix-shell . -A unflake.env --run 'write-unflake --verbose'
nix-shell . -A flake-file.sh --run 'write-unflake --verbose'
nixlock:
needs: [dev]
name: Check nixlock
runs-on: ubuntu-latest
# if: ${{ contains(github.event.pull_request.labels.*.name, 'unflake') }}
env:
NIX_PATH: "nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"
steps:
- uses: actions/checkout@v4
- uses: wimpysworld/nothing-but-nix@main
- uses: cachix/install-nix-action@v31
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: |
set -e -o pipefail
cd templates/nixlock
sed -i 's/# flake-file = import/flake-file = import/' default.nix
nix-shell . -A flake-file.sh --run write-nixlock
dev:
needs: [bootstrap]
name: Check flake dev
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<a href="LICENSE"> <img src="https://img.shields.io/github/license/vic/flake-file" alt="License"/> </a>
</p>

# Generate `flake.nix`/`unflake.nix`/`npins` from inputs defined as module options.
### Generate `flake.nix`/`unflake.nix`/`npins`/`nixlock` from inputs defined as module options.

> `flake-file` and [vic](https://bsky.app/profile/oeiuwq.bsky.social)'s [dendritic libs](https://dendritic.oeiuwq.com) made for you with Love++ and AI--. If you like my work, consider [sponsoring](https://dendritic.oeiuwq.com/sponsor)

Expand All @@ -23,11 +23,11 @@ This means
- Your inputs follow a **typed Input Schema**.
- Your outputs can be defined on a **typed Output Schema**.

> Despite the original flake-oriented name, it NOW also works on _stable Nix_, non-flakes environments via [npins](templates/npins) or [unflake](templates/unflake).
> Despite the original flake-oriented name, it NOW also works on _stable Nix_, non-flakes environments via [npins](templates/npins), [unflake](templates/unflake), [nixlock](https://codeberg.org/FrdrCkII/nixlock)

<table><tr><td>

## Features
### Features

- Flake definition aggregated from Nix modules.
- [Input](https://github.com/vic/flake-file/blob/main/modules/options/default.nix) and Output schemas based on Nix types.
Expand All @@ -39,7 +39,7 @@ This means
- Incrementally add [flake-parts-builder](#parts_templates) templates.
- Pick flakeModules for different feature sets.
- [Dendritic](https://vic.github.io/dendrix/Dendritic.html) flake template.
- Works on stable Nix, [npins](templates/npins) and [unflake](templates/unflake) environments.
- Works on stable Nix, [npins](templates/npins), [unflake](templates/unflake), [nixlock](templates/nixlock) environments.

</td><td>

Expand Down
12 changes: 12 additions & 0 deletions dev/_bootstrap-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ let
'';
};

test-nixlock = pkgs.writeShellApplication {
name = "test-nixlock";
runtimeInputs = [
(empty.flake-file.apps.write-nixlock pkgs)
];
text = ''
write-nixlock
grep vic/empty-flake/archive ${outdir}/nixlock.lock.nix
'';
};

in
pkgs.mkShell {
buildInputs = [
Expand All @@ -115,5 +126,6 @@ pkgs.mkShell {
test-npins
test-npins-follows
test-npins-transitive
test-nixlock
];
}
4 changes: 2 additions & 2 deletions docs/src/content/docs/explanation/what-is-flake-file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ move your outputs function into `outputs.nix` and use something like:
Even if some people use unstable flakes, others should not be forced out of stable Nix.

Each module defines inputs and flake-file can extract to whatever input-locking backend you need.
Be it `flake.nix`, `unflake.nix`, `npins`.
Be it `flake.nix`, `unflake.nix`, `nixlock`, `npins`.

## Everybody `.follows`

Expand Down Expand Up @@ -66,7 +66,7 @@ Running `nix run .#write-flake` materialises all declared inputs into `flake.nix

- **Modular:** Each module declares only its own dependencies.
- **Composable:** Modules can be shared across projects — including their input declarations.
- **Backend-agnostic:** The same module options generate `flake.nix`, `unflake.nix`, or `npins/` depending on the chosen backend.
- **Backend-agnostic:** The same module options generate `flake.nix`, `unflake.nix`, `nixlock` or `npins/` depending on the chosen backend.
- **Standard Nix:** Uses the Nix module system — `lib.mkDefault`, priority overrides, conditional inputs — all work as expected.

## Real-world Usage
Expand Down
10 changes: 8 additions & 2 deletions docs/src/content/docs/guides/flake-modules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ Source: [`modules/prune-lock/nix-auto-follow.nix`](https://github.com/vic/flake-

Defines `flake-file` options for [npins](https://github.com/andir/npins)-based environments. Exposes `write-npins`. Supports `github`, `gitlab`, `channel`, `tarball`, and `git` schemes. Respects `follows` for deduplication. Prunes stale pins automatically.

Source: [`modules/npins.nix`](https://github.com/vic/flake-file/tree/main/modules/npins.nix)
Source: [`modules/npins`](https://github.com/vic/flake-file/tree/main/modules/npins)

## `flakeModules.unflake`

Defines `flake-file` options for [unflake](https://codeberg.org/goldstein/unflake)-based environments. Exposes `write-unflake`.

Source: [`modules/unflake.nix`](https://github.com/vic/flake-file/tree/main/modules/unflake.nix)
Source: [`modules/unflake`](https://github.com/vic/flake-file/tree/main/modules/unflake)

## `flakeModules.nixlock`

Defines `flake-file` options for [nixlock](https://codeberg.org/FrdrCkII/nixlock)-based environments. Exposes `write-nixlock`.

Source: [`modules/nixlock`](https://github.com/vic/flake-file/tree/main/modules/nixlock)
8 changes: 8 additions & 0 deletions docs/src/content/docs/guides/templates.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ For **non-flake** (stable Nix) environments. Uses [goldstein/unflake](https://co
nix flake init -t github:vic/flake-file#unflake
```

## `nixlock`

For **non-flake** (stable Nix) environments. Uses [FrdrCkII/nixlock](https://codeberg.org/FrdrCkII/nixlock) to pin inputs.

```shell
nix flake init -t github:vic/flake-file#unflake
```

## Tips

> **Tip:** You can use the `write-flake` app as part of a devshell command or a git pre-commit hook to keep `flake.nix` always up to date.
2 changes: 1 addition & 1 deletion docs/src/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ Ever wanted to interpolate a string just to discover inputs are **NOT REAL** Nix
Built-in support for automatic `flake.lock` flattening via `allfollow` or `nix-auto-follow`.
</Card>
<Card title="Multiple Backends" icon="setting">
Generate `flake.nix`, `unflake.nix`, or `npins/` from the same module options. Switch backends without rewriting your modules.
Generate `flake.nix`, `unflake.nix`, `nixlock`, or `npins/` from the same module options. Switch backends without rewriting your modules.
</Card>
</CardGrid>
2 changes: 1 addition & 1 deletion docs/src/content/docs/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ flake-file treats `flake.nix` as a generated artifact. You declare inputs and se
<LinkButton href="/tutorials/migrate-traditional-flake" variant="minimal" icon="right-arrow">Learn More</LinkButton>
</Card>
<Card title="Migrate without flakes" icon="pencil">
Adopt flake-file in a non-flake project using npins or unflake.
Adopt flake-file in a non-flake project using npins, nixlock or unflake.
<LinkButton href="/tutorials/migrate-no-flakes" variant="minimal" icon="right-arrow">Learn More</LinkButton>
</Card>
</CardGrid>
Expand Down
3 changes: 2 additions & 1 deletion docs/src/content/docs/reference/bootstrap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: All options for the flake-file bootstrap command.

import { Aside } from '@astrojs/starlight/components';

The bootstrap command lets you generate `flake.nix`, `unflake.nix`, or `npins/` from scratch — without being inside an existing flake.
The bootstrap command lets you generate `flake.nix`, `unflake.nix`, `nixlock.lock.nix`, or `npins/` from scratch — without being inside an existing flake.

```shell
nix-shell https://github.com/vic/flake-file/archive/refs/heads/main.zip \
Expand All @@ -21,6 +21,7 @@ The `flake-file.sh` shell provides these commands:
| `write-flake` | Generate a `flake.nix` file |
| `write-inputs` | Generate an `inputs.nix` expression (for debugging) |
| `write-unflake` | Generate `unflake.nix` via [unflake](https://codeberg.org/goldstein/unflake) |
| `write-nixlock` | Generate `nixlock.lock.nix` via [nixlock](https://codeberg.org/FrdrCkII/nixlock) |
| `write-npins` | Generate/update `npins/` directory via [npins](https://github.com/andir/npins) |

## Arguments
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/tutorials/bootstrap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ You can create a `flake.nix` from scratch — without running inside an existing
# Write a minimal flake-file.nix file (or copy a flake.nix of yours)
echo '{ inputs.flake-file.url = "github:vic/flake-file"; }' > flake-file.nix

# Generate flake.nix or unflake.nix or npins from flake-file.nix
# Generate flake.nix or unflake.nix or npins or nixlock from flake-file.nix
nix-shell https://github.com/vic/flake-file/archive/refs/heads/main.zip \
-A flake-file.sh --run write-flake --arg modules ./flake-file.nix
```

> <small>See also: all [bootstrap command args](/reference/bootstrap)</small>

Replace `write-flake` with `write-inputs`, `write-unflake`, or `write-npins` to target a different backend.
Replace `write-flake` with `write-inputs`, `write-unflake`, `write-nixlock`, or `write-npins` to target a different backend.


## Using a modules directory
Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/tutorials/migrate-no-flakes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ of tools for that in the ecosystem.

flake-file has support
for [`unflake`](https://codeberg.org/goldstein/unflake)
and [`nixlock`](https://codeberg.org/FrdrCkII/nixlock)
and [`npins`](https://github.com/andir/npins)
send PR for others.

Expand Down
1 change: 1 addition & 0 deletions modules/bootstrap/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ let
./../options
./../npins
./../unflake
./../nixlock
./../write-inputs.nix
./../write-flake.nix
./../flake-options.nix
Expand Down
11 changes: 11 additions & 0 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let
import-tree
npins
unflake
nixlock
flake-options
;
};
Expand All @@ -29,6 +30,11 @@ let
./unflake
];

nixlock.imports = [
base
./nixlock
];

default.imports = [
base
./write-flake.nix
Expand Down Expand Up @@ -67,6 +73,11 @@ let
path = ./../templates/unflake;
};

templates.nixlock = {
description = "nixlock template";
path = ./../templates/nixlock;
};

templates.dendritic = {
description = "dendritic template";
path = ./../templates/dendritic;
Expand Down
Loading