From 9943e0762e1589e37c3653c3812967f303225277 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 12 Oct 2009 17:09:38 +0000 Subject: [PATCH] * Update some more modules. svn path=/nixos/trunk/; revision=17763 --- modules/rename.nix | 5 +- modules/services/databases/postgresql.nix | 21 ++--- modules/services/misc/gpsd.nix | 8 +- modules/services/misc/synergy.nix | 2 +- modules/services/networking/gnunet.nix | 2 +- modules/services/networking/ifplugd.nix | 26 +++--- modules/services/networking/ntpd.nix | 32 +++---- modules/services/system/uptimed.nix | 26 +++--- .../web-servers/apache-httpd/default.nix | 83 +++++++++---------- modules/system/upstart/tools.nix | 36 -------- modules/system/upstart/upstart.nix | 22 +---- 11 files changed, 93 insertions(+), 170 deletions(-) delete mode 100644 modules/system/upstart/tools.nix diff --git a/modules/rename.nix b/modules/rename.nix index 05d278bd3e7..a3b40da4213 100644 --- a/modules/rename.nix +++ b/modules/rename.nix @@ -71,10 +71,7 @@ in zipModules ([] ++ rename obsolete "boot.bootMount" to "boot.loader.grub.bootDevice" ++ rename obsolete "boot.grubSplashImage" to "boot.loader.grub.splashImage" -# jobs -++ rename obsolete "services.extraJobs" to "jobs" - -# kde +# KDE ++ rename deprecated "kde.extraPackages" to "environment.kdePackages" diff --git a/modules/services/databases/postgresql.nix b/modules/services/databases/postgresql.nix index 1fb11244768..207701f1355 100644 --- a/modules/services/databases/postgresql.nix +++ b/modules/services/databases/postgresql.nix @@ -113,27 +113,24 @@ in environment.systemPackages = [postgresql]; - jobs = singleton { - name = "postgresql"; + jobAttrs.postgresql = + { description = "PostgreSQL server"; - job = '' - description "PostgreSQL server" + startOn = "${startDependency}/started"; + stopOn = "shutdown"; - start on ${startDependency}/started - stop on shutdown - - start script + preStart = + '' if ! test -e ${cfg.dataDir}; then mkdir -m 0700 -p ${cfg.dataDir} chown -R postgres ${cfg.dataDir} ${run} -c '${postgresql}/bin/initdb -D ${cfg.dataDir} -U root' fi cp -f ${pkgs.writeText "pg_hba.conf" cfg.authentication} ${cfg.dataDir}/pg_hba.conf - end script + ''; - respawn ${run} -c '${postgresql}/bin/postgres -D ${cfg.dataDir} ${toString flags}' - ''; - }; + exec = "${run} -c '${postgresql}/bin/postgres -D ${cfg.dataDir} ${toString flags}'"; + }; }; diff --git a/modules/services/misc/gpsd.nix b/modules/services/misc/gpsd.nix index b4cc58c3094..ba2d550f461 100644 --- a/modules/services/misc/gpsd.nix +++ b/modules/services/misc/gpsd.nix @@ -93,10 +93,10 @@ in exec = '' - respawn ${pkgs.gpsd}/sbin/gpsd -D "${toString cfg.debugLevel}" \ - -S "${toString cfg.port}" \ - ${if cfg.readonly then "-b" else ""} \ - "${cfg.device}" + ${pkgs.gpsd}/sbin/gpsd -D "${toString cfg.debugLevel}" \ + -S "${toString cfg.port}" \ + ${if cfg.readonly then "-b" else ""} \ + "${cfg.device}" ''; }; diff --git a/modules/services/misc/synergy.nix b/modules/services/misc/synergy.nix index a7df38f239d..88226755e66 100644 --- a/modules/services/misc/synergy.nix +++ b/modules/services/misc/synergy.nix @@ -94,7 +94,7 @@ in exec = '' - respawn ${pkgs.synergy}/bin/synergys -c ${cfgS.configFile} \ + ${pkgs.synergy}/bin/synergys -c ${cfgS.configFile} \ -f ${if cfgS.address == "" then "" else "-a ${cfgS.address}"} \ ${if cfgS.screenName == "" then "" else "-n ${cfgS.screenName}" } ''; diff --git a/modules/services/networking/gnunet.nix b/modules/services/networking/gnunet.nix index 05956f74612..4f9723fc304 100644 --- a/modules/services/networking/gnunet.nix +++ b/modules/services/networking/gnunet.nix @@ -205,7 +205,7 @@ in exec = '' - respawn ${pkgs.gnunet}/bin/gnunetd \ + ${pkgs.gnunet}/bin/gnunetd \ ${if debug then "--debug" else "" } \ --user="gnunetd" \ --config="${configFile}" \ diff --git a/modules/services/networking/ifplugd.nix b/modules/services/networking/ifplugd.nix index 9a08bba05e5..021e7f8fecf 100644 --- a/modules/services/networking/ifplugd.nix +++ b/modules/services/networking/ifplugd.nix @@ -1,7 +1,8 @@ {pkgs, config, ...}: +with pkgs.lib; + let - inherit (pkgs.lib) mkOption mkIf; inherit (pkgs) ifplugd; @@ -54,20 +55,19 @@ in config = mkIf config.networking.interfaceMonitor.enable { - jobs = pkgs.lib.singleton { - name = "ifplugd"; + jobAttrs.ifplugd = + { description = "Network interface connectivity monitor"; - job = '' - description "Network interface connectivity monitor" + startOn = "network-interfaces/started"; + stopOn = "network-interfaces/stop"; - start on network-interfaces/started - stop on network-interfaces/stop - - respawn ${ifplugd}/sbin/ifplugd --no-daemon --no-startup --no-shutdown \ - ${if config.networking.interfaceMonitor.beep then "" else "--no-beep"} \ - --run ${plugScript} - ''; - }; + exec = + '' + ${ifplugd}/sbin/ifplugd --no-daemon --no-startup --no-shutdown \ + ${if config.networking.interfaceMonitor.beep then "" else "--no-beep"} \ + --run ${plugScript} + ''; + }; environment.systemPackages = [ifplugd]; diff --git a/modules/services/networking/ntpd.nix b/modules/services/networking/ntpd.nix index e4b3432abd9..711682c9dce 100644 --- a/modules/services/networking/ntpd.nix +++ b/modules/services/networking/ntpd.nix @@ -1,9 +1,9 @@ -{pkgs, config, ...}: +{ config, pkgs, ... }: + +with pkgs.lib; let - inherit (pkgs.lib) mkOption mkIf singleton; - inherit (pkgs) ntp; stateDir = "/var/lib/ntp"; @@ -70,19 +70,14 @@ in home = stateDir; }; - jobs = singleton { + jobAttrs.ntpd = + { description = "NTP daemon"; - name = "ntpd"; - - job = '' - description "NTP daemon" - - start on ip-up - stop on ip-down - stop on shutdown - - start script + startOn = "ip-up"; + stopOn = "ip-down"; + preStart = + '' mkdir -m 0755 -p ${stateDir} chown ${ntpUser} ${stateDir} @@ -95,13 +90,10 @@ in # phase. Thus a hanging ntpd job can block system # shutdown. # ${ntp}/bin/ntpd -q -g ${ntpFlags} + ''; - end script - - respawn ${ntp}/bin/ntpd -g -n ${ntpFlags} - ''; - - }; + exec = "${ntp}/bin/ntpd -g -n ${ntpFlags}"; + }; }; diff --git a/modules/services/system/uptimed.nix b/modules/services/system/uptimed.nix index 9dd251a2821..259363024fc 100644 --- a/modules/services/system/uptimed.nix +++ b/modules/services/system/uptimed.nix @@ -39,6 +39,7 @@ in ###### implementation config = mkIf config.services.uptimed.enable { + environment.systemPackages = [ uptimed ]; users.extraUsers = singleton @@ -48,18 +49,14 @@ in home = stateDir; }; - jobs = singleton { + jobAttrs.uptimed = + { description = "Uptimed daemon"; - name = "uptimed"; - - job = '' - description "Uptimed daemon" - - start on startup - stop on shutdown - - start script + startOn = "startup"; + stopOn = "shutdown"; + preStart = + '' mkdir -m 0755 -p ${stateDir} chown ${uptimedUser} ${stateDir} @@ -69,13 +66,10 @@ in if ! test -f ${stateDir}/bootid ; then ${uptimed}/sbin/uptimed -b fi + ''; - end script - - respawn ${uptimed}/sbin/uptimed ${uptimedFlags} - ''; - - }; + exec = "${uptimed}/sbin/uptimed ${uptimedFlags}"; + }; }; diff --git a/modules/services/web-servers/apache-httpd/default.nix b/modules/services/web-servers/apache-httpd/default.nix index 77a724f1e46..6470b64d6be 100644 --- a/modules/services/web-servers/apache-httpd/default.nix +++ b/modules/services/web-servers/apache-httpd/default.nix @@ -559,59 +559,54 @@ in environment.systemPackages = [httpd] ++ concatMap (svc: svc.extraPath) allSubservices; - jobs = singleton { - name = "httpd"; + jobAttrs.httpd = + { # Statically verify the syntactic correctness of the generated + # httpd.conf. !!! this is impure! It doesn't just check for + # syntax, but also whether the Apache user/group exist, + # whether SSL keys exist, etc. + buildHook = + '' + echo + echo '=== Checking the generated Apache configuration file ===' + ${httpd}/bin/httpd -f ${httpdConf} -t || true + ''; - # Statically verify the syntactic correctness of the generated - # httpd.conf. !!! this is impure! It doesn't just check for - # syntax, but also whether the Apache user/group exist, whether SSL - # keys exist, etc. - buildHook = '' - echo - echo '=== Checking the generated Apache configuration file ===' - ${httpd}/bin/httpd -f ${httpdConf} -t || true - ''; + description = "Apache HTTPD"; - job = '' - description "Apache HTTPD" + startOn = "${startingDependency}/started"; + stopOn = "shutdown"; - start on ${startingDependency}/started - stop on shutdown + environment = + { # !!! This should be added in test-instrumentation.nix. It + # shouldn't hurt though, since packages usually aren't built + # with coverage enabled. + GCOV_PREFIX = "/tmp/coverage-data"; - start script - mkdir -m 0700 -p ${mainCfg.stateDir} - mkdir -m 0700 -p ${mainCfg.logDir} + PATH = "${pkgs.coreutils}/bin:${pkgs.gnugrep}/bin:${concatStringsSep ":" (concatMap (svc: svc.extraServerPath) allSubservices)}"; + } // (listToAttrs (concatMap (svc: svc.globalEnvVars) allSubservices)); - # Get rid of old semaphores. These tend to accumulate across - # server restarts, eventually preventing it from restarting - # succesfully. - for i in $(${pkgs.utillinux}/bin/ipcs -s | grep ' ${mainCfg.user} ' | cut -f2 -d ' '); do - ${pkgs.utillinux}/bin/ipcrm -s $i - done + preStart = + '' + mkdir -m 0700 -p ${mainCfg.stateDir} + mkdir -m 0700 -p ${mainCfg.logDir} - # Run the startup hooks for the subservices. - for i in ${toString (map (svn: svn.startupScript) allSubservices)}; do - echo Running Apache startup hook $i... - $i - done - end script + # Get rid of old semaphores. These tend to accumulate across + # server restarts, eventually preventing it from restarting + # succesfully. + for i in $(${pkgs.utillinux}/bin/ipcs -s | grep ' ${mainCfg.user} ' | cut -f2 -d ' '); do + ${pkgs.utillinux}/bin/ipcrm -s $i + done - ${ - let f = {name, value}: "env ${name}=${value}\n"; - in concatMapStrings f (concatMap (svc: svc.globalEnvVars) allSubservices) - } + # Run the startup hooks for the subservices. + for i in ${toString (map (svn: svn.startupScript) allSubservices)}; do + echo Running Apache startup hook $i... + $i + done + ''; - # !!! This should be added in test-instrumentation.nix. It - # shouldn't hurt though, since packages usually aren't built - # with coverage enabled. - env GCOV_PREFIX=/tmp/coverage-data + exec = "${httpd}/bin/httpd -f ${httpdConf} -DNO_DETACH"; + }; - env PATH=${pkgs.coreutils}/bin:${pkgs.gnugrep}/bin:${concatStringsSep ":" (concatMap (svc: svc.extraServerPath) allSubservices)} - - respawn ${httpd}/bin/httpd -f ${httpdConf} -DNO_DETACH - ''; - }; - }; } diff --git a/modules/system/upstart/tools.nix b/modules/system/upstart/tools.nix deleted file mode 100644 index e2adbd1d841..00000000000 --- a/modules/system/upstart/tools.nix +++ /dev/null @@ -1,36 +0,0 @@ -# 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; - }; - }; -} diff --git a/modules/system/upstart/upstart.nix b/modules/system/upstart/upstart.nix index f55c7ddcf3d..f84d98ff873 100644 --- a/modules/system/upstart/upstart.nix +++ b/modules/system/upstart/upstart.nix @@ -5,11 +5,11 @@ with pkgs.lib; let # From a job description, generate an Upstart job file. - makeJob = job@{buildHook ? "", ...}: + makeJob = job: let - jobText = if job.job != "" then job.job else + jobText = '' # Upstart job `${job.name}'. This is a generated file. Do not edit. @@ -66,7 +66,7 @@ let in pkgs.runCommand ("upstart-" + job.name) - { inherit buildHook; inherit jobText; } + { inherit (job) buildHook; inherit jobText; } '' eval "$buildHook" ensureDir $out/etc/event.d @@ -116,22 +116,6 @@ let ''; }; - job = mkOption { - default = ""; - type = types.string; - example = - '' - 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" - ''; - description = '' - Contents of the Upstart job. - ''; - }; - buildHook = mkOption { type = types.string; default = "true";