Don't wait for swap at startup

On one laptop, I have two swap devices (because of reusing historical partitioning / zfs pool):

  swapDevices = [
      device = "/dev/disk/by-id/nvme-T[...]-part2";
      randomEncryption = {
        enable = true;
        allowDiscards = true;
      priority = 1;
      discardPolicy = "both";
      device = "/dev/zvol/rpool/SWAP";
      priority = 0;
      discardPolicy = "both";

It’s using zfs encryption for the pool contents, so I don’t have a separate random encryption requirement there.

This all works fine, except there is a pause during boot, waiting for the zvol device to appear, even after the zfs encryption passphrase has been entered. It’s not unbearably long, maybe 20s or so, but it’s by far the longest pause in the boot process, aside from the passphrase prompt. But it’s annoying, and totally unnecessary: there’s plenty of RAM, another swap device already online (with higher priority), and neither gets used often unless certain heavier workloads get run long after boot.

What I’d like is an option to tell systemd that there’s no need to wait for this swap device to be online, and just let it complete in the background asynchronously. That probably means getting to not wait on it.

There doesn’t seem to be a nix option for it. This gets written out to an fstab file, for systemd generator to parse and make the individual services from, and in turn I can’t see an fstab option for it either. There’s a nofail option but that’s not quite what I want.

Does anyone have any ideas how to do this?

It may also be a matter of adding another dependency in the unit for that swap device. I’m not sure, but it may start trying to start that swap device while waiting for the passphrase, fail a few times, and then go into a longer wait until the next retry, with the "waiting for… " message after the passphrase has been entered.

Either way, there still doesn’t seem to be a way to do that.

I have the same issue, but my critical path is creating the swap with dd, so I just created a PR with an optimization: nixos/swapDevices: faster allocation by kamadorueda · Pull Request #178839 · NixOS/nixpkgs · GitHub

Yeah, that optimisation is potentially not portable across filesystems, as noted already in the PR.

But it could use the same mechanism as desired here to avoid waiting for the dd to finish

Just asking for the sake of humanity. Does someone have a good solution, not to was time on boot on optional swap?