HeadlinesBriefing favicon HeadlinesBriefing.com

Swap, ZRAM, Zswap and Hibernate on NixOS

Hacker News •
×

I pulled this out of my non-obvious nixos config piece into its own post. Note: I'm going to Nix Con 2026, say hello if you're going as well! Oh no, I'm going to talk about swap, zram, zswap...

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. This will first ACPI S3 suspend to RAM, then after a delay go into S4 Hibernate. To use hibernate you need swap to save your system state to disk.

There are also arguments over swap files vs swap partitions. On a UEFI system the details are saved into an EFI variable when hibernation starts. I set up my desktop with a simple swap partition. I set up my laptop with LUKS encryption and a swap file. 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.

My current configuration is simply: boot.zswap.enable = true; boot.kernel.sysctl."vm.swappiness" = 100. Chris Down recommends using zswap with disk-backed swap. Swappiness controls the relative cost of swapping and filesystem paging so it will depend on your particular hardware. For now, 100 is serving me well with my SSDs.