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
|
|
|
|
2017-01-29 18:11:50 +00:00
|
|
|
nfsConfFile = pkgs.writeText "nfs.conf" cfg.extraConfig;
|
2019-11-27 21:01:34 +00:00
|
|
|
requestKeyConfFile = pkgs.writeText "request-key.conf" ''
|
|
|
|
create id_resolver * * ${pkgs.nfs-utils}/bin/nfsidmap -t 600 %k %d
|
|
|
|
'';
|
2017-01-29 18:11:50 +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 = {
|
2017-01-29 18:11:50 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2014-07-30 21:47:52 +00:00
|
|
|
description = ''
|
2017-01-29 18:11:50 +00:00
|
|
|
Extra nfs-utils configuration.
|
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
|
|
|
|
|
|
|
boot.initrd.kernelModules = mkIf inInitrd [ "nfs" ];
|
|
|
|
|
2017-01-29 18:11:50 +00:00
|
|
|
systemd.packages = [ pkgs.nfs-utils ];
|
2012-03-16 20:41:49 +00:00
|
|
|
|
2019-11-27 21:01:34 +00:00
|
|
|
environment.systemPackages = [ pkgs.keyutils ];
|
|
|
|
|
2017-01-29 18:11:50 +00:00
|
|
|
environment.etc = {
|
|
|
|
"idmapd.conf".source = idmapdConfFile;
|
|
|
|
"nfs.conf".source = nfsConfFile;
|
2019-11-27 21:01:34 +00:00
|
|
|
"request-key.conf".source = requestKeyConfFile;
|
2017-01-29 18:11:50 +00:00
|
|
|
};
|
2012-03-16 20:41:49 +00:00
|
|
|
|
2017-01-29 18:11:50 +00:00
|
|
|
systemd.services.nfs-blkmap =
|
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
2012-03-16 20:41:49 +00:00
|
|
|
};
|
|
|
|
|
2017-01-29 18:11:50 +00:00
|
|
|
systemd.targets.nfs-client =
|
|
|
|
{ wantedBy = [ "multi-user.target" "remote-fs.target" ];
|
|
|
|
};
|
2012-03-21 11:58:06 +00:00
|
|
|
|
2017-01-29 18:11:50 +00:00
|
|
|
systemd.services.nfs-idmapd =
|
|
|
|
{ restartTriggers = [ idmapdConfFile ];
|
|
|
|
};
|
2012-03-21 11:58:06 +00:00
|
|
|
|
2017-01-29 18:11:50 +00:00
|
|
|
systemd.services.nfs-mountd =
|
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
|
|
|
enable = mkDefault false;
|
|
|
|
};
|
2012-03-21 11:58:06 +00:00
|
|
|
|
2017-01-29 18:11:50 +00:00
|
|
|
systemd.services.nfs-server =
|
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
|
|
|
enable = mkDefault false;
|
|
|
|
};
|
2012-03-21 11:58:06 +00:00
|
|
|
|
2017-09-18 09:42:40 +00:00
|
|
|
systemd.services.auth-rpcgss-module =
|
|
|
|
{
|
|
|
|
unitConfig.ConditionPathExists = [ "" "/etc/krb5.keytab" ];
|
|
|
|
};
|
|
|
|
|
2017-01-29 18:11:50 +00:00
|
|
|
systemd.services.rpc-gssd =
|
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
2017-09-18 09:42:40 +00:00
|
|
|
unitConfig.ConditionPathExists = [ "" "/etc/krb5.keytab" ];
|
2017-01-29 18:11:50 +00:00
|
|
|
};
|
2012-03-21 11:58:06 +00:00
|
|
|
|
2017-01-29 18:11:50 +00:00
|
|
|
systemd.services.rpc-statd =
|
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
2017-02-04 23:10:57 +00:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p /var/lib/nfs/{sm,sm.bak}
|
|
|
|
'';
|
2012-03-21 11:58:06 +00:00
|
|
|
};
|
|
|
|
|
2014-09-16 08:51:05 +00:00
|
|
|
};
|
2012-03-09 14:37:58 +00:00
|
|
|
}
|