diff --git a/upstart-jobs/cron.nix b/upstart-jobs/cron.nix index 45a3295f7165..404fdd45b559 100644 --- a/upstart-jobs/cron.nix +++ b/upstart-jobs/cron.nix @@ -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} diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index 4b42d8a77389..47d2a0ec422a 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -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 = { diff --git a/upstart-jobs/lib/default.nix b/upstart-jobs/lib/default.nix new file mode 100644 index 000000000000..e2adbd1d8410 --- /dev/null +++ b/upstart-jobs/lib/default.nix @@ -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; + }; + }; +}