Swap is activated by systemd, so let's query which unit is responsible for it on your NixOS:
sudo systemctl --type swap
This will among other things output the name of the unit that is responsible for activating swap.
Copy it to your clipboard (for me the value is dev-nvme0n1p2.swap
).
Now we will need to let NixOS know that we don't need any swap.
For that, we will need to change the following/similar line in
/etc/nixos/hardware-configuration.nix
:
swapDevices =
[ { device = "/dev/disk/by-uuid/f1378b43-5a09-4d00-a92c-7207e83ba088"; }
];
To something that looks like this:
systemd.units."dev-nvme0n1p2.swap".enable = false;
swapDevices = [];
# [ { device = "/dev/disk/by-uuid/f1378b43-5a09-4d00-a92c-7207e83ba088"; }
# ];
Please note that systemd unit will have to correspond to the value you copied to the clipboard in the beginning.
To check if you have swap enabled or disabled you can use one of the following methods:
lsblk # should produce no lines containing [SWAP]
free -th # should indicate if there is swap capacity available or not
This disables swapping of anonymous pages but not mapped pages. Because anonymous pages are swapped first and accessed less frequently, this will cause even more swap thrashing when you run out of memory than if you had kept a swap partition.
You need either a kernel patch or to configure a cgroup with memory.min set to all RAM along with this change in order for both types of pages to be unswappable.