2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.nfs.server;
|
|
|
|
|
|
|
|
exports = pkgs.writeText "exports" cfg.exports;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "nfs" "lockdPort" ] [ "services" "nfs" "server" "lockdPort" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "nfs" "statdPort" ] [ "services" "nfs" "server" "statdPort" ])
|
|
|
|
];
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.nfs = {
|
|
|
|
|
|
|
|
server = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to enable the kernel's NFS server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraNfsdConfig = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Extra configuration options for the [nfsd] section of /etc/nfs.conf.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
exports = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Contents of the /etc/exports file. See
|
2022-08-21 13:32:41 +00:00
|
|
|
{manpage}`exports(5)` for the format.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
hostName = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Hostname or address on which NFS requests will be accepted.
|
2022-08-21 13:32:41 +00:00
|
|
|
Default is all. See the {option}`-H` option in
|
|
|
|
{manpage}`nfsd(8)`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
nproc = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 8;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Number of NFS server threads. Defaults to the recommended value of 8.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
createMountPoints = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Whether to create the mount points in the exports file at startup time.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mountdPort = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 4002;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Use fixed port for rpc.mountd, useful if server is behind firewall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
lockdPort = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 4001;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Use a fixed port for the NFS lock manager kernel module
|
2022-08-12 12:06:08 +00:00
|
|
|
(`lockd/nlockmgr`). This is useful if the
|
2020-04-24 23:36:52 +00:00
|
|
|
NFS server is behind a firewall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
statdPort = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 4000;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
Use a fixed port for {command}`rpc.statd`. This is
|
2020-04-24 23:36:52 +00:00
|
|
|
useful if the NFS server is behind a firewall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
services.rpcbind.enable = true;
|
|
|
|
|
|
|
|
boot.supportedFilesystems = [ "nfs" ]; # needed for statd and idmapd
|
|
|
|
|
|
|
|
environment.etc.exports.source = exports;
|
|
|
|
|
|
|
|
systemd.services.nfs-server =
|
|
|
|
{ enable = true;
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p /var/lib/nfs/v4recovery
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.nfs-mountd =
|
|
|
|
{ enable = true;
|
|
|
|
restartTriggers = [ exports ];
|
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p /var/lib/nfs
|
|
|
|
|
|
|
|
${optionalString cfg.createMountPoints
|
|
|
|
''
|
|
|
|
# create export directories:
|
|
|
|
# skip comments, take first col which may either be a quoted
|
|
|
|
# "foo bar" or just foo (-> man export)
|
|
|
|
sed '/^#.*/d;s/^"\([^"]*\)".*/\1/;t;s/[ ].*//' ${exports} \
|
|
|
|
| xargs -d '\n' mkdir -p
|
|
|
|
''
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|