diff --git a/modules/services/system/nscd.nix b/modules/services/system/nscd.nix index 63fa36b94227..11aa48720b27 100644 --- a/modules/services/system/nscd.nix +++ b/modules/services/system/nscd.nix @@ -17,31 +17,24 @@ in description = "Name service cache daemon user"; }; - jobs = singleton { - name = "nscd"; + jobs = singleton + { name = "nscd"; + + description = "Name Service Cache Daemon"; + + startOn = "startup"; + stopOn = "shutdown"; + + environment = { LD_LIBRARY_PATH = nssModulesPath; }; - job = '' - description \"Name Service Cache Daemon\" - - start on startup - stop on shutdown - - env LD_LIBRARY_PATH=${nssModulesPath} - - start script - + preStart = + '' mkdir -m 0755 -p /var/run/nscd mkdir -m 0755 -p /var/db/nscd + ''; - rm -f /var/db/nscd/* # for testing - - end script - - # !!! -d turns on debug info which probably makes nscd slower - # 2>/dev/null is to make it shut up - respawn ${pkgs.glibc}/sbin/nscd -f ${./nscd.conf} -d 2> /dev/null - ''; - }; + exec = "${pkgs.glibc}/sbin/nscd -f ${./nscd.conf} -d 2> /dev/null"; + }; }; } diff --git a/modules/system/upstart/upstart.nix b/modules/system/upstart/upstart.nix index 1c304233e847..6933b71c027c 100644 --- a/modules/system/upstart/upstart.nix +++ b/modules/system/upstart/upstart.nix @@ -1,20 +1,44 @@ {config, pkgs, ...}: +with pkgs.lib; + let - inherit (pkgs.lib) mkOption mergeListOption types; - - makeJob = - {name, job, buildHook ? "true", passthru ? null}: - - pkgs.runCommand ("upstart-" + name) - { inherit buildHook job; } - '' - eval "$buildHook" - ensureDir $out/etc/event.d - echo "$job" > $out/etc/event.d/${name} - ''; + # From a job description, generate an Upstart job file. + makeJob = job@{buildHook ? "", ...}: + let + + jobText = if job.job != "" then job.job else + '' + description "${job.description}" + + ${if job.startOn != "" then "start on ${job.startOn}" else ""} + ${if job.stopOn != "" then "start on ${job.stopOn}" else ""} + + ${concatMapStrings (n: "env ${n}=${getAttr n job.environment}\n") (attrNames job.environment)} + + ${if job.preStart != "" then '' + start script + ${job.preStart} + end script + '' else ""} + + ${if job.exec != "" then '' + exec ${job.exec} + '' else ""} + ''; + + in + pkgs.runCommand ("upstart-" + job.name) + { inherit buildHook; inherit jobText; } + '' + eval "$buildHook" + ensureDir $out/etc/event.d + echo "$jobText" > $out/etc/event.d/${job.name} + ''; + + jobs = [pkgs.upstart] # for the built-in logd job ++ map makeJob (config.jobs ++ config.services.extraJobs); @@ -63,6 +87,7 @@ in }; job = mkOption { + default = ""; type = types.string; example = '' @@ -88,6 +113,57 @@ in ''; }; + description = mkOption { + type = types.string; + default = "(no description given)"; + description = '' + A short description of this job. + ''; + }; + + startOn = mkOption { + type = types.string; + default = ""; + description = '' + The Upstart event that triggers this job to be started. + If empty, the job will not start automatically. + ''; + }; + + stopOn = mkOption { + type = types.string; + default = ""; + description = '' + The Upstart event that triggers this job to be stopped. + ''; + }; + + preStart = mkOption { + type = types.string; + default = ""; + description = '' + Shell commands executed before the job is started + (i.e. before the exec command is run). + ''; + }; + + exec = mkOption { + type = types.string; + default = ""; + description = '' + Command to start the job. + ''; + }; + + environment = mkOption { + type = types.attrs; + default = {}; + example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; }; + description = '' + Environment variables passed to the job's processes. + ''; + }; + }; };