Files
Nomarchy/hosts/nomarchy-live.nix
Bernardo Magri f318585dc4 fix(installer): harden disk selection and partitioning phase
The disk phase was the dominant source of incomplete installs. Six
concrete failure modes addressed in one pass:

1. Live-ISO USB excluded from the disk picker. select_disk previously
   filtered loop|ram|zram|sr but not the device the installer booted
   from; picking it would format the boot media mid-install. New
   detect_live_iso_devices walks /, /iso, /run/initramfs/live,
   /nix/.ro-store, /nix/store and resolves each backing device to its
   parent disk via lsblk -no PKNAME. Override with
   NOMARCHY_INSTALL_ALLOW_ISO_TARGET=1 for the developer case.

2. 10 GiB minimum-capacity preflight. Disko fails late and obscurely
   on undersized media; surface it while the picker is still open.

3. prewipe_target_drive rewritten:
   - Enumerates every active dm-crypt mapping via dmsetup ls and
     closes those whose backing device is on the target drive. The
     old version only knew about the hardcoded names "crypted" /
     "crypted_main" so an aborted multi-disk run or a non-Nomarchy
     install would leave a holder open and silently break the wipe.
   - Drops `|| true` from wipefs / sgdisk / dd. After the LUKS and
     swap teardown above, a real failure means something is still
     holding the device — surface that instead of papering over it.
   - udevadm settle bounded to 30s so a flapping USB can't hang.
   - Post-wipe sanity check: refuse to hand the disk to disko if
     anything is still mounted off it.

4. run_disko_with_retry wraps the disko call. On failure, shows the
   last 30 lines of output via gum style and offers Retry /
   View full log / Abort. set -e is suspended for the disko call so
   the exit code can be inspected. The previous bare `disko --mode
   disko` aborted the whole installer with output scrolled past.

5. Sed-templated disko-golden.nix + disko-btrfs-multi.nix pair
   replaced by a single disko-config.nix Nix function of
   { mainDrive, extraDrives ? [] } called via --argstr / --arg.
   Templating Nix via shell-escaped string substitution caused at
   least one production bug (3aadc36 fixed embedded-newline
   escaping); function arguments are the right shape and eliminate
   the entire class of escaping concerns. Single-disk path is
   `extraDrives = []`; multi-disk gets BTRFS `-d single -m raid1`
   plus the additional /dev/mapper/* devices. Hosts that shipped
   /etc/disko-golden.nix now ship /etc/disko-config.nix.

6. EXIT trap added so the tmpfs LUKS key file (/dev/shm/nomarchy-
   luks.key) is removed even if the script aborts between key-write
   and the explicit unset. Replaced redundant `shred -u` on tmpfs
   with `rm -f` (already in RAM).

Verification: bash -n on install.sh, nix-instantiate parse + strict
eval on disko-config.nix in both single and multi shapes, full
nix flake check --no-build evaluating all three NixOS configurations
(default, nomarchy-installer, nomarchy-live) plus the installerVm.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 19:42:00 +01:00

81 lines
2.8 KiB
Nix

{ config, pkgs, inputs, lib, ... }:
{
# Live-ISO defaults. The install.sh keymap step calls `hyprctl keyword
# input:kb_layout` at runtime so the user's pick takes effect during the
# install, and writes the chosen value into the *installed* system.
console.keyMap = lib.mkDefault "us";
i18n.defaultLocale = lib.mkDefault "en_US.UTF-8";
services.xserver.xkb.layout = lib.mkDefault "us";
# ISO Branding
isoImage.volumeID = lib.mkForce "NOMARCHY_LIVE";
isoImage.edition = lib.mkForce "graphical";
# Home Manager activation for the nixos live user is provided by the
# home-manager.nixosModules.home-manager module wired up in flake.nix.
environment.systemPackages = with pkgs; [
git
gum
alacritty
parted
btrfs-progs
cryptsetup
inputs.disko.packages.${pkgs.stdenv.hostPlatform.system}.disko
(pkgs.makeDesktopItem {
name = "install-nomarchy";
desktopName = "Install Nomarchy";
exec = "alacritty -e sudo /etc/install.sh";
terminal = false;
categories = [ "System" ];
})
];
# Ensure the live environment user has the necessary groups for graphical acceleration and audio
users.users.nixos.extraGroups = [ "wheel" "video" "render" "audio" "networkmanager" ];
# Graphics support for live environment.
#
# Force-loading every GPU driver in the initrd (amdgpu+radeon+nouveau+i915)
# panics most machines — only one of them can claim the GPU and the others
# explode. List them under `availableKernelModules` instead so udev only
# loads the one that matches the present hardware. We still force the AMD
# pair when Plymouth needs KMS early; `virtio_gpu` is auto-loaded when
# we're booted in QEMU via nomarchy-test-live-iso.
boot.initrd.availableKernelModules = [
"amdgpu" "radeon" "nouveau" "i915" "virtio_gpu"
];
services.xserver.videoDrivers = [ "amdgpu" "radeon" "nouveau" "modesetting" "fbdev" "virtio" ];
environment.etc."install.sh" = {
source = ../installer/install.sh;
mode = "0755";
};
environment.etc."hardware-db.sh" = {
source = ../installer/hardware-db.sh;
mode = "0644";
};
environment.etc."disko-config.nix" = {
source = ../installer/disko-config.nix;
};
environment.etc."nomarchy".source = inputs.self;
# Override the upstream installer helpLine (says "NixOS", points nowhere
# useful for us). Shown on every TTY before login and again as the MOTD.
services.getty.helpLine = lib.mkForce ''
Welcome to the Nomarchy live environment.
To install Nomarchy: sudo /etc/install.sh
To preview the install: sudo /etc/install.sh --dry-run
To resume an interrupted run: sudo /etc/install.sh --resume
The graphical session autologins as 'nixos' (no password).
The 'nixos' and 'root' accounts have empty passwords.
'';
}