diff --git a/README.md b/README.md index f5f9071..b05b98e 100644 --- a/README.md +++ b/README.md @@ -1,161 +1,64 @@ -# mads — NixOS config (one flake, two machines) +# nixos -Declarative NixOS for: +One flake, two machines. Hyprland + greetd autologin, Zen+Tridactyl, neovim, zsh+starship. -| host | `nixosConfigurations.` | arch | notes | -|------|------------------------------|------|-------| -| MacBook (M1 Pro, Asahi) | `mbp` | `aarch64-linux` | Apple Silicon support module + vendored firmware | -| Arbitrary x86 PC | `pc` | `x86_64-linux` | plain NixOS | - -Everything shared (Hyprland, greetd autologin, Zen+Tridactyl, neovim, zsh+starship, -packages, user) lives in the `common` / `home` modules in `flake.nix`. Host-specific -bits (Asahi firmware/cache vs. x86 boot) are the small inline modules per host. +| host | arch | build | +|------|------|-------| +| `mbp` | aarch64 | MacBook M1 Pro (Asahi) | +| `pc` | x86_64 | any UEFI x86 | ``` -flake.nix inputs + common/home modules + both hosts -hosts/mbp/hardware-configuration.nix ← DUMMY, regenerate on the Mac -hosts/pc/hardware-configuration.nix ← DUMMY, regenerate on the PC -config/ hypr eww fuzzel nvim raw configs (sourced by home-manager) -firmware/ Wi-Fi/BT blobs (Mac only, git-add at install) +flake.nix all config (common + home modules, both hosts) +config/ raw configs: hypr eww fuzzel nvim +hosts/*/hardware-configuration.nix mbp: regenerate on Mac · pc: generic, as-is +firmware/ Mac Wi-Fi/BT blobs — git-add at install. KEEP REPO PRIVATE. ``` -> **Keep this repo private** — the Mac firmware under `firmware/` is non-redistributable. +Set `time.timeZone` in `common`. Rename a host = change the `nixosConfigurations.` key + its `networking.hostName`. -The `hardware-configuration.nix` files are placeholders so the flake evaluates -off-target; each is overwritten by `nixos-generate-config` during that machine's install. +## Apply ---- - -## Rename a host / set your timezone - -- Host name: change the `nixosConfigurations.` key **and** its - `networking.hostName` in `flake.nix` (e.g. `pc` → `desktop`). -- `time.timeZone` is in the `common` module. - ---- - -## Install on the MacBook (Asahi + NixOS) - -Follows the official guide — **always check the latest**, as steps change: - -(this config tracks Asahi `main`; currently kernel `linux-asahi 7.0.13`). - -> ⚠ **Back up first.** Damaging the GPT / first / last partition can brick the Mac -> and lose all data. - -### 1. macOS → install the UEFI environment -In macOS Terminal (admin account): ```sh -curl https://alx.sh | sh +sudo nixos-rebuild switch --flake ~/nixos#mbp # or #pc +nix flake update && sudo nixos-rebuild switch --flake ~/nixos#mbp # update ``` -- `r` — resize macOS, leave ≥ 20 GB free for NixOS -- `f` — install into free space → **UEFI environment only**, name it `NixOS` -- Reboot into recovery when told; set **permissive security** for the new OS. -- It reboots into U-Boot (Asahi + U-Boot logos). Power off. +Roll back = pick an older generation at boot. -### 2. Build + write the installer USB -On any Linux box with Nix (or download a release ISO from the repo's Releases): -```sh -nix build github:nix-community/nixos-apple-silicon#installer-bootstrap -o installer -sudo dd if=installer/iso/nixos-*.iso of=/dev/sdX bs=4M conv=fsync status=progress -``` -(`dd` only — not unetbootin.) +## Install: MacBook (Asahi) -### 3. Boot the installer, partition, mount -Boot the USB (U-Boot → GRUB → installer), then: +Full/latest guide: . **Back up — a bad partition can brick the Mac.** + +1. macOS Terminal: `curl https://alx.sh | sh` → `r` resize (≥20 GB free) → `f` install **UEFI environment only**, name `NixOS` → recovery: permissive security. Reboots to U-Boot; power off. +2. Installer USB (on a Linux+Nix box): `nix build github:nix-community/nixos-apple-silicon#installer-bootstrap -o installer` then `dd` the ISO to USB. +3. Boot USB → `sudo su`: ```sh -sudo su -sgdisk /dev/nvme0n1 -n 0:0 -s # root fills free space -sgdisk /dev/nvme0n1 -p # find the new 8300 partition number (e.g. p5) +sgdisk /dev/nvme0n1 -n 0:0 -s && sgdisk /dev/nvme0n1 -p # note new 8300 part, e.g. p5 mkfs.ext4 -L nixos /dev/nvme0n1p5 - -mount /dev/disk/by-label/nixos /mnt -mkdir -p /mnt/boot +mount /dev/disk/by-label/nixos /mnt && mkdir -p /mnt/boot mount /dev/disk/by-partuuid/$(cat /proc/device-tree/chosen/asahi,efi-system-partition) /mnt/boot -``` - -### 4. Hardware config + vendored firmware + this flake -```sh nixos-generate-config --root /mnt - -# get this repo onto the target (private remote or USB), e.g.: -git clone /mnt/etc/nixos/config && cd /mnt/etc/nixos/config - -cp /mnt/etc/nixos/hardware-configuration.nix hosts/mbp/hardware-configuration.nix - -# vendor the Wi-Fi/BT firmware (pure flakes can't read /boot/asahi) -mkdir -p firmware -cp /mnt/boot/asahi/all_firmware.tar.gz firmware/ -cp /mnt/boot/asahi/kernelcache* firmware/ +git clone /mnt/root/nixos && cd /mnt/root/nixos +cp /mnt/etc/nixos/hardware-configuration.nix hosts/mbp/ +mkdir -p firmware && cp /mnt/boot/asahi/{all_firmware.tar.gz,kernelcache*} firmware/ git add -f hosts/mbp/hardware-configuration.nix firmware/* +nixos-install --flake .#mbp && reboot ``` -### 5. Install +## Install: x86 + +No hardware generation — `hosts/pc/hardware-configuration.nix` is generic (mounts by label). Boot the NixOS ISO, `sudo -i`: ```sh -nixos-install --flake .#mbp # sets root password at the end -reboot -``` -Boot picker: hold the power button. greetd autologins `mads` into Hyprland. -**First thing after login: `passwd`** (the config ships `initialPassword = "changeme"`). - ---- - -## Install on an x86 PC - -Standard NixOS install (), -just point `nixos-install` at `.#pc`. - -### 1. Boot the NixOS ISO, get network, partition (UEFI/GPT) -```sh -sudo -i -parted /dev/nvme0n1 -- mklabel gpt -parted /dev/nvme0n1 -- mkpart ESP fat32 1MiB 512MiB -parted /dev/nvme0n1 -- set 1 esp on -parted /dev/nvme0n1 -- mkpart primary 512MiB 100% - +parted /dev/nvme0n1 -- mklabel gpt \ + mkpart ESP fat32 1MiB 512MiB set 1 esp on \ + mkpart primary 512MiB 100% mkfs.fat -F32 -n BOOT /dev/nvme0n1p1 mkfs.ext4 -L nixos /dev/nvme0n1p2 - -mount /dev/disk/by-label/nixos /mnt -mkdir -p /mnt/boot -mount /dev/disk/by-label/BOOT /mnt/boot +mount /dev/disk/by-label/nixos /mnt && mkdir -p /mnt/boot && mount /dev/disk/by-label/BOOT /mnt/boot +git clone /mnt/root/nixos && cd /mnt/root/nixos +nixos-install --flake .#pc && reboot ``` -(The `BOOT` / `nixos` labels match the dummy `hosts/pc/hardware-configuration.nix`, -but the generated one below replaces it with real UUIDs anyway.) +Exotic storage controller won't boot? Add its module to `availableKernelModules` in `hosts/pc/hardware-configuration.nix` (`nixos-generate-config --show-hardware-config` lists it). -### 2. Hardware config + this flake + install -```sh -nixos-generate-config --root /mnt -git clone /mnt/etc/nixos/config && cd /mnt/etc/nixos/config -cp /mnt/etc/nixos/hardware-configuration.nix hosts/pc/hardware-configuration.nix +## After first boot -nixos-install --flake .#pc -reboot -``` -Then `passwd`. - ---- - -## Day-to-day - -```sh -# apply config changes -sudo nixos-rebuild switch --flake ~/nixos#mbp # or #pc - -# update everything (nixpkgs + asahi + zen + addons), then rebuild -nix flake update -sudo nixos-rebuild switch --flake ~/nixos#mbp - -# roll back: pick a previous generation in the boot menu -``` - -Both `apple-silicon` and `nixpkgs` are cached (asahi via its Cachix), so updates -download rather than compile. - ---- - -## Verify-on-first-boot (can't be checked off-machine) - -- **greetd session** — the command is `uwsm start hyprland`. If you land on a blank - tty instead of Hyprland, change it to `command = "Hyprland"` in `common`. -- **Asahi `hardware.asahi.*`** — firmware path / sound options, per the guide above. +`passwd` (ships `initialPassword = "changeme"`). If you land on a tty instead of Hyprland, change greetd's `uwsm start hyprland` → `Hyprland` in `common`. diff --git a/hosts/pc/hardware-configuration.nix b/hosts/pc/hardware-configuration.nix index 0f4c551..b33d089 100644 --- a/hosts/pc/hardware-configuration.nix +++ b/hosts/pc/hardware-configuration.nix @@ -1,8 +1,20 @@ -# DUMMY x86 hardware config — just enough for `nix eval`/build off-target. -# OVERWRITTEN at install by: nixos-generate-config --root /mnt -# then copy /mnt/etc/nixos/hardware-configuration.nix here. -{ ... }: +# Generic x86_64 UEFI hardware profile — boots on most machines WITHOUT +# per-machine `nixos-generate-config`, as long as you format the disks with the +# labels `nixos` (root) and `BOOT` (ESP). +# +# `availableKernelModules` covers NVMe + SATA/AHCI + USB boot. An exotic storage +# controller could need one more entry — check with: +# nixos-generate-config --show-hardware-config +{ modulesPath, ... }: { + imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + + boot.initrd.availableKernelModules = [ + "nvme" "xhci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" "sr_mod" "vmd" + ]; + + hardware.enableRedistributableFirmware = true; # wifi/gpu firmware for arbitrary hw + fileSystems."/" = { device = "/dev/disk/by-label/nixos"; fsType = "ext4"; @@ -11,4 +23,6 @@ device = "/dev/disk/by-label/BOOT"; fsType = "vfat"; }; + + swapDevices = [ ]; }