2014-04-14 18:26:48 +04:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-03-09 18:37:58 +04:00
|
|
|
|
2014-04-14 18:26:48 +04:00
|
|
|
with lib;
|
2012-03-09 18:37:58 +04:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
inInitrd = any (fs: fs == "nfs") config.boot.initrd.supportedFilesystems;
|
|
|
|
|
2012-03-21 15:58:06 +04:00
|
|
|
nfsStateDir = "/var/lib/nfs";
|
|
|
|
|
|
|
|
rpcMountpoint = "${nfsStateDir}/rpc_pipefs";
|
|
|
|
|
2012-05-10 02:06:17 +04:00
|
|
|
idmapdConfFile = pkgs.writeText "idmapd.conf" ''
|
|
|
|
[General]
|
|
|
|
Pipefs-Directory = ${rpcMountpoint}
|
|
|
|
${optionalString (config.networking.domain != "")
|
|
|
|
"Domain = ${config.networking.domain}"}
|
|
|
|
|
|
|
|
[Mapping]
|
|
|
|
Nobody-User = nobody
|
|
|
|
Nobody-Group = nogroup
|
|
|
|
|
|
|
|
[Translation]
|
|
|
|
Method = nsswitch
|
|
|
|
'';
|
2012-03-21 15:58:06 +04:00
|
|
|
|
2012-03-09 18:37:58 +04:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2012-03-17 00:41:49 +04:00
|
|
|
###### implementation
|
|
|
|
|
2012-03-22 16:24:23 +04:00
|
|
|
config = mkIf (any (fs: fs == "nfs" || fs == "nfs4") config.boot.supportedFilesystems) {
|
2012-03-17 00:41:49 +04:00
|
|
|
|
2012-03-22 00:37:37 +04:00
|
|
|
services.rpcbind.enable = true;
|
2012-10-24 20:10:58 +04:00
|
|
|
|
2012-03-09 18:37:58 +04:00
|
|
|
system.fsPackages = [ pkgs.nfsUtils ];
|
|
|
|
|
2012-03-22 17:01:06 +04:00
|
|
|
boot.kernelModules = [ "sunrpc" ];
|
|
|
|
|
2012-03-09 18:37:58 +04:00
|
|
|
boot.initrd.kernelModules = mkIf inInitrd [ "nfs" ];
|
|
|
|
|
2013-01-16 15:33:18 +04:00
|
|
|
systemd.services.statd =
|
2012-10-24 20:10:58 +04:00
|
|
|
{ description = "NFSv3 Network Status Monitor";
|
2012-03-17 00:41:49 +04:00
|
|
|
|
|
|
|
path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ];
|
|
|
|
|
2013-07-16 13:55:12 +04:00
|
|
|
wantedBy = [ "network-online.target" "multi-user.target" ];
|
|
|
|
before = [ "network-online.target" ];
|
2012-10-24 20:10:58 +04:00
|
|
|
requires = [ "basic.target" "rpcbind.service" ];
|
|
|
|
after = [ "basic.target" "rpcbind.service" "network.target" ];
|
|
|
|
|
|
|
|
unitConfig.DefaultDependencies = false; # don't stop during shutdown
|
2012-03-17 00:41:49 +04:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
2012-03-21 15:58:06 +04:00
|
|
|
mkdir -p ${nfsStateDir}/sm
|
|
|
|
mkdir -p ${nfsStateDir}/sm.bak
|
2012-03-17 00:41:49 +04:00
|
|
|
sm-notify -d
|
|
|
|
'';
|
|
|
|
|
2012-10-24 20:10:58 +04:00
|
|
|
serviceConfig.Type = "forking";
|
|
|
|
serviceConfig.ExecStart = "@${pkgs.nfsUtils}/sbin/rpc.statd rpc.statd --no-notify";
|
|
|
|
serviceConfig.Restart = "always";
|
2012-03-17 00:41:49 +04:00
|
|
|
};
|
|
|
|
|
2013-01-16 15:33:18 +04:00
|
|
|
systemd.services.idmapd =
|
2012-10-24 20:10:58 +04:00
|
|
|
{ description = "NFSv4 ID Mapping Daemon";
|
2012-03-21 15:58:06 +04:00
|
|
|
|
2012-10-24 20:10:58 +04:00
|
|
|
path = [ pkgs.sysvtools pkgs.utillinux ];
|
2012-03-21 15:58:06 +04:00
|
|
|
|
2013-07-16 13:55:12 +04:00
|
|
|
wantedBy = [ "network-online.target" "multi-user.target" ];
|
|
|
|
before = [ "network-online.target" ];
|
2012-10-24 20:10:58 +04:00
|
|
|
requires = [ "rpcbind.service" ];
|
|
|
|
after = [ "rpcbind.service" ];
|
2012-03-21 15:58:06 +04:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p ${rpcMountpoint}
|
|
|
|
mount -t rpc_pipefs rpc_pipefs ${rpcMountpoint}
|
|
|
|
'';
|
|
|
|
|
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
umount ${rpcMountpoint}
|
|
|
|
'';
|
|
|
|
|
2012-10-24 20:10:58 +04:00
|
|
|
serviceConfig.Type = "forking";
|
|
|
|
serviceConfig.ExecStart = "@${pkgs.nfsUtils}/sbin/rpc.idmapd rpc.idmapd -c ${idmapdConfFile}";
|
|
|
|
serviceConfig.Restart = "always";
|
2012-03-21 15:58:06 +04:00
|
|
|
};
|
|
|
|
|
2012-03-09 18:37:58 +04:00
|
|
|
};
|
|
|
|
}
|