nix

n.b.: this is a guide for using nix/entering nixos on archlinux

pacman -S nix
  • start daemon (allows operations on nix store without sudo/root)
sudo systemctl enable nix-daemon.service
sudo systemctl start  nix-daemon.service
  • add self to nix-users
sudo gpasswd -a username nix-users
  • don't use channels because not reproducible, so don't do the below
nix-channel --add https://nixos.org/channels/nixpkgs-unstable
nix-channel --update
  • enable flakes and new CLI interface by editing ~/.config/nix/nix.conf
experimental-features = nix-command flakes
nix-collect-garbage

home-manager

nix run home-manager/master -- init --switch
  • problem with gc:
home-manager switch
nix-store --gc
home-manager switch
  • keeps clearing/re-downloading on every switch

  • looking at the stores: nixpkgs and home-manager, precisely the inputs to the flake

  • solution: use nix-direnv to register flake inputs as gc root

  • problem: failed to set locale

  • solution: set LOCALE_ARCHIVE to

/nix/store/{hash}-glibc-locales-{version}/lib/locale/locale-archive

installing nixos with kexec

nixos-generate-config
  • (optional) use flake template for configuration.nix
nix flake new /etc/nixos -t github:nix-community/home-manager#nixos

configuration tips

  • need to import netboot-minimal.nix
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      (modulesPath + "/installer/netboot/netboot-minimal.nix")
    ];
  # overwrite /installer/netboot/netboot-minimal.nix
  hardware.enableRedistributableFirmware = lib.mkForce true;
  • on luks, probably need to manually specify root partition
  boot.initrd.luks.devices.cryptlvm.device =
    "/dev/disk/by-uuid/5d57809c-d0e9-49e9-939e-f5d68392faf4";
  # manually specify because `nixos-generate-config` doesn't pick it up
  fileSystems."/" = {
    device = "/dev/VolumeGroup/root";
    fsType = "ext4";
  };
  boot.kernelParams = [ "boot.shell_on_fail" ];

entering the build

  • not risking normal build (overwrites bootloader), try kexec to prototype
  • arch wiki - kexec
pacman -S kexec-tools
  • generate kernel image
nix-build '<nixpkgs/nixos>' \
    -I /nix/store/{hash}-nixpkgs \
    --arg configuration ./configuration.nix \
    --attr config.system.build.kexecTree
  • if using flakes, path to nixpkgs can also be -I nixpkgs=flake:nixpkgs

  • turn off kernel mode setting

  • /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="... quiet loglevel=3 ... nomodeset"
  • remove amdgpu kernel module

  • /etc/mkinitcpio.conf

MODULES=()
  • reload grub/initramfs, reboot, go into vt, run sudo ./result/kexec-boot