diff --git a/README.md b/README.md new file mode 100644 index 0000000..15619c5 --- /dev/null +++ b/README.md @@ -0,0 +1,102 @@ +# 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 + ``` + diff --git a/installer.nix b/installer.nix index 6f2631b..d844b70 100644 --- a/installer.nix +++ b/installer.nix @@ -12,7 +12,7 @@ services.openssh.settings.PermitRootLogin = "yes"; environment.systemPackages = with pkgs; [ - git curl parted e2fsprogs btrfs-progs util-linux + git curl jq parted e2fsprogs btrfs-progs util-linux ]; # environment.etc."flake-url".text = "git+https://gitea.lan.ddnsgeek.com/beatzaplenty/nixos.git?ref=main#nixos"; @@ -38,8 +38,18 @@ environment.etc."git-credentials".text = export FLAKE_BASE_URL="git+https://gitea.lan.ddnsgeek.com/beatzaplenty/nixos.git" -# Menu options -options=("nixos" "docker" "server" "nix-cache" "nix-minimal") +echo "Fetching available NixOS hosts from flake..." +mapfile -t options < <( + nix eval --json --no-use-registries --no-accept-flake-config \ + "''${FLAKE_BASE_URL}#nixosConfigurations" \ + --apply builtins.attrNames \ + | jq -r '.[]' +) + +if [[ ''${#options[@]} -eq 0 ]]; then + echo "ERROR: No NixOS hosts found in ''${FLAKE_BASE_URL}#nixosConfigurations" >&2 + exit 1 +fi echo "Choose the flake profile to install:" select choice in "''${options[@]}"; do diff --git a/result b/result new file mode 120000 index 0000000..746bf99 --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/qrx1ipw9azj3as3y93l9g5sjxpk20jaz-nixos-minimal-25.05.20250112.2f9e2f8-x86_64-linux.iso \ No newline at end of file