mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-01 23:22:37 +00:00
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:
parent
b47e6675b8
commit
c787cb1a0a
@ -46,7 +46,6 @@ let
|
||||
MAILTO="${config.services.cron.mailto}"
|
||||
${pkgs.lib.concatStrings (map (job: job + "\n") systemCronJobs)}
|
||||
'';
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
@ -81,8 +80,8 @@ in
|
||||
job = ''
|
||||
description "Cron daemon"
|
||||
|
||||
start on ${jobsTags.system.start}
|
||||
stop on ${jobsTags.system.stop}
|
||||
start on startup
|
||||
stop on shutdown
|
||||
|
||||
# Needed to interpret times in the local timezone.
|
||||
env TZ=${config.time.timeZone}
|
||||
|
@ -5,17 +5,6 @@ let
|
||||
inherit (pkgs.lib) mkOption mapAttrs getAttr fold
|
||||
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 = {
|
||||
services = {
|
||||
extraJobs = mkOption {
|
||||
@ -37,20 +26,13 @@ let
|
||||
";
|
||||
};
|
||||
|
||||
# this attribute must be computed before extraJobs.
|
||||
jobsTags = mkOption {
|
||||
default = {};
|
||||
example = {
|
||||
newtworkInterface = {
|
||||
name = "gw6c";
|
||||
priority = 5;
|
||||
};
|
||||
tools = {
|
||||
upstartJobs = mkOption {
|
||||
default = {};
|
||||
description = "
|
||||
List of functions which can be used to create upstart-jobs.
|
||||
";
|
||||
};
|
||||
description = "
|
||||
Allow jobs to overload jobs tags used by upstart jobs.
|
||||
";
|
||||
merge = mergeTags;
|
||||
apply = applyTags;
|
||||
};
|
||||
};
|
||||
|
||||
@ -471,22 +453,20 @@ let
|
||||
})
|
||||
|
||||
# User-defined events.
|
||||
++ (map makeJob (config.services.extraJobs))
|
||||
|
||||
# For the built-in logd job.
|
||||
++ [(makeJob { jobDrv = pkgs.upstart; })];
|
||||
++ (map makeJob (config.services.extraJobs));
|
||||
|
||||
|
||||
command = import ../upstart-jobs/gather.nix {
|
||||
inherit (pkgs) runCommand;
|
||||
inherit jobs;
|
||||
};
|
||||
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
require = [
|
||||
options
|
||||
(import ./lib/default.nix)
|
||||
];
|
||||
|
||||
environment = {
|
||||
@ -509,13 +489,10 @@ in
|
||||
};
|
||||
|
||||
services = {
|
||||
jobsTags = {
|
||||
system = {
|
||||
priority = 0;
|
||||
start = "startup";
|
||||
stop = "shutdown";
|
||||
};
|
||||
};
|
||||
extraJobs = [
|
||||
# For the built-in logd job.
|
||||
{ jobDrv = pkgs.upstart; }
|
||||
];
|
||||
};
|
||||
|
||||
tests = {
|
||||
|
36
upstart-jobs/lib/default.nix
Normal file
36
upstart-jobs/lib/default.nix
Normal 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;
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user