Purpose of `swapDevices.*.size`?

I’m using a swapfile like this:

swapDevices = [ { device = "/swap/swapfile"; } ]

And it’s working just fine, so I’m wondering what’s the purpose of swapDevices.*.size? Is it only necessary if you want NixOS to auto-create the swapfile for you?

If you try to set size on a block device (starts with /dev/), you get a warning.

Otherwise a few commands are run in a systemd service to create the swap file just as you said.

And we only create the service if the size (or other conditions) are set.

I see, thanks for clarifying!