Handbook:NixOS setup

In an effort to improve my sysadmin/DevOps skills and to learn how to manage a NixOS install locally (besides bloody Windows 10), I decided to embark on a journey that involves nuking my current Ubuntu install, reorganize partitions painfully, and finally do the installation. I also document the process I did for my future self to remember about this.

Goals

 * NixOS 22.11 (as of time of writing)
 * Separate partition (aka multiboot setup alongside Windows) on a laptop
 * In my current setup, my home directory is on a separate partition for safekeeping and to make backups easier in case I inadvently nuked the partition where that distro is installed.
 * Create a bootable USB for UEFI mode via Rufus (or pick your own)
 * UEFI mode, without the Secure Boot shitfuckery of WIndows 11.

Prerequisites

 * The latest ISO, with either GNOME Desktop or KDE Plasma included - Since both desktop ISOs have GParted installed, we can partition things painlessly, although you can open the terminal with Ctrl+Alt+T and learn how to use fdisk and gdisk.
 * Internet connection - This is obvious, unless you're using proprietary drivers (spoiler: Broadcom Wi-Fi drivers). Get yourself an Ethernet cable or a wireless Wi-Fi adapter if that's the case.
 * Maybe ample amount of free storage. In my case, I give my HP laptop ~56 GB for the distribution itself, although you do you if you store your pirated stash outside the internal hard drive.
 * Secure Boot disabled - Bloody Windows 11 wants to make every Linux distro's EFI images to be signed with Microsoft keys, but PC manufacturers simply don't care or just make consumers' lives miserable in managing keys. We'll leave UEFI mode enabled.

The boring stuff

 * 1) Get the latest ISO from the website. In my case, I chose the "Graphical installation" with KDE Plasma so that I can use the graphical installer and check the manual via Firefox, although you can go with "Minimal installation" and use lynx and tmux.
 * 2) Get a copy of Rufus installed while you wait. Once downloaded, launch the app, select GPT (since we're messing around with UEFI mode), and leave the defaults untouched. Select the ISO, tick Quick format for good measure, and also tick "Create extended label and icon files" as well.
 * 3) * If you're like me who want to check the USB drive for bad sectors first, go to advanced format options and tick Check device for bad sectors.
 * 4) Hit Start to start formatting. Rufus might prompt you if you want to use ISO or DD mode, pick DD. At the time of this tutorial's writing which might be outdated by today's standards, the NixOS ISO seems to only like DD, and for non-Windows users the recommended way to mount the image is using   anyway. It may also prompt you about downloading Syslinux files, click yes. It will just download these files in the same folder as wherever Rufus was started from, you can delete them after.
 * 5) After formatting the USB for NixOS, reboot your laptop/desktop computer to BIOS/UEFI settings (a quick search should be enough for particular motherboard/laptop model), find Secure Boot and disable it.
 * 6) * It is recommended to back up the PK keys to another USB drive in case something go horribly wrong if we chose to embark this with Secure Boot enabled, because blame Windows 11.

The fun stuff - Partitioning your drive
If you do use the graphical installation ISO, check if GParted is installed and open it. Otherwise, go to the UEFI install section of NixOS manual, fdisk in Arch Wiki and some walkthroughs for gdisk.

The fun stuff - The installation process
Follow the prompts for the graphical installer as usual. For the minimal install, read on.


 * Generate NixOS config with nixos-generate-config --root /mnt (assuming you mounted your to-be-NixOS partition, alongside with anything else). Edit that file with nano (or Vim) as needed, including anything related to encrypted LUKS partitions.
 * TODO: Explain about Wi-Fi setup here.
 * See https://nixos.wiki/wiki/Dual_Booting_NixOS_and_Windows#Grub_2 for setting up GRUB instead of systemd-boot for multiboot setups for minimal installation.