2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-03-09 14:37:58 +00:00
|
|
|
|
2014-04-14 15:26:48 +01: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";
|
|
|
|
|
2020-10-21 02:21:37 +01:00
|
|
|
format = pkgs.formats.ini {};
|
2012-03-21 11:58:06 +00:00
|
|
|
|
2020-10-21 02:21:37 +01:00
|
|
|
idmapdConfFile = format.generate "idmapd.conf" cfg.idmapd.settings;
|
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 22:47:52 +01:00
|
|
|
cfg = config.services.nfs;
|
|
|
|
|
2012-03-09 14:37:58 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2014-07-30 22:47:52 +01:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.nfs = {
|
2020-10-21 02:21:37 +01:00
|
|
|
idmapd.settings = mkOption {
|
|
|
|
type = format.type;
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
libnfsidmap configuration. Refer to
|
|
|
|
<link xlink:href="https://linux.die.net/man/5/idmapd.conf"/>
|
|
|
|
for details.
|
|
|
|
'';
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
Translation = {
|
|
|
|
GSS-Methods = "static,nsswitch";
|
|
|
|
};
|
|
|
|
Static = {
|
|
|
|
"root/hostname.domain.com@REALM.COM" = "root";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2017-01-29 18:11:50 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2014-07-30 22:47:52 +01:00
|
|
|
description = ''
|
2017-01-29 18:11:50 +00:00
|
|
|
Extra nfs-utils configuration.
|
2014-07-30 22:47:52 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2012-03-09 14:37:58 +00:00
|
|
|
|
2012-03-16 20:41:49 +00:00
|
|
|
###### implementation
|
|
|
|
|
2014-09-16 09:51:05 +01: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
|
|
|
|
2020-10-21 02:21:37 +01:00
|
|
|
services.nfs.idmapd.settings = {
|
|
|
|
General = mkMerge [
|
|
|
|
{ Pipefs-Directory = rpcMountpoint; }
|
|
|
|
(mkIf (config.networking.domain != null) { Domain = config.networking.domain; })
|
|
|
|
];
|
|
|
|
Mapping = {
|
|
|
|
Nobody-User = "nobody";
|
|
|
|
Nobody-Group = "nogroup";
|
|
|
|
};
|
|
|
|
Translation = {
|
|
|
|
Method = "nsswitch";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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 10:42:40 +01: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 10:42:40 +01: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 =
|
2020-09-10 20:22:01 +01:00
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p /var/lib/nfs/{sm,sm.bak}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-09-16 09:51:05 +01:00
|
|
|
};
|
2012-03-09 14:37:58 +00:00
|
|
|
}
|