Swap: Difference between revisions

From NixOS Wiki
imported>Yuu
No edit summary
imported>Axelbdt
Add method to add swapfile
Line 1: Line 1:
== Configuration ==
== Configuration ==
Swap on NixOS is set with the option <code>swapDevices</code> on <code>/etc/nixos/hardware-configuration.nix</code>.
Swap on NixOS is set with the option <code>swapDevices</code> on <code>/etc/nixos/hardware-configuration.nix</code>.
=== Add a Swapfile ===
Add a swapfile with the following :
<syntaxhighlight lang="nix">
swapDevices = [ {
    device = "/var/lib/swapfile";
    size = 16*1024;
  } ];
</syntaxhighlight>


=== Disable swap ===  
=== Disable swap ===  

Revision as of 12:25, 22 March 2023

Configuration

Swap on NixOS is set with the option swapDevices on /etc/nixos/hardware-configuration.nix.

Add a Swapfile

Add a swapfile with the following :

 swapDevices = [ {
    device = "/var/lib/swapfile";
    size = 16*1024;
  } ];

Disable swap

To remove all swap devices from NixOS, set the following to remove the swap partition or file from being included in /etc/fstab.

swapDevices = lib.mkForce [ ];

If you are using GPT partitioning tables, systemd-gpt-auto-generator(8) will still mount your swap partition automatically. You must therefore turn on attribute 63 on your partition in the partition table. This can be done with gptfdisk or similar:

gdisk /dev/sda
x
a
<partition number>
63
<enter>
w