Skip to content

Instantly share code, notes, and snippets.

@linuxluser
Last active September 26, 2021 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linuxluser/6ce06ac61f96d3fab34c35b32fc1cdcf to your computer and use it in GitHub Desktop.
Save linuxluser/6ce06ac61f96d3fab34c35b32fc1cdcf to your computer and use it in GitHub Desktop.

Installing Nixos

Partition Disks w/Encryption and LVM

NOTE: Assumes you're using the entire disk /dev/sda.

$ parted /dev/sda -- mklabel gpt
$ parted /dev/sda -- mkpart primary 512MiB 100%
$ parted /dev/sda -- mkpart ESP fat32 1MiB 512MiB
$ parted /dev/sda -- set 2 esp on
$ mkfs.fat -F 32 -n boot /dev/sda2
$ cryptsetup luksFormat /dev/sda1
$ cryptsetup luksOpen /dev/sda1 xps-enc
$ pvcreate /dev/mapper/xps-enc
$ vgcreate xps-vg /dev/mapper/xps-enc
$ lvcreate -L 8G -n swap xps-vg
$ lvcreate -l '100%FREE' -n root xps-vg
$ mkfs.ext4 -L root /dev/xps-vg/root
$ mkswap -L swap /dev/xps-vg/swap
$ mount /dev/xps-vg/root /mnt
$ mkdir /mnt/boot
$ mount /dev/sda2 /mnt/boot
$ swapon /dev/xps-vg/swap

configuration.nix: GRUB w/EFI support

boot.loader = {
  grub = {
    enable = true;
    version = 2;
    efiSupport = true;
    device = "nodev";
  };
  efi = {
    canTouchEfiVariables = true;
    efiSysMountPoint = "/boot";
  };
};

configuration.nix: LUKS Encryption

Get the UUID of /dev/sda1 and add LUKS configuration clause to unlock at boot:

$ UUID=$(for link in /dev/disk/by-uuid/*; do readlink $link | grep -q sda1 && { echo $(basename $link); break; }; done)
$ cat <<EOF >>/mnt/etc/nixos/configuration.nix
boot.initrd.luks.devices = {
  "xps-enc" = {
    device = "/dev/disk/by-uuid/${UUID}"
    preLVM = true;
  };
};
EOF

configuration.nix: Cinnamon Desktop w/LightDM

services.xserver.displayManager.lightdm.enable = true;
services.xserver.desktopManager.cinnamon.enable = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment