How to configure zramSwap.writebackDevice

I would like to configure zramSwap.writebackDevice but both versions are rejected by NixOS. It builds without error but is stuck on boot until the timeout of 1:30min is over:

  zramSwap = {
    enable = true;
    memoryPercent = 20;
    # writebackDevice = "/var/zramSwap-writeback"; # TODO
    writebackDevice = "/dev/nvme0n1p3/zramswap"; # TODO
  };

I don’t understand it because defining device in swapDevices like this works:

  swapDevices = [
    {
      device = "/var/swap";
      size = 8 * 1024; # GiB
    }
  ];

This looks completely wrong, a writeback device is another device that is used for uncompressible blocks instead of zramswap. Just leave writebackDevice blank, should be fine.
Or am I not getting correctly what you meant to do?

I would like to define my SSD as the writeback device so that uncompressible data is swapped to it and not kept in the zram Swap in my RAM. However, i don’t know what i’m doing wrong.

Ah okay, then this is the correct idea:

But not quite correct. You need to use a swap partition (mkswap /dev/nvme0n1p3). But, of course, make sure that this partition doesn’t hold anything. And then put "writebackDevice = “/dev/nvme0n1p3” into your config. I just tested that with an old USB Stick as writeback device, the option was at least accepted… Not sure if it is setup correctly.

However, this will create a writeback device for you, I am not sure if it works as you think/want. The writeback of zram is only done when you tell the kernel to do it (by writing into a special “file”), I am not sure if nix is doing anything useful periodically. Would be very interesting to see what will happen.

I’m not sure if this all is what you want, though; if you want the swap process to directly throw all uncompressible data into the writeback device, zswap is the natural choice for you.
It can be beneficial to the performance and responsiveness of a computer to keep everything in RAM. That works quite well in most cases, for normal desktop use and gaming that was what worked best for me. And that is what zram is built for…

Ah, i see. I didn’t know that i need a partition for it, i thought it would use a swapfile. Thank you!