Generally I would add an option so the filesystem times out quickly, or use an option so the filesystem only mounts when actually needed.
From what you said this may not help, though. When you regenerate your hardware configuration most options like this aren’t preserved. I assume you’re automatically regenerating your hardware configuration file - why? Depending on why you could add the above mentioned options to configuration.nix.
What do you mean “why?”? Because I want to update drives I mounted. If I add a ZFS filesystem to my setup I run nixos-generate-config to add it to the hardware-configuration.nix. But pretty much always I have some nfs/cifs filesystem mount, because for example I’m playing music from one, so it’s almost always mounted.
And autofs is always mounted, even when no specific filesystems managed by autofs is mounted:
> sudo mount | grep nfs
> sudo mount | grep autofs
/nix/store/gimisssyy7pdmmhl4vv6z1m9xmgm3pdf-melchior on /mnt/melchior type autofs (rw,relatime,fd=6,pgrp=4760,timeout=600,minproto=5,maxproto=5,indirect)
So I don’t think setting a “time out” for that is even doable in the first place.
I assume that to be a fairly rare situation. Since you have to manually provision & format the disk itself it doesn’t seem like much of a stretch to manually add the disk to hardware-configuration.nix. That is what I do on those rare occasions
Did you try using any options like x-systemd.automount, x-systemd.idle-timeout=?, x-systemd.device-timeout=?, x-systemd.mount-timeout=?, and specifying timeout values that work for you?