Skip to content

Instantly share code, notes, and snippets.

@kekneus373
Created March 22, 2026 19:39
Show Gist options
  • Select an option

  • Save kekneus373/8e22121c23d0ced11b1c8c4a4fd1a2e6 to your computer and use it in GitHub Desktop.

Select an option

Save kekneus373/8e22121c23d0ced11b1c8c4a4fd1a2e6 to your computer and use it in GitHub Desktop.
[NixOS] Set Up Zram Swap

Zram nixos

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment