2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-03-09 14:37:58 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2012-03-09 14:37:58 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
inInitrd = any (fs: fs == "nfs") config.boot.initrd.supportedFilesystems;
|
|
|
|
|
2012-03-21 11:58:06 +00:00
|
|
|
nfsStateDir = "/var/lib/nfs";
|
|
|
|
|
|
|
|
rpcMountpoint = "${nfsStateDir}/rpc_pipefs";
|
|
|
|
|
2012-05-09 22:06:17 +00:00
|
|
|
idmapdConfFile = pkgs.writeText "idmapd.conf" ''
|
|
|
|
[General]
|
|
|
|
Pipefs-Directory = ${rpcMountpoint}
|
2014-11-30 09:14:46 +00:00
|
|
|
${optionalString (config.networking.domain != null)
|
2012-05-09 22:06:17 +00:00
|
|
|
"Domain = ${config.networking.domain}"}
|
|
|
|
|
|
|
|
[Mapping]
|
|
|
|
Nobody-User = nobody
|
|
|
|
Nobody-Group = nogroup
|
|
|
|
|
|
|
|
[Translation]
|
|
|
|
Method = nsswitch
|
|
|
|
'';
|
2012-03-21 11:58:06 +00:00
|
|
|
|
2014-07-30 21:47:52 +00:00
|
|
|
cfg = config.services.nfs;
|
|
|
|
|
2012-03-09 14:37:58 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2014-07-30 21:47:52 +00:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.nfs = {
|
|
|
|
statdPort = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = 4000;
|
|
|
|
description = ''
|
2016-09-07 12:06:04 +00:00
|
|
|
Use a fixed port for <command>rpc.statd</command>. This is
|
|
|
|
useful if the NFS server is behind a firewall.
|
2014-07-30 21:47:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
lockdPort = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = 4001;
|
|
|
|
description = ''
|
2016-09-07 12:06:04 +00:00
|
|
|
Use a fixed port for the NFS lock manager kernel module
|
|
|
|
(<literal>lockd/nlockmgr</literal>). This is useful if the
|
|
|
|
NFS server is behind a firewall.
|
2014-07-30 21:47:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2012-03-09 14:37:58 +00:00
|
|
|
|
2012-03-16 20:41:49 +00:00
|
|
|
###### implementation
|
|
|
|
|
2014-09-16 08:51:05 +00:00
|
|
|
config = mkIf (any (fs: fs == "nfs" || fs == "nfs4") config.boot.supportedFilesystems) {
|
2012-03-16 20:41:49 +00:00
|
|
|
|
2012-03-21 20:37:37 +00:00
|
|
|
services.rpcbind.enable = true;
|
2012-10-24 16:10:58 +00:00
|
|
|
|
2014-12-06 15:40:57 +00:00
|
|
|
system.fsPackages = [ pkgs.nfs-utils ];
|
2012-03-09 14:37:58 +00:00
|
|
|
|
2014-09-16 08:51:05 +00:00
|
|
|
boot.extraModprobeConfig = mkIf (cfg.lockdPort != null) ''
|
|
|
|
options lockd nlm_udpport=${toString cfg.lockdPort} nlm_tcpport=${toString cfg.lockdPort}
|
|
|
|
'';
|
|
|
|
|
2012-03-22 13:01:06 +00:00
|
|
|
boot.kernelModules = [ "sunrpc" ];
|
|
|
|
|
2012-03-09 14:37:58 +00:00
|
|
|
boot.initrd.kernelModules = mkIf inInitrd [ "nfs" ];
|
|
|
|
|
2016-09-07 12:06:19 +00:00
|
|
|
# FIXME: should use upstream units from nfs-utils.
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
systemd.services.statd =
|
2012-10-24 16:10:58 +00:00
|
|
|
{ description = "NFSv3 Network Status Monitor";
|
2012-03-16 20:41:49 +00:00
|
|
|
|
2014-12-06 15:40:57 +00:00
|
|
|
path = [ pkgs.nfs-utils pkgs.sysvtools pkgs.utillinux ];
|
2012-03-16 20:41:49 +00:00
|
|
|
|
2016-09-07 12:06:19 +00:00
|
|
|
wants = [ "remote-fs-pre.target" ];
|
2014-12-02 01:17:46 +00:00
|
|
|
before = [ "remote-fs-pre.target" ];
|
2016-09-07 12:06:19 +00:00
|
|
|
wantedBy = [ "remote-fs.target" ];
|
2012-10-24 16:10:58 +00:00
|
|
|
requires = [ "basic.target" "rpcbind.service" ];
|
2014-12-02 01:17:46 +00:00
|
|
|
after = [ "basic.target" "rpcbind.service" ];
|
2012-10-24 16:10:58 +00:00
|
|
|
|
|
|
|
unitConfig.DefaultDependencies = false; # don't stop during shutdown
|
2012-03-16 20:41:49 +00:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
2012-03-21 11:58:06 +00:00
|
|
|
mkdir -p ${nfsStateDir}/sm
|
|
|
|
mkdir -p ${nfsStateDir}/sm.bak
|
2012-03-16 20:41:49 +00:00
|
|
|
sm-notify -d
|
|
|
|
'';
|
|
|
|
|
2012-10-24 16:10:58 +00:00
|
|
|
serviceConfig.Type = "forking";
|
2014-07-30 21:47:52 +00:00
|
|
|
serviceConfig.ExecStart = ''
|
2014-12-06 15:40:57 +00:00
|
|
|
@${pkgs.nfs-utils}/sbin/rpc.statd rpc.statd --no-notify \
|
2015-10-14 00:48:34 +00:00
|
|
|
${if cfg.statdPort != null then "-p ${toString cfg.statdPort}" else ""}
|
2014-07-30 21:47:52 +00:00
|
|
|
'';
|
2012-10-24 16:10:58 +00:00
|
|
|
serviceConfig.Restart = "always";
|
2012-03-16 20:41:49 +00:00
|
|
|
};
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
systemd.services.idmapd =
|
2012-10-24 16:10:58 +00:00
|
|
|
{ description = "NFSv4 ID Mapping Daemon";
|
2012-03-21 11:58:06 +00:00
|
|
|
|
2012-10-24 16:10:58 +00:00
|
|
|
path = [ pkgs.sysvtools pkgs.utillinux ];
|
2012-03-21 11:58:06 +00:00
|
|
|
|
2016-09-07 12:06:19 +00:00
|
|
|
wants = [ "remote-fs-pre.target" ];
|
2014-12-02 01:17:46 +00:00
|
|
|
before = [ "remote-fs-pre.target" ];
|
2016-09-07 12:06:19 +00:00
|
|
|
wantedBy = [ "remote-fs.target" ];
|
2012-10-24 16:10:58 +00:00
|
|
|
requires = [ "rpcbind.service" ];
|
|
|
|
after = [ "rpcbind.service" ];
|
2012-03-21 11:58:06 +00:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p ${rpcMountpoint}
|
|
|
|
mount -t rpc_pipefs rpc_pipefs ${rpcMountpoint}
|
|
|
|
'';
|
|
|
|
|
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
umount ${rpcMountpoint}
|
|
|
|
'';
|
|
|
|
|
2012-10-24 16:10:58 +00:00
|
|
|
serviceConfig.Type = "forking";
|
2014-12-06 15:40:57 +00:00
|
|
|
serviceConfig.ExecStart = "@${pkgs.nfs-utils}/sbin/rpc.idmapd rpc.idmapd -c ${idmapdConfFile}";
|
2012-10-24 16:10:58 +00:00
|
|
|
serviceConfig.Restart = "always";
|
2012-03-21 11:58:06 +00:00
|
|
|
};
|
|
|
|
|
2014-09-16 08:51:05 +00:00
|
|
|
};
|
2012-03-09 14:37:58 +00:00
|
|
|
}
|