How to install NixOS with LUKS disk encryption
Introduction
I’ve done a NixOS server installation before. This time, I’m doing a client installation with LUKS disk encryption.
Actually, it’s quite simple. If you are using the graphical installer, you can choose Encryption
in the Partition
section and set a password.
If you want to install NixOS via the command line, you can follow the steps below. These steps are based on this excellent step-by-step guide with the necessary commands, which I found very helpful in making this note.
Requirements
I first downloaded the minimal ISO image and used Rufus to copy it onto a USB stick with my Windows PC. After opening the ISO with Rufus, I kept all settings default but opted to write with dd
.
In the UEFI BIOS menu, I disabled Secure Boot
. According to this description, you also need to turn off USB Legacy Boot
and turn on Launch CSM
. However, I didn’t have to do this with my relatively new Intel NUC. I also used a new SSD for the installation.
Now boot from the USB stick. If you see multiple boot options, choose the one explicitly labeled with UEFI
.
How To
Partitioning
-
Identify the name of your disk with the command:
In my case, the name of the SSD is
/dev/nvme0n1
, which is the name I use in the commands below. However, it could also be something like/dev/sda
, for example. -
Wipe the existing disk:
-
Create a new partition table:
-
Create the boot partition at the beginning of the disk:
-
Create the primary partition:
Now
/dev/nvme0n1p1
is the boot partition, and/dev/nvme0n1p2
is the primary partition. You can verify this with the command:lsblk
. -
Setup LUKS encryption on the primary partition (
crypted
is the label). This will prompt for creating a password: -
Map the physical, encrypted volume, then create a new volume group and logical volumes in that group for our NixOS root and our swap:
-
Format the boot volume to
FAT32
and the filesystem toEXT4
and also create a swap: -
Mount the target file system to
/mnt
: -
Mount the boot file system on
/mnt/boot
for UEFI boot: -
And activate the swap:
-
Now check the results with:
It should look something like this. Write down the UUID of the disk, in my case:
/dev/nvme0n1
.
Installation
Now we can install NixOS. If you only have WiFi, you can read this on how to activate it. Personally, I use a network cable.
-
Generate the configuration:
-
Modify
/etc/nixos/configuration.nix
:Instructions:
- Required Replace
<the uuid of /dev/nvme0n1>
with the UUID mentioned earlier - Required Replace
Europe/Amsterdam
with your own timezone - Required Replace
uk
with your own keyboard layout
This is a basic configuration. I’ve already set the timezone and keyboard layout, and you can enable wireless networking.
- Required Replace
-
Install NixOS:
Switching between configurations
Now, we’re testing to ensure everything works correctly and adding a user so we don’t have to use root anymore.
-
Power on your PC and if all goes well you will be asked for the LUKS password!
-
Log in with
root
-
Add the user to
/etc/nixos/configuration.nix
:Instructions:
- Required Replace
<username>
with your username
- Required Replace
-
To apply the new NixOS configuration, run the following command:
-
The final step is to set the password of the new user
Instructions:
- Required Replace
<username>
with your username
Now, you can
logout
and log in with this user to further configure NixOS. - Required Replace
No comments found for this note.
Join the discussion for this note on Github. Comments appear on this page instantly.