103 lines
3.2 KiB
Markdown
103 lines
3.2 KiB
Markdown
# Nix Auto Installer
|
|
|
|
This repository builds a custom NixOS installer ISO that can install one of the
|
|
hosts exposed by a separate NixOS flake.
|
|
|
|
The ISO is intentionally opinionated for a local environment. When the `nixos`
|
|
user logs in, it runs `/etc/auto-install.sh`, asks which flake host to install,
|
|
partitions `/dev/sda`, installs NixOS, and reboots.
|
|
|
|
## Repository Layout
|
|
|
|
- `flake.nix` defines the build output. The default package is an
|
|
`install-iso` image produced with `nixos-generators`.
|
|
- `installer.nix` defines the installer ISO configuration, including SSH,
|
|
Git credentials, users, and the generated auto-install script.
|
|
|
|
## Requirements
|
|
|
|
- A machine with Nix installed and flakes enabled.
|
|
- Network access to the configured NixOS flake repository.
|
|
- A target machine or VM where `/dev/sda` is the disk you want to erase.
|
|
|
|
## Build The ISO
|
|
|
|
From the repository root:
|
|
|
|
```sh
|
|
nix build
|
|
```
|
|
|
|
The generated ISO will be available through the `result` symlink.
|
|
|
|
## Use The Installer
|
|
|
|
1. Boot the generated ISO on the target machine.
|
|
2. Log in as the `nixos` user, or connect over SSH if networking is available.
|
|
3. The login shell runs `/etc/auto-install.sh`.
|
|
4. Choose one of the hosts returned by:
|
|
|
|
```sh
|
|
nix eval --json --no-use-registries --no-accept-flake-config \
|
|
"git+https://gitea.lan.ddnsgeek.com/beatzaplenty/nixos.git#nixosConfigurations" \
|
|
--apply builtins.attrNames
|
|
```
|
|
|
|
5. Confirm the install when prompted.
|
|
|
|
## What The Installer Does
|
|
|
|
The generated `/etc/auto-install.sh` script:
|
|
|
|
1. Reads available host names from the configured flake.
|
|
2. Prompts for the host profile to install.
|
|
3. Asks for confirmation.
|
|
4. Repartitions `/dev/sda` with an MBR layout:
|
|
- `/dev/sda1`: ext4 root filesystem labeled `nixos`
|
|
- `/dev/sda2`: swap partition labeled `swap`
|
|
5. Mounts the new root filesystem at `/mnt`.
|
|
6. Runs `nixos-install --flake`.
|
|
7. Reboots the machine.
|
|
|
|
## Configuration Notes
|
|
|
|
The installer currently assumes:
|
|
|
|
- The flake to install is
|
|
`git+https://gitea.lan.ddnsgeek.com/beatzaplenty/nixos.git`.
|
|
- Install targets are exposed under `#nixosConfigurations`.
|
|
- The install disk is always `/dev/sda`.
|
|
- The timezone is `Australia/Brisbane`.
|
|
- SSH is enabled and root login is permitted.
|
|
- The generated ISO has both `root` and `nixos` users configured with hashed
|
|
passwords.
|
|
|
|
Change these values in `installer.nix` before building if your environment
|
|
differs.
|
|
|
|
## Safety Warnings
|
|
|
|
This installer is destructive. Once confirmed, it repartitions `/dev/sda`
|
|
without another prompt. Make sure the target disk name is correct before using
|
|
the ISO on real hardware.
|
|
|
|
`installer.nix` currently contains embedded Git credentials, password hashes,
|
|
and an SSH public key. Treat this repository and any generated ISO as sensitive.
|
|
Prefer moving credentials to a safer delivery mechanism before sharing the repo
|
|
or ISO.
|
|
|
|
## Troubleshooting
|
|
|
|
- If no host choices appear, confirm the target machine has network access and
|
|
can reach the configured flake URL.
|
|
- If installation fails while fetching the flake, verify the embedded Git
|
|
credentials are valid.
|
|
- If the wrong disk is being partitioned, stop immediately and update the disk
|
|
paths in `installer.nix`.
|
|
- If the login shell does not start the installer, run it manually:
|
|
|
|
```sh
|
|
sudo /etc/auto-install.sh
|
|
```
|
|
|