2009-10-12 18:36:19 +02:00
|
|
|
{ config, pkgs, ... }:
|
2009-04-21 18:34:56 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
with pkgs.lib;
|
2009-04-21 18:34:56 +02:00
|
|
|
|
|
|
|
let
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
inherit (pkgs) writeText openssh;
|
|
|
|
|
|
|
|
cfg = config.services.nfsKernel;
|
|
|
|
|
|
|
|
exports =
|
|
|
|
if builtins.pathExists cfg.exports
|
|
|
|
then cfg.exports
|
|
|
|
else pkgs.writeText "exports" cfg.exports;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-04-21 18:34:56 +02:00
|
|
|
|
|
|
|
options = {
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
services.nfsKernel = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the kernel's NFS server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# !!! Why is this a file? Why not a list of export entries?
|
|
|
|
exports = mkOption {
|
|
|
|
check = v: v != "/etc/exports"; # this won't work
|
|
|
|
description = ''
|
|
|
|
The file listing the directories to be exported. See
|
|
|
|
<citerefentry><refentrytitle>exports</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum></citerefentry> for the format.
|
|
|
|
'';
|
2009-04-21 18:34:56 +02:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
hostName = mkOption {
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Hostname or address on which NFS requests will be accepted.
|
|
|
|
Default is all. See the <option>-H</option> option in
|
|
|
|
<citerefentry><refentrytitle>nfsd</refentrytitle>
|
|
|
|
<manvolnum>8</manvolnum></citerefentry>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
nproc = mkOption {
|
|
|
|
default = 8;
|
|
|
|
description = ''
|
|
|
|
Number of NFS server threads. Defaults to the recommended value of 8.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
createMountPoints = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to create the mount points in the exports file at startup time.";
|
|
|
|
};
|
|
|
|
|
2009-04-21 18:34:56 +02:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2009-04-21 18:34:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
2009-04-21 18:34:56 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
config = mkIf config.services.nfsKernel.enable {
|
2009-04-21 18:34:56 +02:00
|
|
|
|
2009-12-24 13:05:34 +01:00
|
|
|
assertions = singleton
|
|
|
|
{ assertion = config.services.portmap.enable;
|
|
|
|
message = "Please enable portmap (services.portmap.enable) to use nfs-kernel.";
|
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
environment.etc = singleton
|
|
|
|
{ source = exports;
|
|
|
|
target = "exports";
|
|
|
|
};
|
2009-04-21 18:34:56 +02:00
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.nfs_kernel_exports =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ name = "nfs-kernel-exports";
|
|
|
|
|
|
|
|
description = "Kernel NFS server";
|
|
|
|
|
2009-11-06 23:19:17 +01:00
|
|
|
startOn = "started network-interfaces";
|
|
|
|
stopOn = "stopping network-interfaces";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
export PATH=${pkgs.nfsUtils}/sbin:$PATH
|
|
|
|
mkdir -p /var/lib/nfs
|
|
|
|
${config.system.sbin.modprobe}/sbin/modprobe nfsd || true
|
|
|
|
|
|
|
|
${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
|
|
|
|
''
|
|
|
|
}
|
|
|
|
|
|
|
|
# exports file is ${exports}
|
|
|
|
# keep this comment so that this job is restarted whenever exports changes!
|
|
|
|
exportfs -ra
|
|
|
|
'';
|
|
|
|
};
|
2009-04-21 18:34:56 +02:00
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.nfs_kernel_nfsd =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ name = "nfs-kernel-nfsd";
|
2009-04-21 18:34:56 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
description = "Kernel NFS server";
|
2009-04-21 18:34:56 +02:00
|
|
|
|
2009-12-24 13:05:34 +01:00
|
|
|
startOn = "started nfs-kernel-exports and started portmap";
|
2009-11-06 23:19:17 +01:00
|
|
|
stopOn = "stopping nfs-kernel-exports";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
exec = "${pkgs.nfsUtils}/sbin/rpc.nfsd ${if cfg.hostName != null then "-H ${cfg.hostName}" else ""} ${builtins.toString cfg.nproc}";
|
|
|
|
};
|
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.nfs_kernel_mountd =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ name = "nfs-kernel-mountd";
|
|
|
|
|
|
|
|
description = "Kernel NFS server - mount daemon";
|
|
|
|
|
2009-12-24 13:05:34 +01:00
|
|
|
startOn = "started nfs-kernel-nfsd and started portmap";
|
2009-11-06 23:19:17 +01:00
|
|
|
stopOn = "stopping nfs-kernel-exports";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
exec = "${pkgs.nfsUtils}/sbin/rpc.mountd -F -f ${exports}";
|
|
|
|
};
|
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.nfs_kernel_statd =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ name = "nfs-kernel-statd";
|
2009-09-03 16:47:58 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
description = "Kernel NFS server - Network Status Monitor";
|
|
|
|
|
2009-12-24 13:05:34 +01:00
|
|
|
startOn = "started nfs-kernel-nfsd and started portmap";
|
|
|
|
stopOn = "stopping nfs-kernel-exports";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p /var/lib/nfs
|
|
|
|
'';
|
|
|
|
|
|
|
|
exec = "${pkgs.nfsUtils}/sbin/rpc.statd -F";
|
|
|
|
};
|
2009-09-03 16:47:58 +02:00
|
|
|
|
2009-04-21 18:34:56 +02:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2009-04-21 18:34:56 +02:00
|
|
|
}
|