2008-12-04 16:48:27 +01:00
|
|
|
{config, pkgs, ...}:
|
2008-11-18 19:00:09 +01:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
let
|
2008-12-07 13:27:46 +01:00
|
|
|
inherit (pkgs.lib) mkOption mapAttrs getAttr fold
|
|
|
|
mergeListOption mergeTypedOption mergeAttrsWithFunc;
|
|
|
|
|
2008-11-18 19:00:09 +01:00
|
|
|
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"
|
|
|
|
'';
|
|
|
|
} ];
|
2009-03-06 13:26:36 +01:00
|
|
|
# should have some checks to verify the syntax
|
2008-11-18 19:00:09 +01:00
|
|
|
merge = pkgs.lib.mergeListOption;
|
|
|
|
description = "
|
|
|
|
Additional Upstart jobs.
|
|
|
|
";
|
|
|
|
};
|
2008-12-07 13:27:46 +01:00
|
|
|
|
2009-01-02 17:06:41 +01:00
|
|
|
tools = {
|
|
|
|
upstartJobs = mkOption {
|
|
|
|
default = {};
|
|
|
|
description = "
|
|
|
|
List of functions which can be used to create upstart-jobs.
|
|
|
|
";
|
2008-12-07 13:27:46 +01:00
|
|
|
};
|
|
|
|
};
|
2008-11-18 19:00:09 +01: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>).
|
|
|
|
";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
let
|
|
|
|
# should be moved to the corresponding jobs.
|
|
|
|
nix = config.environment.nix;
|
|
|
|
nixEnvVars = config.nix.envVars;
|
|
|
|
kernelPackages = config.boot.kernelPackages;
|
|
|
|
nssModulesPath = config.system.nssModules.path;
|
|
|
|
modprobe = config.system.sbin.modprobe;
|
|
|
|
mount = config.system.sbin.mount;
|
2006-12-11 16:32:10 +01:00
|
|
|
|
|
|
|
makeJob = import ../upstart-jobs/make-job.nix {
|
|
|
|
inherit (pkgs) runCommand;
|
|
|
|
};
|
|
|
|
|
2007-11-09 19:49:45 +01:00
|
|
|
optional = cond: service: pkgs.lib.optional cond (makeJob service);
|
2006-12-16 19:24:49 +01:00
|
|
|
|
2009-03-06 13:25:38 +01:00
|
|
|
requiredTTYs = config.requiredTTYs;
|
2007-04-04 19:10:38 +02:00
|
|
|
|
2008-03-16 02:05:40 +01:00
|
|
|
jobs = map makeJob
|
2009-03-05 18:11:40 +01:00
|
|
|
([
|
2008-05-08 14:27:01 +02:00
|
|
|
|
2006-12-11 16:32:10 +01:00
|
|
|
# Ctrl-alt-delete action.
|
|
|
|
(import ../upstart-jobs/ctrl-alt-delete.nix)
|
|
|
|
|
2008-03-16 02:05:40 +01:00
|
|
|
])
|
2006-12-11 16:32:10 +01:00
|
|
|
|
2007-08-14 18:43:56 +02:00
|
|
|
# ifplugd daemon for monitoring Ethernet cables.
|
2007-11-09 19:49:45 +01:00
|
|
|
++ optional config.networking.interfaceMonitor.enable
|
2007-08-14 18:43:56 +02:00
|
|
|
(import ../upstart-jobs/ifplugd.nix {
|
|
|
|
inherit (pkgs) ifplugd writeScript bash;
|
|
|
|
inherit config;
|
|
|
|
})
|
|
|
|
|
2006-12-11 16:32:10 +01:00
|
|
|
# Handles the reboot/halt events.
|
|
|
|
++ (map
|
|
|
|
(event: makeJob (import ../upstart-jobs/halt.nix {
|
|
|
|
inherit (pkgs) bash utillinux;
|
|
|
|
inherit event;
|
|
|
|
}))
|
|
|
|
["reboot" "halt" "system-halt" "power-off"]
|
|
|
|
)
|
|
|
|
|
2006-12-18 18:41:46 +01:00
|
|
|
# User-defined events.
|
2009-01-02 17:06:41 +01:00
|
|
|
++ (map makeJob (config.services.extraJobs));
|
2007-11-23 11:56:12 +01:00
|
|
|
|
2008-11-18 19:00:09 +01:00
|
|
|
|
|
|
|
command = import ../upstart-jobs/gather.nix {
|
|
|
|
inherit (pkgs) runCommand;
|
|
|
|
inherit jobs;
|
|
|
|
};
|
2009-01-02 17:06:41 +01:00
|
|
|
|
2008-11-18 19:00:09 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
require = [
|
|
|
|
options
|
2009-01-02 17:06:41 +01:00
|
|
|
(import ./lib/default.nix)
|
2008-11-18 19:00:09 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
etc = [{ # The Upstart events defined above.
|
|
|
|
source = command + "/etc/event.d";
|
|
|
|
target = "event.d";
|
|
|
|
}]
|
|
|
|
++ pkgs.lib.concatLists (map (job: job.extraEtc) jobs);
|
|
|
|
|
|
|
|
extraPackages =
|
|
|
|
pkgs.lib.concatLists (map (job: job.extraPath) jobs);
|
|
|
|
};
|
|
|
|
|
|
|
|
users = {
|
|
|
|
extraUsers =
|
|
|
|
pkgs.lib.concatLists (map (job: job.users) jobs);
|
|
|
|
|
|
|
|
extraGroups =
|
|
|
|
pkgs.lib.concatLists (map (job: job.groups) jobs);
|
|
|
|
};
|
|
|
|
|
2008-12-07 13:27:46 +01:00
|
|
|
services = {
|
2009-01-02 17:06:41 +01:00
|
|
|
extraJobs = [
|
|
|
|
# For the built-in logd job.
|
|
|
|
{ jobDrv = pkgs.upstart; }
|
|
|
|
];
|
2008-12-07 13:27:46 +01:00
|
|
|
};
|
|
|
|
|
2008-11-18 19:00:09 +01:00
|
|
|
tests = {
|
|
|
|
# see test/test-upstart-job.sh
|
|
|
|
upstartJobs = { recurseForDerivations = true; } //
|
|
|
|
builtins.listToAttrs (map (job:
|
|
|
|
{ name = if job ? jobName then job.jobName else job.name; value = job; }
|
|
|
|
) jobs);
|
|
|
|
};
|
2009-01-02 17:07:21 +01:00
|
|
|
}
|