1 { config, lib, pkgs, ... }:
4 cfg = config.services.nfs.server;
6 exports = pkgs.writeText "exports" cfg.exports;
12 (lib.mkRenamedOptionModule [ "services" "nfs" "lockdPort" ] [ "services" "nfs" "server" "lockdPort" ])
13 (lib.mkRenamedOptionModule [ "services" "nfs" "statdPort" ] [ "services" "nfs" "server" "statdPort" ])
23 enable = lib.mkOption {
24 type = lib.types.bool;
27 Whether to enable the kernel's NFS server.
31 extraNfsdConfig = lib.mkOption {
35 Extra configuration options for the [nfsd] section of /etc/nfs.conf.
39 exports = lib.mkOption {
40 type = lib.types.lines;
43 Contents of the /etc/exports file. See
44 {manpage}`exports(5)` for the format.
48 hostName = lib.mkOption {
49 type = lib.types.nullOr lib.types.str;
52 Hostname or address on which NFS requests will be accepted.
53 Default is all. See the {option}`-H` option in
58 nproc = lib.mkOption {
62 Number of NFS server threads. Defaults to the recommended value of 8.
66 createMountPoints = lib.mkOption {
67 type = lib.types.bool;
69 description = "Whether to create the mount points in the exports file at startup time.";
72 mountdPort = lib.mkOption {
73 type = lib.types.nullOr lib.types.int;
77 Use fixed port for rpc.mountd, useful if server is behind firewall.
81 lockdPort = lib.mkOption {
82 type = lib.types.nullOr lib.types.int;
86 Use a fixed port for the NFS lock manager kernel module
87 (`lockd/nlockmgr`). This is useful if the
88 NFS server is behind a firewall.
92 statdPort = lib.mkOption {
93 type = lib.types.nullOr lib.types.int;
97 Use a fixed port for {command}`rpc.statd`. This is
98 useful if the NFS server is behind a firewall.
109 ###### implementation
111 config = lib.mkIf cfg.enable {
113 services.rpcbind.enable = true;
115 boot.supportedFilesystems = [ "nfs" ]; # needed for statd and idmapd
117 environment.etc.exports.source = exports;
119 systemd.services.nfs-server =
121 wantedBy = [ "multi-user.target" ];
125 mkdir -p /var/lib/nfs/v4recovery
129 systemd.services.nfs-mountd =
131 restartTriggers = [ exports ];
135 mkdir -p /var/lib/nfs
137 ${lib.optionalString cfg.createMountPoints
139 # create export directories:
140 # skip comments, take first col which may either be a quoted
141 # "foo bar" or just foo (-> man export)
142 sed '/^#.*/d;s/^"\([^"]*\)".*/\1/;t;s/[ ].*//' ${exports} \
143 | xargs -d '\n' mkdir -p