2009-04-21 18:34:56 +02:00
|
|
|
|
|
|
|
{pkgs, config, ...}:
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
let
|
|
|
|
inherit (pkgs.lib) mkOption mkIf;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services = {
|
|
|
|
nfsKernel = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
wether to use the kernel nfs functionality to export filesystems.
|
|
|
|
You should be aware about existing security issues.
|
|
|
|
requires portmap!
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
exports = mkOption {
|
|
|
|
default = "/etc/exports";
|
|
|
|
description = "
|
|
|
|
the file listing the directories to be exported.
|
|
|
|
install nfsUtils and run man exports to learn about its format.
|
|
|
|
The exports setting can either be a file path or the file contents.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
hostName = mkOption {
|
|
|
|
default = null;
|
|
|
|
description = "
|
|
|
|
specify a particular hostname (or address) that NFS requests will be accepted on.
|
|
|
|
Default: all.
|
|
|
|
See man rpc.nfsd (-H option)
|
|
|
|
";
|
|
|
|
};
|
|
|
|
nproc = mkOption {
|
|
|
|
default = 8;
|
|
|
|
description = "
|
|
|
|
specify the number of NFS server threads. (-> man rpc.nfsd). Defaults to recommended value 8
|
|
|
|
";
|
|
|
|
};
|
2009-09-05 00:01:08 +02:00
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
inherit (pkgs) writeText openssh;
|
|
|
|
|
|
|
|
cfg = (config.services.nfsKernel);
|
|
|
|
|
|
|
|
modprobe = config.system.sbin.modprobe;
|
|
|
|
|
|
|
|
exports = if builtins.pathExists cfg.exports
|
2009-08-19 22:20:57 +02:00
|
|
|
then cfg.exports else pkgs.writeText "exports" cfg.exports;
|
2009-04-21 18:34:56 +02:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
|
2009-04-21 21:26:47 +02:00
|
|
|
mkIf config.services.nfsKernel.enable {
|
2009-04-21 18:34:56 +02:00
|
|
|
require = [
|
|
|
|
options
|
|
|
|
];
|
|
|
|
|
2009-09-03 16:47:58 +02:00
|
|
|
environment.etc = [
|
|
|
|
{ source = exports;
|
|
|
|
target = "exports"; }
|
|
|
|
];
|
|
|
|
|
2009-04-21 18:34:56 +02:00
|
|
|
services = {
|
|
|
|
extraJobs = [
|
|
|
|
{
|
|
|
|
name = "nfs-kernel-exports";
|
|
|
|
|
|
|
|
job = ''
|
|
|
|
description "export filesystems using kernel nfs"
|
|
|
|
|
|
|
|
start on network-interfaces/started
|
|
|
|
stop on network-interfaces/stop
|
|
|
|
|
|
|
|
start script
|
2009-09-05 00:01:08 +02:00
|
|
|
export PATH=${pkgs.nfsUtils}/sbin:$PATH
|
2009-09-03 16:47:58 +02:00
|
|
|
mkdir -p /var/lib/nfs
|
2009-04-21 18:34:56 +02:00
|
|
|
${modprobe}/sbin/modprobe nfsd || true
|
2009-09-05 00:01:08 +02:00
|
|
|
|
|
|
|
${if cfg.createMountPoints == true then
|
|
|
|
''
|
|
|
|
cat /etc/exports | while read line
|
|
|
|
do
|
|
|
|
for i in $line
|
|
|
|
do
|
|
|
|
mkdir -p $i
|
|
|
|
break
|
|
|
|
done
|
|
|
|
done
|
|
|
|
''
|
|
|
|
else ""}
|
|
|
|
|
2009-09-03 16:47:58 +02:00
|
|
|
exportfs -ra
|
2009-04-21 18:34:56 +02:00
|
|
|
end script
|
|
|
|
|
|
|
|
respawn sleep 1000000
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "nfs-kernel-rpc-nfsd";
|
|
|
|
|
|
|
|
job = ''
|
|
|
|
description "export filesystems using kernel nfs"
|
|
|
|
|
|
|
|
start on nfs-kernel-exports/started
|
|
|
|
stop on nfs-kernel-exports/stop
|
|
|
|
|
|
|
|
respawn ${pkgs.nfsUtils}/sbin/rpc.nfsd ${if cfg.hostName != null then "-H ${cfg.hostName}" else ""} ${builtins.toString cfg.nproc}
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "nfs-kernel-mountd";
|
|
|
|
|
|
|
|
job = ''
|
|
|
|
description "export filesystems using kernel nfs"
|
|
|
|
|
|
|
|
start on nfs-kernel-rpc-nfsd/started
|
|
|
|
stop on nfs-kernel-exports/stop
|
|
|
|
|
|
|
|
respawn ${pkgs.nfsUtils}/sbin/rpc.mountd -F -f ${exports}
|
|
|
|
'';
|
|
|
|
}
|
2009-09-03 16:47:58 +02:00
|
|
|
{
|
|
|
|
name = "nfs-kernel-statd";
|
|
|
|
|
|
|
|
job = ''
|
|
|
|
description "NSM (Network Status Monitor) of the RPC protocol"
|
|
|
|
|
|
|
|
start on nfs-kernel-rpc-nfsd/started
|
|
|
|
stop on nfs-kernel-exports/stop
|
|
|
|
|
|
|
|
start script
|
|
|
|
mkdir -p /var/lib/nfs
|
|
|
|
end script
|
|
|
|
|
|
|
|
respawn ${pkgs.nfsUtils}/sbin/rpc.statd
|
|
|
|
'';
|
|
|
|
}
|
2009-04-21 18:34:56 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|