From f793f76e26b461c3228c69926d82bf950aaac671 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Thu, 17 Sep 2026 11:05:45 +0200 Subject: Add scripted host bootstrapping with directory-driven discovery nixosConfigurations now auto-discovers hosts// 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. --- README.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'README.md') 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 - `modules/nixos/common.nix` — shared NixOS-only system settings applied to every NixOS host - `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` - `users/tom.nix` — identity/profile file consumed by both `mkNixos` and `mkHome` -- `hosts/template/` — a copy-source-only NixOS host skeleton; **never** wired into `flake.nix` outputs directly. Copy it to `hosts//` when provisioning a real machine +- `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 +- `scripts/bootstrap-host.sh` — scaffolds a new `hosts//` from the template; exposed as `apps..bootstrap-host` + +Any directory under `hosts/` other than `hosts/template` that contains a `system` file automatically becomes a real `nixosConfigurations.` output — adding a host means dropping in a directory, not editing `flake.nix`. ## Installing NixOS on a new machine This flake does not partition disks for you — do that first, with the standard NixOS installer or manually. 1. Partition and format disks; mount the target filesystems under `/mnt` (including `/mnt/boot` for the ESP if UEFI). -2. Generate hardware config: `nixos-generate-config --root /mnt`. Keep the generated `hardware-configuration.nix`; discard its `configuration.nix`. -3. Get this repo onto the installer: `nix-shell -p git && git clone ~/nix-config` (requires the repo already pushed to a remote — see Follow-ups below). -4. Copy the template into a real host: `cp -r ~/nix-config/hosts/template ~/nix-config/hosts/`. -5. Edit `hosts//configuration.nix`: set `networking.hostName`, pick the correct boot loader stanza, set `system.stateVersion` to the installer's NixOS release. -6. Replace the stub hardware config: `cp /mnt/etc/nixos/hardware-configuration.nix ~/nix-config/hosts//hardware-configuration.nix`. -7. Add the host to `flake.nix`: - ```nix - nixosConfigurations. = lib.mkNixos { - hostname = ""; - system = "x86_64-linux"; - }; +2. Get this repo onto the installer: `nix-shell -p git && git clone ~/nix-config` (requires the repo already pushed to a remote — see Follow-ups below). +3. From `~/nix-config`, scaffold the host: + ``` + nix run .#bootstrap-host -- --root /mnt --state-version ``` -8. `cd ~/nix-config && git add -A` (flakes only see git-tracked files). -9. If needed: `export NIX_CONFIG="experimental-features = nix-command flakes"`. -10. `nixos-install --root /mnt --flake ~/nix-config#`. -11. Reboot and remove the install media. -12. 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#`. + `--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. +4. Review `hosts//configuration.nix` (boot loader choice, etc.) — the script prints this reminder along with the exact next commands. +5. `cd ~/nix-config && git add hosts/` (flakes only see git-tracked files). +6. If needed: `export NIX_CONFIG="experimental-features = nix-command flakes"`. +7. `nixos-install --root /mnt --flake ~/nix-config#`. +8. Reboot and remove the install media. +9. 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#`. ## Installing on a non-NixOS system (any Linux, or macOS once supported) +Non-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. + 1. 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. 2. `git clone ~/nix-config`. 3. 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. - `nix fmt` — format all `.nix` files with `nixfmt-rfc-style`. - `nix develop` — a shell with `statix` and `deadnix` for linting. -- `nix flake check` — validates `homeConfigurations."tom@linux"` and the other outputs defined here (there are no `nixosConfigurations` yet — see Follow-ups). +- `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). ## Follow-ups (not covered by this change) -- cgit v1.3