2009-10-12 18:36:19 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2009-03-06 13:26:22 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
uid = config.ids.uids.portmap;
|
|
|
|
gid = config.ids.gids.portmap;
|
2009-02-24 20:17:25 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
portmap = pkgs.portmap.override { daemonUID = uid; daemonGID = gid; };
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
in
|
2009-02-24 21:41:58 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
{
|
2009-02-24 21:41:58 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
services.portmap = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable `portmap', an ONC RPC directory service
|
|
|
|
notably used by NFS and NIS, and which can be queried
|
|
|
|
using the rpcinfo(1) command.
|
|
|
|
'';
|
2009-03-06 13:26:22 +01:00
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
verbose = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable verbose output.
|
|
|
|
'';
|
|
|
|
};
|
2008-03-16 00:40:44 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
chroot = mkOption {
|
|
|
|
default = "/var/empty";
|
|
|
|
description = ''
|
|
|
|
If non-empty, a path to change root to.
|
|
|
|
'';
|
|
|
|
};
|
2008-03-16 00:40:44 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-03-06 13:26:22 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2008-03-16 00:40:44 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
2008-03-16 00:40:44 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
config = mkIf config.services.portmap.enable {
|
|
|
|
|
2012-03-16 18:43:18 +01:00
|
|
|
environment.systemPackages = [ portmap ];
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
users.extraUsers = singleton
|
2009-03-06 13:26:22 +01:00
|
|
|
{ name = "portmap";
|
|
|
|
inherit uid;
|
2010-06-09 13:15:25 +02:00
|
|
|
description = "Portmap daemon user";
|
2009-03-06 13:26:22 +01:00
|
|
|
home = "/var/empty";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-03-06 13:26:22 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
users.extraGroups = singleton
|
2009-03-06 13:26:22 +01:00
|
|
|
{ name = "portmap";
|
|
|
|
inherit gid;
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-03-06 13:26:22 +01:00
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.portmap =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ description = "ONC RPC portmap";
|
2009-03-06 13:26:22 +01:00
|
|
|
|
2012-03-17 18:31:08 +01:00
|
|
|
startOn = "started network-interfaces";
|
2010-06-10 00:29:06 +02:00
|
|
|
stopOn = "never";
|
2010-06-09 13:15:25 +02:00
|
|
|
|
2012-03-16 21:10:14 +01:00
|
|
|
daemonType = "fork"; # needed during shutdown
|
2009-03-06 13:26:22 +01:00
|
|
|
|
2012-03-16 20:49:47 +01:00
|
|
|
path = [ portmap pkgs.netcat ];
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
exec =
|
|
|
|
''
|
2012-03-16 20:49:47 +01:00
|
|
|
portmap \
|
2010-06-09 13:15:25 +02:00
|
|
|
${optionalString (config.services.portmap.chroot != "")
|
|
|
|
"-t '${config.services.portmap.chroot}'"} \
|
2009-10-12 18:36:19 +02:00
|
|
|
${if config.services.portmap.verbose then "-v" else ""}
|
|
|
|
'';
|
2012-03-16 20:49:47 +01:00
|
|
|
|
|
|
|
postStart =
|
|
|
|
''
|
|
|
|
# Portmap forks into the background before it starts
|
|
|
|
# listening, so wait until its ready.
|
2012-03-16 22:24:51 +01:00
|
|
|
while ! nc -z localhost 111; do
|
|
|
|
if [[ "$(status)" =~ stop/ ]]; then exit; fi
|
|
|
|
sleep 1
|
|
|
|
done
|
2012-03-16 20:49:47 +01:00
|
|
|
'';
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2008-03-16 00:40:44 +01:00
|
|
|
|
2009-03-06 13:26:22 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-03-16 00:40:44 +01:00
|
|
|
}
|