Replace job tags by a library of function to build upstart jobs.

svn path=/nixos/branches/fix-style/; revision=13674
This commit is contained in:
Nicolas Pierron 2009-01-02 16:06:41 +00:00
parent b47e6675b8
commit c787cb1a0a
3 changed files with 51 additions and 39 deletions

View File

@ -46,7 +46,6 @@ let
MAILTO="${config.services.cron.mailto}" MAILTO="${config.services.cron.mailto}"
${pkgs.lib.concatStrings (map (job: job + "\n") systemCronJobs)} ${pkgs.lib.concatStrings (map (job: job + "\n") systemCronJobs)}
''; '';
in in
{ {
@ -81,8 +80,8 @@ in
job = '' job = ''
description "Cron daemon" description "Cron daemon"
start on ${jobsTags.system.start} start on startup
stop on ${jobsTags.system.stop} stop on shutdown
# Needed to interpret times in the local timezone. # Needed to interpret times in the local timezone.
env TZ=${config.time.timeZone} env TZ=${config.time.timeZone}

View File

@ -5,17 +5,6 @@ let
inherit (pkgs.lib) mkOption mapAttrs getAttr fold inherit (pkgs.lib) mkOption mapAttrs getAttr fold
mergeListOption mergeTypedOption mergeAttrsWithFunc; mergeListOption mergeTypedOption mergeAttrsWithFunc;
mergeTags = mergeTypedOption "jobs tag" (x: true)
(fold (mergeAttrsWithFunc (a: b:
if builtins.lessThan a.priority b.priority then b else a
)) { priority = 100; });
applyTags = mapAttrs (attrName: value:
let name = getAttr ["name"] attrName value; in {
start = getAttr ["start"] (name + "/started") value;
stop = getAttr ["stop"] (name + "/stop") value;
});
options = { options = {
services = { services = {
extraJobs = mkOption { extraJobs = mkOption {
@ -37,20 +26,13 @@ let
"; ";
}; };
# this attribute must be computed before extraJobs. tools = {
jobsTags = mkOption { upstartJobs = mkOption {
default = {}; default = {};
example = { description = "
newtworkInterface = { List of functions which can be used to create upstart-jobs.
name = "gw6c"; ";
priority = 5;
};
}; };
description = "
Allow jobs to overload jobs tags used by upstart jobs.
";
merge = mergeTags;
apply = applyTags;
}; };
}; };
@ -471,10 +453,7 @@ let
}) })
# User-defined events. # User-defined events.
++ (map makeJob (config.services.extraJobs)) ++ (map makeJob (config.services.extraJobs));
# For the built-in logd job.
++ [(makeJob { jobDrv = pkgs.upstart; })];
command = import ../upstart-jobs/gather.nix { command = import ../upstart-jobs/gather.nix {
@ -487,6 +466,7 @@ in
{ {
require = [ require = [
options options
(import ./lib/default.nix)
]; ];
environment = { environment = {
@ -509,13 +489,10 @@ in
}; };
services = { services = {
jobsTags = { extraJobs = [
system = { # For the built-in logd job.
priority = 0; { jobDrv = pkgs.upstart; }
start = "startup"; ];
stop = "shutdown";
};
};
}; };
tests = { tests = {

View File

@ -0,0 +1,36 @@
# This file defines functions to handle upstart-jobs.
{pkgs, config, ...}:
let
inherit (pkgs.lib) filter findSingle;
jobs = config.services.extraJobs;
primaryEvents = [
"startup"
"shutdown"
"never"
];
upstartJobsTools = rec {
exists = name:
let
found = filter
(j: j ? name && j.name == name)
(jobs ++ map (name: {inherit name;}) primaryEvents);
in found != [];
check = name:
if exists name then
name
else
abort "Undefined upstart job name: ${name}.";
};
in
{
services = {
tools = {
upstartJobs = upstartJobsTools;
};
};
}