2012-03-09 14:37:58 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
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 23:06:17 +01: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 11:58:06 +00:00
|
|
|
|
2012-03-09 14:37:58 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2012-03-16 20:41:49 +00:00
|
|
|
###### implementation
|
|
|
|
|
2012-03-22 12:24:23 +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 17:10:58 +01:00
|
|
|
|
2012-03-09 14:37:58 +00:00
|
|
|
system.fsPackages = [ pkgs.nfsUtils ];
|
|
|
|
|
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" ];
|
|
|
|
|
2012-10-24 17:10:58 +01:00
|
|
|
boot.systemd.services.statd =
|
|
|
|
{ description = "NFSv3 Network Status Monitor";
|
2012-03-16 20:41:49 +00:00
|
|
|
|
|
|
|
path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ];
|
|
|
|
|
2012-10-24 17:10:58 +01:00
|
|
|
wantedBy = [ "remote-fs-pre.target" "multi-user.target" ];
|
|
|
|
before = [ "remote-fs-pre.target" ];
|
|
|
|
requires = [ "basic.target" "rpcbind.service" ];
|
|
|
|
after = [ "basic.target" "rpcbind.service" "network.target" ];
|
|
|
|
|
|
|
|
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 17:10:58 +01:00
|
|
|
serviceConfig.Type = "forking";
|
|
|
|
serviceConfig.ExecStart = "@${pkgs.nfsUtils}/sbin/rpc.statd rpc.statd --no-notify";
|
|
|
|
serviceConfig.Restart = "always";
|
2012-03-16 20:41:49 +00:00
|
|
|
};
|
|
|
|
|
2012-10-24 17:10:58 +01:00
|
|
|
boot.systemd.services.idmapd =
|
|
|
|
{ description = "NFSv4 ID Mapping Daemon";
|
2012-03-21 11:58:06 +00:00
|
|
|
|
2012-10-24 17:10:58 +01:00
|
|
|
path = [ pkgs.sysvtools pkgs.utillinux ];
|
2012-03-21 11:58:06 +00:00
|
|
|
|
2012-10-24 17:10:58 +01:00
|
|
|
wantedBy = [ "remote-fs-pre.target" "multi-user.target" ];
|
|
|
|
before = [ "remote-fs-pre.target" ];
|
|
|
|
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 17:10:58 +01:00
|
|
|
serviceConfig.Type = "forking";
|
|
|
|
serviceConfig.ExecStart = "@${pkgs.nfsUtils}/sbin/rpc.idmapd rpc.idmapd -c ${idmapdConfFile}";
|
|
|
|
serviceConfig.Restart = "always";
|
2012-03-21 11:58:06 +00:00
|
|
|
};
|
|
|
|
|
2012-03-09 14:37:58 +00:00
|
|
|
};
|
|
|
|
}
|