Working zswap configuration (different from zram)

@R-VdP not at all, really appreciate the information you shared. The entry (Module request: config.zswap · Issue #119244 · NixOS/nixpkgs · GitHub) here seems to suggest that certain modules that zswap depends on are not readily available in the nixos kernel and hence need to be loaded and we may even need to create a custom kernel patch to include these missing modules that zswap depends on.

You are right in stating that we can use basic systemd configs, one of the users at the end recommend a systemd script that I tested and is working. I have yet to test adding the modules into boot.kernalParams though:

systemd.services.zswap = {
  description = "Enable ZSwap, set to LZ4 and Z3FOLD";
  enable = true;
  wantedBy = [ "basic.target" ];
  path = [ pkgs.bash ];
  serviceConfig = {
    ExecStart = ''${pkgs.bash}/bin/bash -c 'cd /sys/module/zswap/parameters&& \
    echo 1 > enabled&& \
    echo 20 > max_pool_percent&& \
    echo zstd > compressor&& \
    echo z3fold > zpool'
    '';
  Type = "simple";
  };
};

relevant snaps from Issues · NixOS/nixpkgs · GitHub