aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <tom@vanderlee.io>2026-09-17 11:05:45 +0200
committerGravatar Tom van der Lee <tom@vanderlee.io>2026-09-17 11:05:45 +0200
commitf793f76e26b461c3228c69926d82bf950aaac671 (patch)
treeaffac98593ff0de3bb24fcd8aa64f6ef8ed9dc19 /README.md
parentae3fa667bda75f11881c9209dc67226f98bcfd95 (diff)
downloaddesktop-flake-f793f76e26b461c3228c69926d82bf950aaac671.tar.gz
desktop-flake-f793f76e26b461c3228c69926d82bf950aaac671.tar.bz2
desktop-flake-f793f76e26b461c3228c69926d82bf950aaac671.zip
Add scripted host bootstrapping with directory-driven discovery
nixosConfigurations now auto-discovers hosts/<name>/ directories instead of a hand-maintained attrset, and scripts/bootstrap-host.sh (exposed as `nix run .#bootstrap-host`) scaffolds a new host from the template. The script always requires an explicit --root for hardware-configuration.nix so a live-installer run can never read the live ISO's own /etc/nixos by accident. Also records the belated task-11.1 checkbox update for the prior change's already-committed state.
Diffstat (limited to 'README.md')
-rw-r--r--README.md36
1 files changed, 18 insertions, 18 deletions
diff --git a/README.md b/README.md
index 881b2e9..3688c88 100644
--- a/README.md
+++ b/README.md
@@ -9,33 +9,33 @@ A single Nix flake for provisioning both NixOS hosts and non-NixOS systems (any
9- `modules/nixos/common.nix` — shared NixOS-only system settings applied to every NixOS host 9- `modules/nixos/common.nix` — shared NixOS-only system settings applied to every NixOS host
10- `modules/home/` — the shared, cross-platform home-manager profile (shell, git, editor, CLI tools). The same modules are consumed whether activated via a NixOS host's home-manager module or standalone `home-manager switch` 10- `modules/home/` — the shared, cross-platform home-manager profile (shell, git, editor, CLI tools). The same modules are consumed whether activated via a NixOS host's home-manager module or standalone `home-manager switch`
11- `users/tom.nix` — identity/profile file consumed by both `mkNixos` and `mkHome` 11- `users/tom.nix` — identity/profile file consumed by both `mkNixos` and `mkHome`
12- `hosts/template/` — a copy-source-only NixOS host skeleton; **never** wired into `flake.nix` outputs directly. Copy it to `hosts/<real-hostname>/` when provisioning a real machine 12- `hosts/template/` — a copy-source-only NixOS host skeleton; **never** wired into `flake.nix` outputs directly (excluded from discovery by name — see below). Copy it via `scripts/bootstrap-host.sh` (or `nix run .#bootstrap-host`) when provisioning a real machine
13- `scripts/bootstrap-host.sh` — scaffolds a new `hosts/<hostname>/` from the template; exposed as `apps.<system>.bootstrap-host`
14
15Any directory under `hosts/` other than `hosts/template` that contains a `system` file automatically becomes a real `nixosConfigurations.<name>` output — adding a host means dropping in a directory, not editing `flake.nix`.
13 16
14## Installing NixOS on a new machine 17## Installing NixOS on a new machine
15 18
16This flake does not partition disks for you — do that first, with the standard NixOS installer or manually. 19This flake does not partition disks for you — do that first, with the standard NixOS installer or manually.
17 20
181. Partition and format disks; mount the target filesystems under `/mnt` (including `/mnt/boot` for the ESP if UEFI). 211. Partition and format disks; mount the target filesystems under `/mnt` (including `/mnt/boot` for the ESP if UEFI).
192. Generate hardware config: `nixos-generate-config --root /mnt`. Keep the generated `hardware-configuration.nix`; discard its `configuration.nix`. 222. Get this repo onto the installer: `nix-shell -p git && git clone <your-remote-url> ~/nix-config` (requires the repo already pushed to a remote — see Follow-ups below).
203. Get this repo onto the installer: `nix-shell -p git && git clone <your-remote-url> ~/nix-config` (requires the repo already pushed to a remote — see Follow-ups below). 233. From `~/nix-config`, scaffold the host:
214. Copy the template into a real host: `cp -r ~/nix-config/hosts/template ~/nix-config/hosts/<real-hostname>`. 24 ```
225. Edit `hosts/<real-hostname>/configuration.nix`: set `networking.hostName`, pick the correct boot loader stanza, set `system.stateVersion` to the installer's NixOS release. 25 nix run .#bootstrap-host -- <real-hostname> --root /mnt --state-version <ver>
236. Replace the stub hardware config: `cp /mnt/etc/nixos/hardware-configuration.nix ~/nix-config/hosts/<real-hostname>/hardware-configuration.nix`.
247. Add the host to `flake.nix`:
25 ```nix
26 nixosConfigurations.<real-hostname> = lib.mkNixos {
27 hostname = "<real-hostname>";
28 system = "x86_64-linux";
29 };
30 ``` 26 ```
318. `cd ~/nix-config && git add -A` (flakes only see git-tracked files). 27 `--root /mnt` tells the script to read (or generate, via `nixos-generate-config --root /mnt` if needed) `hardware-configuration.nix` from the freshly mounted install target — it never reads the live installer's own `/etc/nixos`, since `--root` has no default and must always be given explicitly. `--state-version` should match the installer's NixOS release (e.g. `24.05`) and should never be changed after the fact.
329. If needed: `export NIX_CONFIG="experimental-features = nix-command flakes"`. 284. Review `hosts/<real-hostname>/configuration.nix` (boot loader choice, etc.) — the script prints this reminder along with the exact next commands.
3310. `nixos-install --root /mnt --flake ~/nix-config#<real-hostname>`. 295. `cd ~/nix-config && git add hosts/<real-hostname>` (flakes only see git-tracked files).
3411. Reboot and remove the install media. 306. If needed: `export NIX_CONFIG="experimental-features = nix-command flakes"`.
3512. Afterwards, clone the flake to a stable path (e.g. `/etc/nix-config`) so future updates are just `sudo nixos-rebuild switch --flake /etc/nix-config#<real-hostname>`. 317. `nixos-install --root /mnt --flake ~/nix-config#<real-hostname>`.
328. Reboot and remove the install media.
339. Afterwards, clone the flake to a stable path (e.g. `/etc/nix-config`) so future updates are just `sudo nixos-rebuild switch --flake /etc/nix-config#<real-hostname>`.
36 34
37## Installing on a non-NixOS system (any Linux, or macOS once supported) 35## Installing on a non-NixOS system (any Linux, or macOS once supported)
38 36
37Non-NixOS hosts are unaffected by `bootstrap-host` — there's nothing per-host to scaffold, since `homeConfigurations."tom@linux"` is one generic entry shared by every standalone machine.
38
391. Install Nix. Recommended: the [Determinate Systems installer](https://github.com/DeterminateSystems/nix-installer) (flakes enabled by default). The official installer also works, but you'll need to add `experimental-features = nix-command flakes` to `nix.conf` yourself. 391. Install Nix. Recommended: the [Determinate Systems installer](https://github.com/DeterminateSystems/nix-installer) (flakes enabled by default). The official installer also works, but you'll need to add `experimental-features = nix-command flakes` to `nix.conf` yourself.
402. `git clone <your-remote-url> ~/nix-config`. 402. `git clone <your-remote-url> ~/nix-config`.
413. First run: `nix run home-manager/master -- switch --flake ~/nix-config#tom@linux`. After that, `home-manager switch --flake ~/nix-config#tom@linux` works directly. 413. First run: `nix run home-manager/master -- switch --flake ~/nix-config#tom@linux`. After that, `home-manager switch --flake ~/nix-config#tom@linux` works directly.
@@ -46,7 +46,7 @@ This only touches your home directory — no sudo required.
46 46
47- `nix fmt` — format all `.nix` files with `nixfmt-rfc-style`. 47- `nix fmt` — format all `.nix` files with `nixfmt-rfc-style`.
48- `nix develop` — a shell with `statix` and `deadnix` for linting. 48- `nix develop` — a shell with `statix` and `deadnix` for linting.
49- `nix flake check` — validates `homeConfigurations."tom@linux"` and the other outputs defined here (there are no `nixosConfigurations` yet — see Follow-ups). 49- `nix flake check` — validates `homeConfigurations."tom@linux"`, `apps.bootstrap-host`, and the other outputs defined here (there are no real `nixosConfigurations` until a host is scaffolded — see Follow-ups).
50 50
51## Follow-ups (not covered by this change) 51## Follow-ups (not covered by this change)
52 52