A swap file is extra space on your disk that helps when your computer runs out of memory.
1. create the swap file (e.g., 8GB)
1. sudo fallocate -l 8G /swapfile or(sudo dd if=/dev/zero of=/swapfile bs=1M count=8192)
2. sudo chmod 600 /swapfile
3. sudo mkswap /swapfile
2. add this to your /etc/nixos/configuration.nix
swapDevices = [
{
device = "/swapfile";
}
];
3. rebuild your NixOS system
sudo nixos-rebuild switch
4. activate the swap file immediately
sudo swapon /swapfile
It’s not recommended unless the drive is NVMe and not fast enough.