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;
|
|
|
|
|
2010-06-08 18:01:31 +02:00
|
|
|
exports = pkgs.writeText "exports" cfg.server.exports;
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-04-21 18:34:56 +02:00
|
|
|
|
|
|
|
options = {
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
services.nfsKernel = {
|
|
|
|
|
2010-02-21 17:26:33 +01:00
|
|
|
client.enable = mkOption {
|
2009-10-12 18:36:19 +02:00
|
|
|
default = false;
|
|
|
|
description = ''
|
2010-02-21 17:26:33 +01:00
|
|
|
Whether to enable the kernel's NFS client daemons.
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
2009-04-21 18:34:56 +02:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2010-02-21 17:26:33 +01:00
|
|
|
server = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the kernel's NFS server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
exports = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Contents of the /etc/exports file. See
|
|
|
|
<citerefentry><refentrytitle>exports</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum></citerefentry> for the format.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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>.
|
|
|
|
'';
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2010-02-21 17:26:33 +01:00
|
|
|
nproc = mkOption {
|
|
|
|
default = 8;
|
|
|
|
description = ''
|
|
|
|
Number of NFS server threads. Defaults to the recommended value of 8.
|
|
|
|
'';
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2010-02-21 17:26:33 +01:00
|
|
|
createMountPoints = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to create the mount points in the exports file at startup time.";
|
|
|
|
};
|
2009-10-12 18:36:19 +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
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
2009-04-21 18:34:56 +02:00
|
|
|
|
2010-02-21 17:26:33 +01:00
|
|
|
config = {
|
2009-04-21 18:34:56 +02:00
|
|
|
|
2010-02-22 18:12:26 +01:00
|
|
|
services.portmap.enable = cfg.client.enable || cfg.server.enable;
|
|
|
|
|
2010-02-21 17:26:33 +01:00
|
|
|
assertions = mkIf (cfg.client.enable || cfg.server.enable) (singleton
|
2010-02-22 18:12:26 +01:00
|
|
|
{ assertion = cfg.client.enable || cfg.server.enable;
|
2009-12-24 13:05:34 +01:00
|
|
|
message = "Please enable portmap (services.portmap.enable) to use nfs-kernel.";
|
2010-02-21 17:26:33 +01:00
|
|
|
});
|
2009-12-24 13:05:34 +01:00
|
|
|
|
2010-02-21 17:26:33 +01:00
|
|
|
environment.etc = mkIf cfg.server.enable (singleton
|
2010-06-08 18:01:31 +02:00
|
|
|
{ source = exports;
|
2009-10-12 18:36:19 +02:00
|
|
|
target = "exports";
|
2010-02-21 17:26:33 +01:00
|
|
|
});
|
2009-04-21 18:34:56 +02:00
|
|
|
|
2010-02-22 18:12:26 +01:00
|
|
|
jobs =
|
|
|
|
optionalAttrs cfg.server.enable
|
|
|
|
{ nfs_kernel_exports =
|
|
|
|
{ name = "nfs-kernel-exports";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2010-02-22 18:12:26 +01:00
|
|
|
description = "Kernel NFS server";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2010-02-22 18:12:26 +01:00
|
|
|
startOn = "started network-interfaces";
|
|
|
|
stopOn = "stopping network-interfaces";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2010-02-22 18:12:26 +01:00
|
|
|
preStart =
|
2009-10-12 18:36:19 +02:00
|
|
|
''
|
2010-02-22 18:12:26 +01:00
|
|
|
export PATH=${pkgs.nfsUtils}/sbin:$PATH
|
|
|
|
mkdir -p /var/lib/nfs
|
2010-06-08 18:01:31 +02:00
|
|
|
|
2010-02-22 18:12:26 +01:00
|
|
|
${config.system.sbin.modprobe}/sbin/modprobe nfsd || true
|
|
|
|
|
2010-06-08 18:01:31 +02:00
|
|
|
${pkgs.sysvtools}/bin/mountpoint -q /proc/fs/nfsd \
|
|
|
|
|| ${config.system.sbin.mount}/bin/mount -t nfsd none /proc/fs/nfsd
|
|
|
|
|
2010-02-22 18:12:26 +01:00
|
|
|
${optionalString cfg.server.createMountPoints
|
|
|
|
''
|
|
|
|
# create export directories:
|
|
|
|
# skip comments, take first col which may either be a quoted
|
|
|
|
# "foo bar" or just foo (-> man export)
|
2010-06-08 18:01:31 +02:00
|
|
|
sed '/^#.*/d;s/^"\([^"]*\)".*/\1/;t;s/[ ].*//' ${exports} \
|
2010-02-22 18:12:26 +01:00
|
|
|
| xargs -d '\n' mkdir -p
|
|
|
|
''
|
|
|
|
}
|
|
|
|
|
2010-06-08 18:01:31 +02:00
|
|
|
# exports file is ${exports}
|
2010-02-22 18:12:26 +01:00
|
|
|
# keep this comment so that this job is restarted whenever exports changes!
|
|
|
|
exportfs -ra
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// optionalAttrs cfg.server.enable
|
|
|
|
{ nfs_kernel_nfsd =
|
|
|
|
{ name = "nfs-kernel-nfsd";
|
|
|
|
|
|
|
|
description = "Kernel NFS server";
|
|
|
|
|
|
|
|
startOn = "started nfs-kernel-exports and started portmap";
|
|
|
|
stopOn = "stopping nfs-kernel-exports";
|
|
|
|
|
2010-06-08 18:01:31 +02:00
|
|
|
preStart = "${pkgs.nfsUtils}/sbin/rpc.nfsd ${if cfg.server.hostName != null then "-H ${cfg.server.hostName}" else ""} ${builtins.toString cfg.server.nproc}";
|
|
|
|
|
|
|
|
postStop = "${pkgs.nfsUtils}/sbin/rpc.nfsd 0";
|
2010-02-22 18:12:26 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// optionalAttrs cfg.server.enable
|
|
|
|
{ nfs_kernel_mountd =
|
|
|
|
{ name = "nfs-kernel-mountd";
|
|
|
|
|
|
|
|
description = "Kernel NFS server - mount daemon";
|
|
|
|
|
|
|
|
startOn = "started nfs-kernel-nfsd and started portmap";
|
|
|
|
stopOn = "stopping nfs-kernel-exports";
|
|
|
|
|
2010-05-08 21:02:54 +02:00
|
|
|
exec = "${pkgs.nfsUtils}/sbin/rpc.mountd -F -f /etc/exports";
|
2010-02-22 18:12:26 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// optionalAttrs (cfg.client.enable || cfg.server.enable)
|
|
|
|
{ nfs_kernel_statd =
|
|
|
|
{ name = "nfs-kernel-statd";
|
|
|
|
|
|
|
|
description = "Kernel NFS server - Network Status Monitor";
|
|
|
|
|
2010-03-11 13:56:40 +01:00
|
|
|
startOn = "${if cfg.server.enable then "started nfs-kernel-nfsd and " else ""} started portmap";
|
2010-02-22 18:12:26 +01:00
|
|
|
stopOn = "stopping nfs-kernel-exports";
|
|
|
|
|
|
|
|
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
|
|
|
}
|