2008-12-04 16:48:27 +01:00
|
|
|
{config, pkgs, ...}:
|
2008-11-18 19:00:09 +01:00
|
|
|
|
|
|
|
let
|
2008-12-07 13:27:46 +01:00
|
|
|
|
2009-07-15 15:41:00 +02:00
|
|
|
inherit (pkgs.lib) mkOption mergeListOption types;
|
2009-07-15 11:06:36 +02:00
|
|
|
|
2009-07-15 14:52:32 +02:00
|
|
|
makeJob =
|
|
|
|
{name, job, buildHook ? "true", passthru ? null}:
|
|
|
|
|
|
|
|
pkgs.runCommand ("upstart-" + name)
|
|
|
|
{ inherit buildHook job; }
|
|
|
|
''
|
|
|
|
eval "$buildHook"
|
|
|
|
ensureDir $out/etc/event.d
|
|
|
|
echo "$job" > $out/etc/event.d/${name}
|
|
|
|
'';
|
2009-07-15 13:38:17 +02:00
|
|
|
|
2009-07-15 14:52:32 +02:00
|
|
|
jobs =
|
|
|
|
[pkgs.upstart] # for the built-in logd job
|
|
|
|
++ map makeJob (config.jobs ++ config.services.extraJobs);
|
2009-05-27 12:32:30 +02:00
|
|
|
|
|
|
|
# Create an etc/event.d directory containing symlinks to the
|
|
|
|
# specified list of Upstart job files.
|
2009-07-15 13:38:17 +02:00
|
|
|
jobsDir = pkgs.runCommand "upstart-jobs" {inherit jobs;}
|
2009-05-27 12:32:30 +02:00
|
|
|
''
|
|
|
|
ensureDir $out/etc/event.d
|
|
|
|
for i in $jobs; do
|
|
|
|
if ln -s $i . ; then
|
|
|
|
if test -d $i; then
|
|
|
|
ln -s $i/etc/event.d/* $out/etc/event.d/
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo Duplicate entry: $i;
|
|
|
|
fi;
|
|
|
|
done
|
2009-05-28 01:30:29 +02:00
|
|
|
''; # */
|
2009-01-02 17:06:41 +01:00
|
|
|
|
2009-07-15 11:06:36 +02:00
|
|
|
in
|
|
|
|
|
2008-11-18 19:00:09 +01:00
|
|
|
{
|
2009-07-15 11:06:36 +02:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2009-07-15 13:19:11 +02:00
|
|
|
jobs = mkOption {
|
2009-07-15 11:06:36 +02:00
|
|
|
default = [];
|
2009-07-15 15:41:00 +02:00
|
|
|
description = ''
|
|
|
|
This option defines the system jobs started and managed by the
|
|
|
|
Upstart daemon.
|
|
|
|
'';
|
|
|
|
|
|
|
|
type = types.list types.optionSet;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
example = "sshd";
|
|
|
|
description = ''
|
|
|
|
Name of the Upstart job.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
job = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
example =
|
|
|
|
''
|
2009-07-15 11:06:36 +02:00
|
|
|
description "nc"
|
|
|
|
start on started network-interfaces
|
|
|
|
respawn
|
|
|
|
env PATH=/var/run/current-system/sw/bin
|
|
|
|
exec sh -c "echo 'hello world' | ${pkgs.netcat}/bin/nc -l -p 9000"
|
2009-07-15 15:41:00 +02:00
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Contents of the Upstart job.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
buildHook = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "true";
|
|
|
|
description = ''
|
|
|
|
Command run while building the Upstart job. Can be used
|
|
|
|
to perform simple regression tests (e.g., the Apache
|
|
|
|
Upstart job uses it to check the syntax of the generated
|
|
|
|
<filename>httpd.conf</filename>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-07-15 13:19:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
services.extraJobs = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Obsolete - don't use.
|
2009-07-15 11:06:36 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
tests.upstartJobs = mkOption {
|
|
|
|
internal = true;
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Make it easier to build individual Upstart jobs. (e.g.,
|
|
|
|
<command>nix-build /etc/nixos/nixos -A
|
|
|
|
tests.upstartJobs.xserver</command>).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2008-11-18 19:00:09 +01:00
|
|
|
};
|
|
|
|
|
2009-07-15 11:06:36 +02:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
|
|
environment.etc =
|
|
|
|
[ { # The Upstart events defined above.
|
2009-07-15 13:38:17 +02:00
|
|
|
source = "${jobsDir}/etc/event.d";
|
2009-07-15 11:06:36 +02:00
|
|
|
target = "event.d";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
# see test/test-upstart-job.sh (!!! check whether this still works)
|
|
|
|
tests.upstartJobs = { recurseForDerivations = true; } //
|
2008-11-18 19:00:09 +01:00
|
|
|
builtins.listToAttrs (map (job:
|
|
|
|
{ name = if job ? jobName then job.jobName else job.name; value = job; }
|
|
|
|
) jobs);
|
2009-07-15 11:06:36 +02:00
|
|
|
|
2008-11-18 19:00:09 +01:00
|
|
|
};
|
2009-07-15 11:06:36 +02:00
|
|
|
|
2009-01-02 17:07:21 +01:00
|
|
|
}
|