// HACKER NEWS — CYBERSECURITY
Swap, ZRAM, Zswap and Hibernate on NixOS
Note: I'm going to NixCon 2026, say hello if you're going as well!
Whether to use swap is a perennial fight online. The conversation is often muddled when people conflate recommendations for servers with recommendations for workstations. In my case, I'm going to focus on desktops and laptops.
I use swap because I like suspend-then-hibernate, or "Standby, then hibernate" in the KDE settings:
![[Pasted image 20260917120542.png]]
This will first ACPI S3 suspend to RAM, then after a delay go into S4 Hibernate. I think this strikes a nice balance: if I step away for a bit I don't have to wait for things to start up, but I don't have to worry if I forget to fully power off my machine.
To use hibernate you need swap to save your system state to disk.
There are also arguments over swap files vs swap partitions. I mostly want to note that swap files can complicate hibernate. That is because when you resume from hibernate initramfs needs to know the location of the swap space before the file systems are mounted. On a UEFI system the details are saved into an EFI variable when hibernation starts.
I set up my laptop with LUKS encryption and a swap file:
This is based on the disko luks-btrfs-subvolumes template.
The good news is that for a while now NixOS understands the nuances of hibernate on swap files and can handle figuring out the offsets.
If I'm going to use swap I want to make sure I use it right. The piece In Defence of Swap and the followup Debunking zswap and zram myths provide a lot of important context. As a starting point, Chris Down recommends using zswap with disk-backed swap.