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";
|
|
|
|
|
2020-10-21 03:21:37 +02:00
|
|
|
format = pkgs.formats.ini {};
|
2012-03-21 12:58:06 +01:00
|
|
|
|
2020-10-21 03:21:37 +02:00
|
|
|
idmapdConfFile = format.generate "idmapd.conf" cfg.idmapd.settings;
|
2017-01-29 19:11:50 +01:00
|
|
|
nfsConfFile = pkgs.writeText "nfs.conf" cfg.extraConfig;
|
2019-11-27 22:01:34 +01:00
|
|
|
requestKeyConfFile = pkgs.writeText "request-key.conf" ''
|
|
|
|
create id_resolver * * ${pkgs.nfs-utils}/bin/nfsidmap -t 600 %k %d
|
|
|
|
'';
|
2017-01-29 19:11:50 +01:00
|
|
|
|
2014-07-30 23:47:52 +02:00
|
|
|
cfg = config.services.nfs;
|
|
|
|
|
2012-03-09 15:37:58 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2014-07-30 23:47:52 +02:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.nfs = {
|
2020-10-21 03:21:37 +02: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.
|
|
|
|
'';
|
2021-10-03 18:06:03 +02:00
|
|
|
example = literalExpression ''
|
2020-10-21 03:21:37 +02:00
|
|
|
{
|
|
|
|
Translation = {
|
|
|
|
GSS-Methods = "static,nsswitch";
|
|
|
|
};
|
|
|
|
Static = {
|
|
|
|
"root/hostname.domain.com@REALM.COM" = "root";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2017-01-29 19:11:50 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2014-07-30 23:47:52 +02:00
|
|
|
description = ''
|
2017-01-29 19:11:50 +01:00
|
|
|
Extra nfs-utils configuration.
|
2014-07-30 23:47:52 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2012-03-09 15:37:58 +01:00
|
|
|
|
2012-03-16 21:41:49 +01:00
|
|
|
###### implementation
|
|
|
|
|
2014-09-16 10:51:05 +02: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
|
|
|
|
2020-10-21 03:21:37 +02: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 16:40:57 +01:00
|
|
|
system.fsPackages = [ pkgs.nfs-utils ];
|
2012-03-09 15:37:58 +01:00
|
|
|
|
|
|
|
boot.initrd.kernelModules = mkIf inInitrd [ "nfs" ];
|
|
|
|
|
2017-01-29 19:11:50 +01:00
|
|
|
systemd.packages = [ pkgs.nfs-utils ];
|
2012-03-16 21:41:49 +01:00
|
|
|
|
2019-11-27 22:01:34 +01:00
|
|
|
environment.systemPackages = [ pkgs.keyutils ];
|
|
|
|
|
2017-01-29 19:11:50 +01:00
|
|
|
environment.etc = {
|
|
|
|
"idmapd.conf".source = idmapdConfFile;
|
|
|
|
"nfs.conf".source = nfsConfFile;
|
2019-11-27 22:01:34 +01:00
|
|
|
"request-key.conf".source = requestKeyConfFile;
|
2017-01-29 19:11:50 +01:00
|
|
|
};
|
2012-03-16 21:41:49 +01:00
|
|
|
|
2017-01-29 19:11:50 +01:00
|
|
|
systemd.services.nfs-blkmap =
|
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
2012-03-16 21:41:49 +01:00
|
|
|
};
|
|
|
|
|
2017-01-29 19:11:50 +01:00
|
|
|
systemd.targets.nfs-client =
|
|
|
|
{ wantedBy = [ "multi-user.target" "remote-fs.target" ];
|
|
|
|
};
|
2012-03-21 12:58:06 +01:00
|
|
|
|
2017-01-29 19:11:50 +01:00
|
|
|
systemd.services.nfs-idmapd =
|
|
|
|
{ restartTriggers = [ idmapdConfFile ];
|
|
|
|
};
|
2012-03-21 12:58:06 +01:00
|
|
|
|
2017-01-29 19:11:50 +01:00
|
|
|
systemd.services.nfs-mountd =
|
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
|
|
|
enable = mkDefault false;
|
|
|
|
};
|
2012-03-21 12:58:06 +01:00
|
|
|
|
2017-01-29 19:11:50 +01:00
|
|
|
systemd.services.nfs-server =
|
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
|
|
|
enable = mkDefault false;
|
|
|
|
};
|
2012-03-21 12:58:06 +01:00
|
|
|
|
2017-09-18 11:42:40 +02:00
|
|
|
systemd.services.auth-rpcgss-module =
|
|
|
|
{
|
|
|
|
unitConfig.ConditionPathExists = [ "" "/etc/krb5.keytab" ];
|
|
|
|
};
|
|
|
|
|
2017-01-29 19:11:50 +01:00
|
|
|
systemd.services.rpc-gssd =
|
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
2017-09-18 11:42:40 +02:00
|
|
|
unitConfig.ConditionPathExists = [ "" "/etc/krb5.keytab" ];
|
2017-01-29 19:11:50 +01:00
|
|
|
};
|
2012-03-21 12:58:06 +01:00
|
|
|
|
2017-01-29 19:11:50 +01:00
|
|
|
systemd.services.rpc-statd =
|
2020-09-10 21:22:01 +02:00
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p /var/lib/nfs/{sm,sm.bak}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-09-16 10:51:05 +02:00
|
|
|
};
|
2012-03-09 15:37:58 +01:00
|
|
|
}
|