Add USB install tooling, key/secret helpers, installer ISO, README
- install-system (nix run .#install): disk picker -> disk-ids.json, typed confirmation, disko, hardware config, host SSH key + secrets decrypt check, sbctl keys, nixos-install, password, repo copy - create-keys, set-password, secret-from-file, switch-system helpers - installer ISO (nix build .#iso) with the flake at /etc/nixos-config Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J1cugeLkfFLZMpiztQ8TyN
This commit is contained in:
3 files changed
+251
-4
No files matched your search
@@ -0,0 +1,245 @@
|
|||||||
|
# NixOS flake: Hyprland + Noctalia gaming desktop
|
||||||
|
|
||||||
|
Declarative NixOS for one AMD desktop (`desktop`, user `faumaray`), installable
|
||||||
|
from a USB stick with a single command.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Flake** with home-manager, agenix, disko, lanzaboote and nixos-hardware.
|
||||||
|
- **Hyprland** (from its own flake, current git) under UWSM with the
|
||||||
|
**Noctalia v5** shell, WezTerm, Neovim, zsh + starship.
|
||||||
|
- **Gaming**: Steam with Proton-GE, gamescope, gamemode, MangoHud.
|
||||||
|
- **Full AMD**: AMD CPU, Radeon GPU (Mesa, LACT, optional ROCm).
|
||||||
|
- **Disks via disko, btrfs, no encryption**:
|
||||||
|
- NVMe: ESP (`/boot`, 2G) + btrfs `nixos` with `@root @home @nix @log @swap`
|
||||||
|
(16G swapfile).
|
||||||
|
- SATA SSD: btrfs `data`, one subvolume per folder, mounted into the home:
|
||||||
|
`~/Games ~/Downloads ~/Documents ~/Music ~/Pictures ~/Videos ~/Storage`.
|
||||||
|
- **Secure Boot** with lanzaboote (keys in `/var/lib/sbctl`).
|
||||||
|
- **Secrets** with agenix, decrypted by the machine's SSH host key
|
||||||
|
(`/etc/ssh/ssh_host_ed25519_key`). Every secret is optional.
|
||||||
|
- **Installer**: `install-system` (also `nix run .#install`) and a bootable
|
||||||
|
ISO with this repository baked in (`nix build .#iso`).
|
||||||
|
|
||||||
|
## Layout
|
||||||
|
|
||||||
|
```
|
||||||
|
flake.nix inputs and outputs
|
||||||
|
lib/ mkHost, mkInstaller
|
||||||
|
overlays/ hyprland (upstream), noctalia, additions (./pkgs), modifications
|
||||||
|
pkgs/ install-system, create-keys, set-password, secret-from-file, switch-system
|
||||||
|
apps/ the same tools as `nix run .#<app>`
|
||||||
|
modules/nixos/ NixOS modules, options under my.*
|
||||||
|
modules/home/ home-manager modules, options under my.home.*
|
||||||
|
modules/installer/ the installer ISO
|
||||||
|
hosts/desktop/ default.nix (the host), disks.nix, disk-ids.json, hardware-configuration.nix, home.nix
|
||||||
|
secrets/ secrets.nix (recipients) and the encrypted *.age files
|
||||||
|
keys/ PRIVATE keys, gitignored, lives only on your USB stick
|
||||||
|
```
|
||||||
|
|
||||||
|
### How it is organised
|
||||||
|
|
||||||
|
- `lib.mkHost` builds a host from `hosts/<name>` plus every module in
|
||||||
|
`modules/nixos`. A module does nothing until its `my.*` option is switched on,
|
||||||
|
so the host file stays short and declarative.
|
||||||
|
- Overlays are composed in `overlays/default.nix`. `overlays/additions.nix`
|
||||||
|
adds everything in `pkgs/`; `overlays/modifications.nix` changes existing
|
||||||
|
packages. Put your own tweaks there.
|
||||||
|
- `my.*` options (NixOS): `my.user`, `my.locale`, `my.boot.secureBoot.enable`,
|
||||||
|
`my.hardware.amd`, `my.disks`, `my.desktop.hyprland.enable`,
|
||||||
|
`my.gaming.enable`, `my.secrets`. Home-manager side: `my.home.<module>.enable`,
|
||||||
|
switched on in `hosts/desktop/home.nix`.
|
||||||
|
- To add a machine: copy `hosts/desktop`, register it in `flake.nix`
|
||||||
|
(`myLib.mkHost { hostname = "..."; }`).
|
||||||
|
|
||||||
|
> No `flake.lock` is committed yet. The first build (or `install-system`)
|
||||||
|
> locks all inputs with `nix flake lock`; commit the resulting `flake.lock` so
|
||||||
|
> installs and the ISO are reproducible.
|
||||||
|
|
||||||
|
## First-time setup (on your current machine)
|
||||||
|
|
||||||
|
Everything here is **optional**. Without it the system still installs; the
|
||||||
|
login password then is `changeme` (with a warning) and there is no SSH key.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone <this repo> nixos-config && cd nixos-config
|
||||||
|
|
||||||
|
# 1. Host SSH key (the agenix identity) and Secure Boot keys -> keys/desktop/
|
||||||
|
nix run .#create-keys
|
||||||
|
|
||||||
|
# 2. Open secrets/secrets.nix and replace the two placeholder keys:
|
||||||
|
# host = the public key create-keys printed
|
||||||
|
# faumaray = your own public key (cat ~/.ssh/id_ed25519.pub)
|
||||||
|
|
||||||
|
# 3. Login password (asks twice, stores secrets/faumaray-password.age)
|
||||||
|
nix run .#set-password -- -i ~/.ssh/id_ed25519
|
||||||
|
|
||||||
|
# 4. Your SSH key, installed as ~/.ssh/id_ed25519 on the new system
|
||||||
|
nix run .#secret-from-file -- ssh-id_ed25519.age ~/.ssh/id_ed25519 -i ~/.ssh/id_ed25519
|
||||||
|
cp ~/.ssh/id_ed25519.pub secrets/ssh-id_ed25519.pub
|
||||||
|
|
||||||
|
# 5. Commit. Flakes only see tracked files; keys/ is gitignored on purpose.
|
||||||
|
git add -A && git commit -m "Add secrets"
|
||||||
|
```
|
||||||
|
|
||||||
|
`-i` is only a check: it proves your private key can decrypt what was just
|
||||||
|
written. Edit secrets later with `cd secrets && agenix -e <name>.age -i <your key>`.
|
||||||
|
Copy the whole directory, **including `keys/`**, to the USB stick (and back
|
||||||
|
`keys/` up: it holds the host key and the Secure Boot keys).
|
||||||
|
|
||||||
|
`keys/<host>/` contains `ssh_host_ed25519_key(.pub)` and `sbctl/{keys,GUID}`.
|
||||||
|
The installer copies them to `/etc/ssh` and `/var/lib/sbctl`; if they are
|
||||||
|
missing it generates new ones and saves them back to the stick.
|
||||||
|
|
||||||
|
## Install from USB
|
||||||
|
|
||||||
|
Needs a UEFI PC and network. **The NixOS installer image is not Secure Boot
|
||||||
|
signed: disable Secure Boot in the firmware while installing** (you enable it
|
||||||
|
again afterwards, see below). `install-system` erases the two chosen disks.
|
||||||
|
|
||||||
|
### Path A: official NixOS ISO + this repository on a stick
|
||||||
|
|
||||||
|
1. Boot the official NixOS ISO (minimal or graphical, e.g. with Ventoy), connect
|
||||||
|
to the network (`nmtui`).
|
||||||
|
2. Mount the stick that holds the repository and `keys/`. **Not below `/mnt`**,
|
||||||
|
that is where the new system is mounted:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo -i
|
||||||
|
mkdir -p /media/usb && mount /dev/disk/by-label/<LABEL> /media/usb
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Run the installer from the repository:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cd /media/usb/nixos-config
|
||||||
|
nix --extra-experimental-features 'nix-command flakes' run --accept-flake-config .#install
|
||||||
|
```
|
||||||
|
|
||||||
|
If Nix complains about the repository ownership or a read-only stick, copy
|
||||||
|
it first: `cp -r /media/usb/nixos-config /root/ && cd /root/nixos-config`.
|
||||||
|
|
||||||
|
### Path B: the custom ISO
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix build .#iso # result/iso/nixos-*.iso, this repository included
|
||||||
|
sudo dd if=result/iso/nixos-*.iso of=/dev/sdX bs=4M status=progress conv=fsync
|
||||||
|
```
|
||||||
|
|
||||||
|
(check `sdX` with `lsblk` first; or just copy the file to a Ventoy stick).
|
||||||
|
Boot it, then:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nmtui # if you need Wi-Fi
|
||||||
|
sudo mkdir -p /media/keys && sudo mount /dev/disk/by-label/<LABEL> /media/keys # stick with keys/
|
||||||
|
sudo install-system
|
||||||
|
```
|
||||||
|
|
||||||
|
The ISO ships the flake in `/etc/nixos-config` (read-only; `install-system`
|
||||||
|
works on a copy) and finds `keys/` on mounted sticks. Point at it explicitly
|
||||||
|
with `--keys-dir /media/keys/keys`. If you changed secrets after building the
|
||||||
|
ISO, use Path A or rebuild the ISO.
|
||||||
|
|
||||||
|
### What `install-system` does
|
||||||
|
|
||||||
|
1. Checks root, UEFI and the flake; copies it to `/root/nixos-config` if it is
|
||||||
|
read-only or not a usable git repository (`keys/` is never copied into a
|
||||||
|
flake, it would end up in the world-readable Nix store).
|
||||||
|
2. If `hosts/desktop/disk-ids.json` still has `CHANGE-ME` (or a disk does not
|
||||||
|
exist), lists the disks and asks for the system NVMe and the data SSD. The
|
||||||
|
live USB is skipped. The choice is written to `disk-ids.json`.
|
||||||
|
3. Shows both disks (model, size) and wipes them only after you type the host
|
||||||
|
name. `--yes` skips this prompt.
|
||||||
|
4. Runs disko, writes `hosts/desktop/hardware-configuration.nix` from the real
|
||||||
|
hardware (`nixos-generate-config --no-filesystems`).
|
||||||
|
5. Installs the host key, checks that it can decrypt `secrets/*.age`; if not it
|
||||||
|
stops **before** installing and explains how to fix it.
|
||||||
|
6. Puts the Secure Boot keys into `/mnt/var/lib/sbctl`.
|
||||||
|
7. `nixos-install --flake .#desktop`, asks for a login password if there is no
|
||||||
|
password secret, and copies the repository to `~/nixos-config` of the new system.
|
||||||
|
|
||||||
|
Useful options: `--host`, `--flake DIR`, `--keys-dir DIR`, `--select-disks`,
|
||||||
|
`--disko-mode mount` (re-run after a failure without wiping anything), `--help`.
|
||||||
|
|
||||||
|
## After the installation
|
||||||
|
|
||||||
|
Reboot, remove the stick, log in (greetd/tuigreet: pick **Hyprland**).
|
||||||
|
|
||||||
|
**Secure Boot** (lanzaboote). The keys exist but the firmware does not trust them yet:
|
||||||
|
|
||||||
|
1. Enter the firmware setup and put Secure Boot into **Setup Mode** ("Reset to
|
||||||
|
Setup Mode" / clear the Platform Key; keep the factory db/dbx).
|
||||||
|
2. Boot NixOS (Secure Boot still off or in Setup Mode), then:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo sbctl enroll-keys --microsoft
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Reboot, enable Secure Boot in the firmware, and check:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
bootctl status | grep -i "secure boot" # Secure Boot: enabled (user)
|
||||||
|
sudo sbctl status
|
||||||
|
```
|
||||||
|
|
||||||
|
`--microsoft` keeps Microsoft's keys so firmware option ROMs (GPU) still work.
|
||||||
|
|
||||||
|
**Steam**: Settings > Storage > add `~/Games/SteamLibrary` (on the data SSD).
|
||||||
|
Proton-GE appears under the compatibility tool list.
|
||||||
|
|
||||||
|
**Noctalia** starts with the session (a systemd user service). `Super+Space`
|
||||||
|
launcher, `Super+S` control center, `Super+,` settings. Changes made in the
|
||||||
|
settings window are stored by Noctalia and override `modules/home/noctalia.nix`;
|
||||||
|
move what you want to keep into that file.
|
||||||
|
|
||||||
|
Commit the files the installer generated:
|
||||||
|
`hosts/desktop/disk-ids.json`, `hosts/desktop/hardware-configuration.nix`, `flake.lock`.
|
||||||
|
|
||||||
|
## Day-2
|
||||||
|
|
||||||
|
```sh
|
||||||
|
switch-system # nh os switch (or: switch-system boot | test)
|
||||||
|
nix flake update # new inputs, then switch-system
|
||||||
|
nix fmt # nixfmt
|
||||||
|
nix flake check --no-build
|
||||||
|
```
|
||||||
|
|
||||||
|
Roll back: pick an older generation in the boot menu, or
|
||||||
|
`sudo nixos-rebuild switch --rollback`.
|
||||||
|
|
||||||
|
**Add a folder on the SSD later** (example `Projects`):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo mkdir -p /mnt/data
|
||||||
|
sudo mount -o subvolid=5 /dev/disk/by-label/data /mnt/data # top level of the data fs
|
||||||
|
sudo btrfs subvolume create /mnt/data/@projects
|
||||||
|
sudo umount /mnt/data
|
||||||
|
```
|
||||||
|
|
||||||
|
then add `Projects = { };` to `homeFolders` in `hosts/desktop/disks.nix`
|
||||||
|
(subvolume name defaults to `@projects`) and run `switch-system`.
|
||||||
|
|
||||||
|
**Change a secret**: `cd secrets && agenix -e faumaray-password.age -i ~/.ssh/id_ed25519`
|
||||||
|
(or run `set-password` / `secret-from-file` again with `--force`), `git add`, switch.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
- **The PC does not boot after enabling Secure Boot.** Disable Secure Boot in
|
||||||
|
the firmware and boot. To go back to plain systemd-boot set
|
||||||
|
`my.boot.secureBoot.enable = false;` in `hosts/desktop/default.nix` and run
|
||||||
|
`switch-system boot`. `sbctl enroll-keys` refusing to run means the firmware
|
||||||
|
is not in Setup Mode.
|
||||||
|
- **Secrets do not decrypt** (no password, no `~/.ssh/id_ed25519`). The host key
|
||||||
|
in `secrets/secrets.nix` must match `/etc/ssh/ssh_host_ed25519_key.pub` on the
|
||||||
|
machine. Test: `sudo age -d -i /etc/ssh/ssh_host_ed25519_key secrets/<name>.age`.
|
||||||
|
Fix `secrets.nix`, re-encrypt (`agenix -r -i <your key>`), `git add`, switch.
|
||||||
|
Meanwhile log in with `changeme` (when no password secret is defined) and
|
||||||
|
run `passwd`.
|
||||||
|
- **The SSD is missing or fails.** Its mounts use `nofail` and a 10 s timeout, so
|
||||||
|
the system still boots from the NVMe. Files written to `~/Games` meanwhile land
|
||||||
|
on the NVMe and are hidden once the SSD is mounted again.
|
||||||
|
- **A new file is "not found" by Nix.** Flakes only see git-tracked files: `git add` it.
|
||||||
|
- **The installer stopped halfway.** Run it again with `--disko-mode mount` (and
|
||||||
|
the same `--flake`); partitions and the already installed host key are reused.
|
||||||
|
- **Slow first build / compiling Hyprland or Noctalia.** The binary caches in
|
||||||
|
`flake.nix` (`nixConfig`) must be accepted; use `--accept-flake-config`.
|
||||||
@@ -98,8 +98,8 @@ else
|
|||||||
fi
|
fi
|
||||||
if [ ! -e "$HOSTKEY.pub" ]; then
|
if [ ! -e "$HOSTKEY.pub" ]; then
|
||||||
ssh-keygen -y -f "$HOSTKEY" >"$HOSTKEY.pub"
|
ssh-keygen -y -f "$HOSTKEY" >"$HOSTKEY.pub"
|
||||||
chmod 0644 "$HOSTKEY.pub"
|
|
||||||
fi
|
fi
|
||||||
|
chmod 0644 "$HOSTKEY.pub"
|
||||||
|
|
||||||
if [ -d "$SBCTL/keys" ] && [ -f "$SBCTL/GUID" ]; then
|
if [ -d "$SBCTL/keys" ] && [ -f "$SBCTL/GUID" ]; then
|
||||||
ok "Secure Boot keys exist, left untouched: $SBCTL"
|
ok "Secure Boot keys exist, left untouched: $SBCTL"
|
||||||
|
|||||||
@@ -232,6 +232,8 @@ sync_back() {
|
|||||||
|
|
||||||
ensure_lock() {
|
ensure_lock() {
|
||||||
if [ -f "$FLAKE/flake.lock" ]; then
|
if [ -f "$FLAKE/flake.lock" ]; then
|
||||||
|
# `nix run .#install` may have just created it: make sure git tracks it.
|
||||||
|
git_add flake.lock
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
info "no flake.lock yet: locking all flake inputs (needs network, takes a minute)"
|
info "no flake.lock yet: locking all flake inputs (needs network, takes a minute)"
|
||||||
@@ -618,7 +620,7 @@ could not log in). Nothing has been installed yet. Host public key:
|
|||||||
$HOST_PUB
|
$HOST_PUB
|
||||||
|
|
||||||
Fix it with ONE of the following, then run the installer again with
|
Fix it with ONE of the following, then run the installer again with
|
||||||
sudo install-system --host $HOST --flake $FLAKE --disko-mode mount
|
sudo install-system --host $HOST --flake $FLAKE --keys-dir $KEYS_DIR --disko-mode mount
|
||||||
|
|
||||||
A) Encrypt the secrets for this key.
|
A) Encrypt the secrets for this key.
|
||||||
1. Put the key above into secrets/secrets.nix (the 'host' variable).
|
1. Put the key above into secrets/secrets.nix (the 'host' variable).
|
||||||
@@ -692,7 +694,7 @@ set_user_password() {
|
|||||||
info "no password secret: set the login password for $USER_NAME"
|
info "no password secret: set the login password for $USER_NAME"
|
||||||
local i
|
local i
|
||||||
for i in 1 2 3; do
|
for i in 1 2 3; do
|
||||||
if nixos-enter --root "$MNT" -c "passwd $(printf '%q' "$USER_NAME")"; then
|
if nixos-enter --root "$MNT" -c "/nix/var/nix/profiles/system/sw/bin/passwd $(printf '%q' "$USER_NAME")"; then
|
||||||
ok "password set"
|
ok "password set"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@@ -716,7 +718,7 @@ copy_repo_to_home() {
|
|||||||
chown "$USER_UID:100" "$home"
|
chown "$USER_UID:100" "$home"
|
||||||
while IFS= read -r m; do
|
while IFS= read -r m; do
|
||||||
chown "$USER_UID:100" "$m"
|
chown "$USER_UID:100" "$m"
|
||||||
done < <(findmnt -rn -o TARGET | awk -v h="$home/" 'index($0, h) == 1 && substr($0, length(h) + 1) !~ /\//')
|
done < <(findmnt -ln -o TARGET | awk -v h="$home/" 'index($0, h) == 1 && substr($0, length(h) + 1) !~ /\//')
|
||||||
if [ -d "$home/Games" ]; then
|
if [ -d "$home/Games" ]; then
|
||||||
install -d -m 0755 -o "$USER_UID" -g 100 "$home/Games/SteamLibrary"
|
install -d -m 0755 -o "$USER_UID" -g 100 "$home/Games/SteamLibrary"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in new issue
Block a user