I’m playing around with nixos in a few VMs and at some point I realized I must have lost the swap configuration in one of my refactorings.

To my surprise, however, the VMs do use the swap partitions I had set up.

There is no mention on “swap” in my nix configuration (or in fstab) and no .swap units in /etc/systemd/system; I do however have a swap partition labelled “swap”.

Turns out there is a systemd unit (albeit not a corresponding file) that sets up swap:

[root@vm1:~]# free -hw
               total        used        free      shared     buffers       cache   available
Mem:           2.8Gi       664Mi       955Mi       4.0Mi       3.0Mi       1.3Gi       2.0Gi
Swap:          3.7Gi          0B       3.7Gi

[root@vm1:~]# systemctl list-dependencies swap.target 
swap.target
● └─dev-disk-by\x2ddiskseq-1\x2dpart3.swap

I’m wondering where the unit comes from? Can I rely on this and never configure swap ever again?

  • PortugalSpaceMoon@infosec.pub
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    9 months ago

    It’s difficult to say without seeing your nixos config. Are you importing any nixos modules? Would you be able to share your configs?

    Also see https://nixos.wiki/wiki/Swap In paricular:

    If you are using GPT partitioning tables, systemd-gpt-auto-generator(8) will still mount your swap partition automatically.