4
submitted 1 year ago* (last edited 1 year ago) by gomp@lemmy.ml to c/nixos@lemmy.ml

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?

top 2 comments
sorted by: hot top controversial new old
[-] Klaymore@sh.itjust.works 3 points 1 year ago* (last edited 1 year ago)

Apparently they still get auto-mounted even if they aren't in your config. You can check the wiki.

[-] PortugalSpaceMoon@infosec.pub 2 points 1 year ago* (last edited 1 year 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.

this post was submitted on 28 Sep 2023
4 points (100.0% liked)

nixos

1262 readers
1 users here now

All about NixOS - https://nixos.org/

founded 4 years ago