zramSwap in NixOS enables compressed swap space in RAM using the kernel's zram module, acting as a faster, disk-free alternative to traditional swap partitions or files. It's ideal for systems with sufficient RAM and helps reduce SSD wear. #
Enable zramSwap in your configuration with: boot.kernelModules = [ "zram" ]; zramSwap = { enable = true; priority = 100; # Higher than disk swap to prefer zram algorithm = "zstd"; # Balances speed and compression memoryPercent = 50; # Use up to 50% of RAM for zram }; #
Key benefits: Faster than disk swap, no disk I/O, reduces SSD wear. #
Trade-offs: Uses CPU for compression; not suitable for hibernation (requires a swap partition equal to RAM size). #
Advanced use: Supports writeback to a disk device for incompressible data via writebackDevice . For detailed options, see the NixOS Wiki or the zram.nix module source.