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