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-05-27 12:32:30 +02:00
|
|
|
makeJob = import ./make-job.nix {
|
2006-12-11 16:32:10 +01:00
|
|
|
inherit (pkgs) runCommand;
|
|
|
|
};
|
|
|
|
|
2009-07-15 11:06:36 +02:00
|
|
|
inherit (pkgs.lib) mkOption mergeListOption;
|
|
|
|
|
2009-05-28 18:03:48 +02:00
|
|
|
jobs = map makeJob 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.
|
|
|
|
command = pkgs.runCommand "upstart-jobs" {inherit jobs;}
|
|
|
|
''
|
|
|
|
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 = {
|
|
|
|
|
|
|
|
services.extraJobs = mkOption {
|
|
|
|
default = [];
|
|
|
|
example =
|
|
|
|
[ { name = "test-job";
|
|
|
|
job = ''
|
|
|
|
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"
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
# should have some checks to verify the syntax
|
|
|
|
merge = pkgs.lib.mergeListOption;
|
|
|
|
description = ''
|
|
|
|
Additional Upstart jobs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
|
|
|
source = command + "/etc/event.d";
|
|
|
|
target = "event.d";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
environment.extraPackages =
|
|
|
|
pkgs.lib.concatLists (map (job: job.extraPath) jobs);
|
|
|
|
|
|
|
|
users.extraUsers =
|
2008-11-18 19:00:09 +01:00
|
|
|
pkgs.lib.concatLists (map (job: job.users) jobs);
|
|
|
|
|
2009-07-15 11:06:36 +02:00
|
|
|
users.extraGroups =
|
2008-11-18 19:00:09 +01:00
|
|
|
pkgs.lib.concatLists (map (job: job.groups) jobs);
|
|
|
|
|
2009-07-15 11:06:36 +02:00
|
|
|
services.extraJobs =
|
|
|
|
[ # For the built-in logd job.
|
|
|
|
{ jobDrv = pkgs.upstart; }
|
|
|
|
];
|
2008-12-07 13:27:46 +01:00
|
|
|
|
2009-07-15 11:06:36 +02:00
|
|
|
# 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
|
|
|
}
|