Skip to content

Commit 07a7eec

Browse files
Add standalone flakes to examples (#1539)
## Summary - add standalone `flake.nix` files for every Nix-backed example - point each example at `github:indexable-inc/index` - pin each example to `github:NixOS/nixpkgs/nixos-unstable` and make Index follow that nixpkgs - use `ix.nix` as the example entrypoint, not `default.nix` or `example.nix` - expose fleet examples under `ix.fleets.default` for the `ix up` toplevel contract, while preserving `nixosConfigurations` - update aggregate example discovery to read `examples/**/ix.nix` Fixes #1537 ## Tests - `nix run nixpkgs#nixfmt -- examples/**/*.nix lib/discovery.nix` - coverage script: no `examples/**/default.nix` or `examples/**/example.nix`; every example flake has an `ix.nix`; every example flake has the Index input, nixos-unstable input, and nixpkgs follow - eval script: 20 fleet examples evaluated `.#ix.fleets.default.planValue.order`; 2 non-Nix OCI examples evaluated `.#ix.images.default.name`; `nomad-secret-refs` evaluated `.#checks.x86_64-linux.default.name`; `nixos-switch-multi` evaluated `.#ix.nixosConfigurations.default.web.config.system.build.toplevel.drvPath` - aggregate eval: `.#packages.aarch64-darwin.dev-fleet-up.name`, `.#packages.aarch64-darwin.nginx-lifecycle-up.name`, `.#packages.aarch64-darwin.ray-cluster-up.name` (sent by an AI agent via Codex) <!-- Macroscope's pull request summary starts here --> <!-- Macroscope will only edit the content between these invisible markers, and the markers themselves will not be visible in the GitHub rendered markdown. --> <!-- If you delete either of the start / end markers from your PR's description, Macroscope will append its summary at the bottom of the description. --> > [!NOTE] > ### Add standalone flake entrypoints to all examples and rename `default.nix` to `ix.nix` > - Each example directory gains a `flake.nix` that imports `./ix.nix` and exposes standard outputs (`ix.fleets.default`, `nixosConfigurations`, etc.), making every example runnable directly with `nix` or `ix up`. > - All existing `default.nix` entrypoints are renamed to `ix.nix`; no logic changes in these files. > - The `dev-fleet` example is restructured: `ix.nix` becomes a `mkDev` entrypoint and the NixOS module content moves to a new [`dev.nix`](https://github.com/indexable-inc/index/pull/1539/files#diff-fb2fbe8cb5cba7d162ca3247836edcc33a80e0ffcb38297fb76bdebd868cf2fd). > - [`lib/discovery.nix`](https://github.com/indexable-inc/index/pull/1539/files#diff-99ac7778993e1b9c08033c2057dd9cb20220148285ea3f1d1f4e528b82f4a21e) is updated to target `ix.nix`, filter examples that accept an `index` argument, and require `nodes` and `planValue` attributes on the result. > - [`tests/default.nix`](https://github.com/indexable-inc/index/pull/1539/files#diff-1cc580de297308d93d82f7b72446ae4b98832a8aae3378e9e134102519a0e33a) is updated to reference `ix.nix` paths and asserts that the `dev-fleet` example exposes both `ix.nix` and `dev.nix`. > > <!-- Macroscope's review summary starts here --> > > <sup><a href="https://app.macroscope.com">Macroscope</a> summarized d12ad20.</sup> > <!-- Macroscope's review summary ends here --> > <!-- macroscope-ui-refresh --> <!-- Macroscope's pull request summary ends here -->
1 parent b900d3a commit 07a7eec

68 files changed

Lines changed: 629 additions & 129 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
description = "ix example: _non-nix-oci-debian";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
index = {
7+
url = "github:indexable-inc/index";
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
};
10+
};
11+
12+
outputs =
13+
{ index, ... }:
14+
let
15+
image = import ./ix.nix { inherit index; };
16+
in
17+
{
18+
ix.images.default = image;
19+
packages.x86_64-linux.default = image;
20+
};
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
description = "ix example: _non-nix-oci-ubuntu";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
index = {
7+
url = "github:indexable-inc/index";
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
};
10+
};
11+
12+
outputs =
13+
{ index, ... }:
14+
let
15+
image = import ./ix.nix { inherit index; };
16+
in
17+
{
18+
ix.images.default = image;
19+
packages.x86_64-linux.default = image;
20+
};
21+
}

examples/declared-groups/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ix shell client -- curl -fsS http://api:8080/
2727

2828
## Shape
2929

30-
- [`default.nix`](default.nix) declares the fleet; note `api` has no
30+
- [`ix.nix`](ix.nix) declares the fleet; note `api` has no
3131
fleet-level `groups` entry.
3232
- [`api.nix`](api.nix) carries the group in the image
3333
(`ix.networking.groups`) and exposes port 8080 to group members.

examples/declared-groups/flake.nix

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
description = "ix example: declared-groups";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
index = {
7+
url = "github:indexable-inc/index";
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
};
10+
};
11+
12+
outputs =
13+
{ index, ... }:
14+
let
15+
fleet = import ./ix.nix { inherit index; };
16+
in
17+
{
18+
ix.fleets.default = fleet;
19+
nixosConfigurations = fleet.nixosConfigurations;
20+
};
21+
}

examples/dev-fleet/README.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
# ix fleet
22

3-
A forkable ix environment (RFC 0007). One [`ix.nix`](ix.nix), an ordinary
4-
NixOS module, is the source of truth for the per-VM environment, the fleet
5-
topology, and an opt-in shared SMB volume that gives the whole fleet one Claude
6-
(and ix) login.
3+
A forkable ix environment (RFC 0007). [`ix.nix`](ix.nix) is the runnable ix
4+
entrypoint, and [`dev.nix`](dev.nix) is the ordinary NixOS module for the
5+
per-VM environment, fleet topology, and opt-in shared SMB volume that gives the
6+
whole fleet one Claude (and ix) login.
77

88
## Run
99

1010
```sh
11-
nix run .#dev-fleet-up
11+
ix up
1212
```
1313

14-
Run that from this repo root. A copied consumer flake can use `ix up` after it
15-
exposes the `nixosConfigurations` returned by `index.lib.mkDev`; `ix.nix` is the
16-
editable module, not the CLI entrypoint.
14+
Run that from a copied example flake. In this repo root, the aggregate example
15+
wrapper still exposes `nix run .#dev-fleet-up`; the standalone example shape is
16+
what `ix up` consumes.
1717

1818
This example declares a multi-node `ix.dev.fleet`. Omit that block and the same
19-
`ix.nix` is a **single VM named `dev`** that `index.lib.mkDev` builds and
20-
creates through `nix run .#up`; `default.nix` shows the composition. The fleet
21-
below is the scale-up.
19+
`dev.nix` is a **single VM named `dev`** that `index.lib.mkDev` builds and
20+
creates through `ix up`; `ix.nix` shows the composition. The fleet below is the
21+
scale-up.
2222

2323
## Shape
2424

25-
- [`ix.nix`](ix.nix) is the module a user edits after `ix init`. Top-level
25+
- [`dev.nix`](dev.nix) is the module a user edits after `ix init`. Top-level
2626
NixOS config (`environment.systemPackages`, `programs.git.enable`) is the
2727
environment; `ix.dev.fleet` is the topology; `ix.dev.shared` turns on the
2828
identity volume. Claude Code and Codex are installed by default.
29-
- [`default.nix`](default.nix) hands the module to `index.lib.mkDev`, passing
30-
`src = ./.` (the flake source a copied repo wires as `self`). In this repo,
31-
fleet discovery imports `default.nix` and exposes `.#dev-fleet-up`.
29+
- [`ix.nix`](ix.nix) hands the module to `index.lib.mkDev`, passing
30+
`src = ./.` (the flake source a copied repo wires as `self`).
3231

3332
`mkDev` reads `ix.dev` and desugars this into a `mkFleet` plan:
3433

@@ -65,7 +64,7 @@ notes; this example places the source.)
6564
## Tradeoffs
6665

6766
- The share is **guest-writable** by default (`ix.dev.shared.guestOk`) so
68-
bring-up works without secrets plumbing, the same tradeoff
67+
`ix up` works without secrets plumbing, the same tradeoff
6968
[`multi-client-file-sharing`](../multi-client-file-sharing) documents. It is
7069
only reachable on the private group, never public. A real shared-auth volume
7170
should set `guestOk = false`, add a Samba user, and pass `credentials=`

examples/dev-fleet/default.nix

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/dev-fleet/dev.nix

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# A forkable ix environment (RFC 0007). This is an ordinary NixOS module: write
2+
# your environment at the top level, and use `ix.dev.*` for the fleet and the
3+
# shared volume. After `ix init` this is the one file you edit.
4+
{ pkgs, ... }:
5+
{
6+
# Your environment: applied to every VM (single or fleet).
7+
environment.systemPackages = [
8+
pkgs.ripgrep
9+
pkgs.jq
10+
];
11+
programs.git.enable = true;
12+
13+
# Claude Code + Codex are installed by default; toggle either off here.
14+
# ix.dev.agents.codex = false;
15+
16+
# A fleet: two interchangeable agents plus a builder that opts out of the
17+
# shared volume below. Drop `ix.dev.fleet` entirely for a single VM.
18+
ix.dev.fleet = {
19+
agent.replicas = 2;
20+
builder.dependsOn = [ "agent" ];
21+
};
22+
23+
# One shared Claude (and ix) login for the fleet, over an SMB volume. The
24+
# first `claude login` on any agent logs in every agent; `builder` opts out.
25+
ix.dev.shared = {
26+
enable = true;
27+
ix = true; # also share ~/.n so a node can spawn more VMs (claude is shared by default)
28+
excludeNodes = [ "builder" ];
29+
};
30+
}

0 commit comments

Comments
 (0)