Been struggling with this off and on for months and have amassed hours of troubleshooting. Why is this so hard?
I did manage to get it working once after some troubleshooting:
- To make the mount points I was encountering some weird behavior between nfs and systemd-tmpfiles (and possible nu-shell?) which was generating these odd 0-byte “ghost files” which seemingly both existed and did not exist at the same time. If you ls’d them, it would either say “no such folder” or it would ls the file itself as if it wasn’t a directory… despite it saying it’s a directory. I just have to manually delete them.
- Either it defaults to nfs3 or the wiki is wrong because I needed more than just 2049 open.
- Way too late I realized I needed to run
exportfs -av
manually. This never even occurred to me as a possibility because I figured Nix would do that but who knows.
After all that it worked for a whole day before it just… stopped for some reason. So as of this moment I am here:
- Network is taken care of. Firewalls on client and host are completely open. I can see the server’s exports with
showmount -e
. I can see it’s open ports withrpcbind -p
.tcpinfo
shows no blocked packets. - File permissions for exports and mounts are 0777.
- I’ve tried a variety of different option mount and export options. Setting everything to NFS 4.2, noauto, insecure…
- The ghost files have reappeared! This time on the client. Not that it matters, because I can’t manually mount the exports to a working directory either.
Server
nix module
systemd.tmpfiles.rules = [
"d /srv/share 0777 root root"
];
services = {
nfs = {
server = {
enable = true;
};
};
rpcbind.enable = true; #dunno if I need this
}
services.nfs.server = {
exports = ''/srv/share *(rw,no_subtree_check)'';
}
sudo exportfs
/srv/share <world>
Client
nix module
systemd.tmpfiles.rules = [
"d /mnt/share 0777 root root"
];
environment.systemPackages = with pkgs; [ nfs-utils ];
boot.initrd = {
supportedFilesystems = [ "nfs" ];
kernelModules = [ "nfs" ];
};
fileSystems."/mnt/share" = {
device = "(ip address):/srv/share";
fsType = "nfs";
options = [
"x-systemd.automount"
"noauto"
"_netdev"
];
};
showmount -e (ip address)
Export list for (ip address):
/srv/share *
rpcinfo -p (ip address)
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 37473 status
100024 1 tcp 47917 status
100005 1 udp 20048 mountd
100005 1 tcp 20048 mountd
100005 2 udp 20048 mountd
100005 2 tcp 20048 mountd
100005 3 udp 20048 mountd
100005 3 tcp 20048 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100021 1 udp 39320 nlockmgr
100021 3 udp 39320 nlockmgr
100021 4 udp 39320 nlockmgr
100021 1 tcp 43025 nlockmgr
100021 3 tcp 43025 nlockmgr
100021 4 tcp 43025 nlockmgr
/etc/fstab
(ip address):/srv/share /mnt/share nfs x-systemd.automount,_netdev 0 0
nfsstat
> Server rpc stats:
> calls badcalls badfmt badauth badclnt
> 0 0 0 0 0
systemctl status mnt-share.automount
Set up automount mnt-share.automount.
mnt-share.automount: Got automount request for /mnt/share, triggered by 29668 (nu)
mnt-share.automount: Got automount request for /mnt/share, triggered by 2552 (nu)
mnt-share.automount: Got automount request for /mnt/share, triggered by 2552 (nu)
mnt-share.automount: Got automount request for /mnt/share, triggered by 2552 (nu)
mnt-share.automount: Got automount request for /mnt/share, triggered by 2552 (nu)
mnt-share.automount: Got automount request for /mnt/share, triggered by 2552 (nu)
mnt-share.automount: Failed with result 'mount-start-limit-hit'.
nixos-rebuild switch
Error: Failed to open unit file mnt-share.automount
Caused by: No such file or directory (os error 2)
warning: error(s) occurred while switching to the new configuration
Any attempt to mount the shares gives me mount.nfs: failed to prepare mount: No such device
. I honestly have no idea what is wrong, journalctl doesn’t really tell me anything. If I can see the exports from the server with showmount, why do I get “No such device”?? I feel like it’s something weird with portmapper or rpcbind that I am not smart enough to diagnose. Or maybe a race condition somewhere with systemd.tmpfiles.