NixOS on LVM - hpaluch/hpaluch.github.io GitHub Wiki

Install minimal NixOS on LVM

After installing Guix System on LVM (see Guix on LVM I decided to try also NixOS on LVM for comparison.

Used installation iso:

$ ls -lo nixos-minimal-25.11.10684.8fd9daa3db09-x86_64-linux.iso

-rw-r--r--. 1 qemu 1632927744 May 14 18:21 nixos-minimal-25.11.10684.8fd9daa3db09-x86_64-linux.iso

$ sha256sum -b nixos-minimal-25.11.10684.8fd9daa3db09-x86_64-linux.iso

02c64f483c77e99070ae1982fcca102609865d6c2ec6460081c3ab5911da5cb8 *nixos-minimal-25.11.10684.8fd9daa3db09-x86_64-linux.iso

I used VM under LibVirt with following parameters:

  • OS: NixOS Unstable (automatically detected)
  • Memory: 8192 MB (nix-env -qa NAME is extremely memory hungry - eating 6GB or more)
  • CPUs: 2
  • disk: 40GB
  • Name: nixos-lvm-efi
  • checked: Customize configuration...
  • Overview -> Firmware -> change to UEFI
  • Video: changed from VGA to QXL

Additionally - I plan to deploy later it to SATA disk (/dev/sdX) so I changed Virtio-BLK to Virtio-SCSI using:

  • Add Hardware -> Controller -> SCSI -> Virtio SCSI
  • select VirtIO Disk 1 and change Disk bus: to SCSI

Now click on Begin Installation to proceed.

It WILL fail because there is no signed boot loader on ISO.

To remedy that failure:

  • press any key to enter Boot Manager Menu
  • ENTER on Device Manager -> Secure Boot Configuration -> Attempt Secure Boot -> [X]
  • press SPACE to deselect it
  • press ESC several time to return to main menu
  • select and press on Reset
  • it WILL again fail - because virt-manager thought Reset occurred after OS installation so it removed installation ISO
  • on Info tab select SATA CDROM 1 and attach again ISO.
  • go to Boot Options and check on SATA CDROM 1
  • on menu click on Force Reset - now system should finally boot

Now we will enable remote SSH access to NixOS VM so we can copy & paste commands:

  • you should be autologged as nixos user
  • run:
    sudo passwd root
    nmcli # to get IP address
    ip -br -4 a
    
  • SSHd should be already running (try systemctl status sshd)
  • try to connect from Client using ssh root@IP_OF_VM

Now we will mostly follow: https://nixos.org/manual/nixos/stable/#ex-config

# ensure that we have `/dev/sda` disk:

lsblk -d -o+model | grep disk

  sda     8:0    0   40G  0 disk                QEMU HARDDISK

# WARNING: I properly reordered partitions (ESP first) and added
# just one LVM volume:

d=/dev/sda
parted $d -- mklabel gpt
parted $d -- mkpart ESP fat32 1MB 512MB
parted $d -- set 1 esp on
parted $d -- mkpart root 512MB 100%
parted $d -- set 2 lvm on

# now verify Device names!
fdisk -l /dev/sda | sed '1,/^$/d'

Device      Start      End  Sectors  Size Type
/dev/sda1    2048   999423   997376  487M EFI System
/dev/sda2  999424 83884031 82884608 39.5G Linux LVM

# my custom part: creating LVM
pvcreate /dev/sda2
vgcreate nixosvg /dev/sda2
# 8GB swap
lvcreate -n swap -L 8G nixosvg
# use remaining 98% of space for filesystem
lvcreate -n rootfs -l 98%FREE nixosvg

# format filesystems:
# NOTE: using uppercase 'BOOT' instead of 'boot' because of FAT restrictions
mkfs.fat -F 32 -n BOOT /dev/sda1
mkfs.ext4 -L nixos /dev/mapper/nixosvg-rootfs
mkswap -L swap /dev/mapper/nixosvg-swap
swapon /dev/mapper/nixosvg-swap

Now we will follow docs on https://nixos.org/manual/nixos/stable/#ex-config:

mount /dev/disk/by-label/nixos /mnt
mkdir -p /mnt/boot
mount -o umask=077 /dev/disk/by-label/BOOT /mnt/boot
nixos-generate-config --root /mnt
vi /mnt/etc/nixos/configuration.nix

I did following changes (mostly from manual):

 users.users.alice = {
     isNormalUser = true;
     extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
     packages = with pkgs; [
       tree
     ];
  };

 environment.systemPackages = with pkgs; [
     git mc tmux vim wget
  ];
 services.openssh.enable = true;

And finally:

nixos-install
# will be asked for 'root' password ..

reboot

After reboot:

  • login as 'root' with specific password
  • remember to set alice's password with: passwd alice