How do I setup automounting user home from nfs host?

I am trying to setup a NixOS PC as NFS client,
but I can’t find anything on how to achieve an automatic user specific mounting of the home directory.

Can someone please recommend a tutorial?
Or packages or services that can help?
I only mangae to find Linux tutorials or general mounting tutorials.

systemd-homed is all about this kind of setup, see the CIFS heading: Home Directories

You can also probably do it differently, but most use cases for having a user’s full homedir on networked storage are going to be the type of thing systemd-homed is trying to do.

1 Like

Here an example for all the people who also want/have to use autofs:

/etc/nixos/handleautofs.nix:

# /etc/nixos/handleautofs.nix
{ config, pkgs, … }:

{

services.autofs = {
enable = true;
autoMaster = ‘’
/home /etc/auto.home --timeout=180
‘’;
};

environment.etc.“auto.home”.text = ‘’
* -fstype=nfs,rw,soft,intr SERVERADDRESS:/export/home/& # Don't forget to replace SERVERADDRESS with the address (or a variable that contains it).
‘’;

}

I hope this will help.

Little, but important correction:

The setting

boot.supportedFilesystems = [ “nfs” ];

is also required. (I forgot it in the configuration.nix after previous experiments.)

So the complete /etc/nixos/handleautofs.nix looks like this:

{ config, pkgs, ... }:

{
  # Ensures rpc-statsd is running for on demand mounting
  boot.supportedFilesystems = [ "nfs" ];

  services.autofs = {
    enable = true;
    autoMaster = ''
      /home /etc/auto.home --timeout=180
    '';
  };

  environment.etc."auto.home".text = ''
    * -fstype=nfs,rw,soft,intr SERVERADDRESS:/export/home/& # Don't forget to replace SERVERADDRESS with the address (or a variable that contains it).
  '';

}

Other configurations like

networking.firewall.allowedTCPPorts = [ 2049 ];

and

services.rpcbind.enable = true;

don’t seem to be necessary, because everything still worked fine after removing them.