2012-03-09 15:37:58 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
idmapdConfFile = {
|
|
|
|
target = "idmapd.conf";
|
|
|
|
source = 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-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-03-16 21:41:49 +01: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" ];
|
|
|
|
|
|
|
|
boot.initrd.extraUtilsCommands = mkIf inInitrd
|
|
|
|
''
|
|
|
|
# !!! Uh, why don't we just install mount.nfs?
|
|
|
|
cp -v ${pkgs.klibc}/lib/klibc/bin.static/nfsmount $out/bin
|
|
|
|
'';
|
|
|
|
|
2012-03-21 12:58:06 +01:00
|
|
|
environment.etc = singleton idmapdConfFile;
|
|
|
|
|
2012-03-22 13:24:23 +01:00
|
|
|
# Ensure that statd and idmapd are started before mountall.
|
|
|
|
jobs.mountall.preStart =
|
|
|
|
''
|
|
|
|
ensure statd || true
|
|
|
|
ensure idmapd || true
|
|
|
|
'';
|
|
|
|
|
2012-03-16 21:41:49 +01:00
|
|
|
jobs.statd =
|
|
|
|
{ description = "Kernel NFS server - Network Status Monitor";
|
|
|
|
|
|
|
|
path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ];
|
|
|
|
|
2012-03-17 19:00:20 +01:00
|
|
|
stopOn = ""; # needed during shutdown
|
2012-03-16 21:41:49 +01:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
2012-03-21 21:37:37 +01:00
|
|
|
ensure rpcbind
|
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
|
|
|
|
'';
|
|
|
|
|
|
|
|
daemonType = "fork";
|
|
|
|
|
|
|
|
exec = "rpc.statd --no-notify";
|
|
|
|
};
|
|
|
|
|
2012-03-21 12:58:06 +01:00
|
|
|
jobs.idmapd =
|
2012-03-22 14:01:06 +01:00
|
|
|
{ description = "NFS ID mapping daemon";
|
2012-03-21 12:58:06 +01:00
|
|
|
|
|
|
|
path = [ pkgs.nfsUtils pkgs.sysvtools pkgs.utillinux ];
|
|
|
|
|
2012-03-22 14:01:06 +01:00
|
|
|
startOn = "started udev";
|
2012-03-21 12:58:06 +01:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
2012-03-21 21:37:37 +01:00
|
|
|
ensure rpcbind
|
2012-03-21 12:58:06 +01:00
|
|
|
mkdir -p ${rpcMountpoint}
|
|
|
|
mount -t rpc_pipefs rpc_pipefs ${rpcMountpoint}
|
|
|
|
'';
|
|
|
|
|
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
umount ${rpcMountpoint}
|
|
|
|
'';
|
|
|
|
|
|
|
|
daemonType = "fork";
|
|
|
|
|
|
|
|
exec = "rpc.idmapd";
|
|
|
|
};
|
|
|
|
|
2012-03-09 15:37:58 +01:00
|
|
|
};
|
|
|
|
}
|