nixos nfs

Date: 2024-10-12

modDate: 2024-10-12

tags: nixos nfs openbsd

I migrated from FreeBSD to NixOS for my nas. Apparently I never tested/used NFS on the new OS. When I went to mount my music share from my OpenBSD client I received the following error.

NFS Portmap: RPC: Program not registered

I followed this guide to add NFS to the NixOS config.

NixOS NFS WIki

That partially worked. I could use the local client in the example to connect and an Arch Linux client could connect. But my OpenBSD client would not connect.

After some (ok a lot) of searching I stumbled upon this guide, which suggested to run the below rpcinfo commands.

https://misc.openbsd.narkive.com/WSgxZV17/nfs-protocol-not-supported-when-mounting-from-a-linux-machine

rpcinfo -t hostname mountd
rpcinfo -u hostname mountd
rpcinfo -t hostname nfs
rpcinfo -u hostname nfs

When I got to this one it became obvious what was really going on.

rpcinfo -u nas nfs
rpcinfo: RPC: Program not registered
program 100003 is not available

It turns out that OpenBSD defaults to using UDP for NFS and Linux defaults to TCP. When I had ran my rpcinfo command I didn’t notice that there was a UDP entry missing for the NFS service.

rpcinfo -p nas
   program vers proto   port
    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   4000  status
    100024    1   tcp   4000  status
    100005    1   udp   4002  mountd
    100005    1   tcp   4002  mountd
    100005    2   udp   4002  mountd
    100005    2   tcp   4002  mountd
    100005    3   udp   4002  mountd
    100005    3   tcp   4002  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049
    100021    1   udp   4001  nlockmgr
    100021    3   udp   4001  nlockmgr
    100021    4   udp   4001  nlockmgr
    100021    1   tcp   4001  nlockmgr
    100021    3   tcp   4001  nlockmgr
    100021    4   tcp   4001  nlockmgr

showmount -e nas
Exports list on nas:
export                            192.168.88.0/24
export/music                      192.168.88.0/24

I tried mount_nfs with the -T option to specify using TCP and it worked!

mount_nfs -T nas:/export/music /mnt/nas-media

I then hunted around for the flag for NixOS to add a UDP service for NFS. You need to add udp=y. The below is the NFS config for my NixOS.

services = {
  nfs = {
    server.enable = true;
    server.exports = ''
      /export          192.168.88.0/24(rw,fsid=0,no_subtree_check)
      /export/music    192.168.88.0/24(rw,nohide,insecure,no_subtree_check)
    '';
    # for nvsv3
    # fixed rpc.statd port; for firewall
    server.statdPort  = 4000;
    server.lockdPort  = 4001;
    server.mountdPort = 4002;
    server.extraNfsdConfig = ''udp=y'';
  }:
}:

After upgrading to nixos 24.05 services.nfs.server.extraNfsConfig was deprecated. You now use services.nfs.settings. That config would like the below.

services = {
  nfs = {
    server.enable = true;
    server.exports = ''
      /export          192.168.88.0/24(rw,fsid=0,no_subtree_check)
      /export/music    192.168.88.0/24(rw,nohide,insecure,no_subtree_check)
    '';
    # for nvsv3
    # fixed rpc.statd port; for firewall
    server.statdPort  = 4000;
    server.lockdPort  = 4001;
    server.mountdPort = 4002;
    settings = {
      nfsd.udp = true;
    };
  }:
}:

# Open ports in the firewall.
networking.firewall.enable = true;
networking.firewall.allowedTCPPorts = [ 111 2049 4000 4001 4002 20048 ];
networking.firewall.allowedUDPPorts = [ 111 2049 4000 4001 4002 20048 ];

Now rpcinfo shows:

rpcinfo -p nas
   program vers proto   port
    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
    100005    1   udp   4002  mountd
    100005    1   tcp   4002  mountd
    100005    2   udp   4002  mountd
    100005    2   tcp   4002  mountd
    100005    3   udp   4002  mountd
    100005    3   tcp   4002  mountd
    100024    1   udp   4000  status
    100024    1   tcp   4000  status
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049
    100003    3   udp   2049  nfs
    100227    3   udp   2049
    100021    1   udp   4001  nlockmgr
    100021    3   udp   4001  nlockmgr
    100021    4   udp   4001  nlockmgr
    100021    1   tcp   4001  nlockmgr
    100021    3   tcp   4001  nlockmgr
    100021    4   tcp   4001  nlockmgr

Also NixOS supports NFS versions 3 through 4.2 and OpenBSD supports versions 2 and 3. However both OSs do successfully negotiate to use version 3.