nixpkgs/modules/services/networking/portmap.nix
Eelco Dolstra 646d67465c * Upstart stupidly doesn't kill post-start scripts if we do "stop
JOB", but it does kill the job's main process.  So if the post-start
  script if waiting for the job's main process to reach some state, it
  may hang forever.  Thus, the post-start script should monitor
  whether its job has been requested to stop and exit in that case.

svn path=/nixos/trunk/; revision=33176
2012-03-16 21:24:51 +00:00

100 lines
2 KiB
Nix

{ config, pkgs, ... }:
with pkgs.lib;
let
uid = config.ids.uids.portmap;
gid = config.ids.gids.portmap;
portmap = pkgs.portmap.override { daemonUID = uid; daemonGID = gid; };
in
{
###### interface
options = {
services.portmap = {
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.
'';
};
verbose = mkOption {
default = false;
description = ''
Whether to enable verbose output.
'';
};
chroot = mkOption {
default = "/var/empty";
description = ''
If non-empty, a path to change root to.
'';
};
};
};
###### implementation
config = mkIf config.services.portmap.enable {
environment.systemPackages = [ portmap ];
users.extraUsers = singleton
{ name = "portmap";
inherit uid;
description = "Portmap daemon user";
home = "/var/empty";
};
users.extraGroups = singleton
{ name = "portmap";
inherit gid;
};
jobs.portmap =
{ description = "ONC RPC portmap";
startOn = "started network-interfaces";
stopOn = "never";
daemonType = "fork"; # needed during shutdown
path = [ portmap pkgs.netcat ];
exec =
''
portmap \
${optionalString (config.services.portmap.chroot != "")
"-t '${config.services.portmap.chroot}'"} \
${if config.services.portmap.verbose then "-v" else ""}
'';
postStart =
''
# Portmap forks into the background before it starts
# listening, so wait until its ready.
while ! nc -z localhost 111; do
if [[ "$(status)" =~ stop/ ]]; then exit; fi
sleep 1
done
'';
};
};
}