1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 inInitrd = any (fs: fs == "nfs") config.boot.initrd.supportedFilesystems;
8
9 nfsStateDir = "/var/lib/nfs";
10
11 rpcMountpoint = "${nfsStateDir}/rpc_pipefs";
12
13 idmapdConfFile = pkgs.writeText "idmapd.conf" ''
14 [General]
15 Pipefs-Directory = ${rpcMountpoint}
16 ${optionalString (config.networking.domain != null)
17 "Domain = ${config.networking.domain}"}
18
19 [Mapping]
20 Nobody-User = nobody
21 Nobody-Group = nogroup
22
23 [Translation]
24 Method = nsswitch
25 '';
26
27 nfsConfFile = pkgs.writeText "nfs.conf" cfg.extraConfig;
28
29 cfg = config.services.nfs;
30
31in
32
33{
34 ###### interface
35
36 options = {
37 services.nfs = {
38 extraConfig = mkOption {
39 type = types.lines;
40 default = "";
41 description = ''
42 Extra nfs-utils configuration.
43 '';
44 };
45 };
46 };
47
48 ###### implementation
49
50 config = mkIf (any (fs: fs == "nfs" || fs == "nfs4") config.boot.supportedFilesystems) {
51
52 services.rpcbind.enable = true;
53
54 system.fsPackages = [ pkgs.nfs-utils ];
55
56 boot.initrd.kernelModules = mkIf inInitrd [ "nfs" ];
57
58 systemd.packages = [ pkgs.nfs-utils ];
59 systemd.generator-packages = [ pkgs.nfs-utils ];
60
61 environment.etc = {
62 "idmapd.conf".source = idmapdConfFile;
63 "nfs.conf".source = nfsConfFile;
64 };
65
66 systemd.services.nfs-blkmap =
67 { restartTriggers = [ nfsConfFile ];
68 };
69
70 systemd.targets.nfs-client =
71 { wantedBy = [ "multi-user.target" "remote-fs.target" ];
72 };
73
74 systemd.services.nfs-idmapd =
75 { restartTriggers = [ idmapdConfFile ];
76 };
77
78 systemd.services.nfs-mountd =
79 { restartTriggers = [ nfsConfFile ];
80 enable = mkDefault false;
81 };
82
83 systemd.services.nfs-server =
84 { restartTriggers = [ nfsConfFile ];
85 enable = mkDefault false;
86 };
87
88 systemd.services.auth-rpcgss-module =
89 {
90 unitConfig.ConditionPathExists = [ "" "/etc/krb5.keytab" ];
91 };
92
93 systemd.services.rpc-gssd =
94 { restartTriggers = [ nfsConfFile ];
95 unitConfig.ConditionPathExists = [ "" "/etc/krb5.keytab" ];
96 };
97
98 systemd.services.rpc-statd =
99 { restartTriggers = [ nfsConfFile ];
100
101 preStart =
102 ''
103 mkdir -p /var/lib/nfs/{sm,sm.bak}
104 '';
105 };
106
107 };
108}