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";
|
|
|
|
|
2012-05-10 00:06:17 +02:00
|
|
|
idmapdConfFile = pkgs.writeText "idmapd.conf" ''
|
|
|
|
[General]
|
|
|
|
Pipefs-Directory = ${rpcMountpoint}
|
2014-11-30 10:14:46 +01:00
|
|
|
${optionalString (config.networking.domain != null)
|
2012-05-10 00:06:17 +02:00
|
|
|
"Domain = ${config.networking.domain}"}
|
|
|
|
|
|
|
|
[Mapping]
|
|
|
|
Nobody-User = nobody
|
|
|
|
Nobody-Group = nogroup
|
|
|
|
|
|
|
|
[Translation]
|
|
|
|
Method = nsswitch
|
|
|
|
'';
|
2012-03-21 12:58:06 +01:00
|
|
|
|
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 = {
|
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
|
|
|
|
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 =
|
|
|
|
{ restartTriggers = [ nfsConfFile ];
|
2017-02-05 00:10:57 +01:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p /var/lib/nfs/{sm,sm.bak}
|
|
|
|
'';
|
2012-03-21 12:58:06 +01:00
|
|
|
};
|
|
|
|
|
2014-09-16 10:51:05 +02:00
|
|
|
};
|
2012-03-09 15:37:58 +01:00
|
|
|
}
|