From 96fc9379bab8430c234f87ca81404a7a82a47f5e Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Wed, 30 Mar 2011 17:52:34 +0000 Subject: [PATCH] Convert assertion option into mkAssert. svn path=/nixos/trunk/; revision=26614 --- .../network-filesystems/nfs-kernel.nix | 13 ++++--- modules/services/networking/openfire.nix | 12 +++---- modules/services/security/tor.nix | 12 +++---- modules/services/x11/xfs.nix | 12 +++---- modules/services/x11/xserver.nix | 34 ++++++++----------- modules/tasks/tty-backgrounds.nix | 14 ++++---- modules/testing/test-instrumentation.nix | 13 +++---- 7 files changed, 47 insertions(+), 63 deletions(-) diff --git a/modules/services/network-filesystems/nfs-kernel.nix b/modules/services/network-filesystems/nfs-kernel.nix index 290622b09977..bc828d5bbb86 100644 --- a/modules/services/network-filesystems/nfs-kernel.nix +++ b/modules/services/network-filesystems/nfs-kernel.nix @@ -74,14 +74,13 @@ in ###### implementation - config = { + config = + mkAssert + (cfg.client.enable || cfg.server.enable -> config.services.portmap.enable) " + Please enable portmap (services.portmap.enable) to use nfs-kernel. + " { - services.portmap.enable = cfg.client.enable || cfg.server.enable; - - assertions = mkIf (cfg.client.enable || cfg.server.enable) (singleton - { assertion = cfg.client.enable || cfg.server.enable; - message = "Please enable portmap (services.portmap.enable) to use nfs-kernel."; - }); + services.portmap.enable = mkAlways (cfg.client.enable || cfg.server.enable); environment.etc = mkIf cfg.server.enable (singleton { source = exports; diff --git a/modules/services/networking/openfire.nix b/modules/services/networking/openfire.nix index a46b4fa42947..02e6b4c9aaa8 100644 --- a/modules/services/networking/openfire.nix +++ b/modules/services/networking/openfire.nix @@ -42,12 +42,10 @@ in ###### implementation - config = mkIf config.services.openfire.enable { - - assertions = singleton - { assertion = !(config.services.openfire.usePostgreSQL -> config.services.postgresql.enable); - message = "openfire assertion failed"; - }; + config = mkIf config.services.openfire.enable ( + mkAssert (!(config.services.openfire.usePostgreSQL -> config.services.postgresql.enable)) " + openfire assertion failed + " { jobs.openfire = { description = "OpenFire XMPP server"; @@ -69,6 +67,6 @@ in ''; # */ }; - }; + }); } diff --git a/modules/services/security/tor.nix b/modules/services/security/tor.nix index 65b7abafd6a2..6e1b2838ead6 100644 --- a/modules/services/security/tor.nix +++ b/modules/services/security/tor.nix @@ -218,12 +218,10 @@ in ###### implementation - config = mkIf (cfg.client.enable || cfg.relay.enable) { - - assertions = [ { - assertion = cfg.relay.enable -> !(cfg.relay.isBridge && cfg.relay.isExit); - message = "Can't be both an exit and a bridge relay at the same time"; - } ]; + config = mkIf (cfg.client.enable || cfg.relay.enable) ( + mkAssert (cfg.relay.enable -> !(cfg.relay.isBridge && cfg.relay.isExit)) " + Can't be both an exit and a bridge relay at the same time + " { users.extraUsers = singleton { name = torUser; @@ -308,6 +306,6 @@ in # Extra config goes here ''; - }; + }); } diff --git a/modules/services/x11/xfs.nix b/modules/services/x11/xfs.nix index f2b7108debc8..424e386b78b4 100644 --- a/modules/services/x11/xfs.nix +++ b/modules/services/x11/xfs.nix @@ -33,12 +33,10 @@ in ###### implementation - config = mkIf config.services.xfs.enable { - - assertions = singleton - { assertion = config.fonts.enableFontDir; - message = "Please enable fontDir (fonts.enableFontDir) to use xfs."; - }; + config = mkIf config.services.xfs.enable ( + mkAssert config.fonts.enableFontDir " + Please enable fontDir (fonts.enableFontDir) to use xfs. + " { jobs.xfs = { description = "X Font Server"; @@ -48,6 +46,6 @@ in exec = "${pkgs.xorg.xfs}/bin/xfs -config ${configFile}"; }; - }; + }); } diff --git a/modules/services/x11/xserver.nix b/modules/services/x11/xserver.nix index 02e15c0343b4..0eb19fc94558 100644 --- a/modules/services/x11/xserver.nix +++ b/modules/services/x11/xserver.nix @@ -328,23 +328,18 @@ in ###### implementation - config = mkIf cfg.enable { - - assertions = - [ { assertion = config.services.hal.enable == true; - message = "The X server needs HAL running. Set services.hal.enable to true"; - } - - { assertion = if cfg.startOpenSSHAgent - then !cfg.startGnuPGAgent - else (if cfg.startGnuPGAgent - then !cfg.startOpenSSHAgent - else true); - message = - "The OpenSSH agent and GnuPG agent cannot be started both. " + - "Choose between `startOpenSSHAgent' and `startGnuPGAgent'."; - } - ]; + config = mkIf cfg.enable ( + mkAssert (config.services.hal.enable == true) " + The X server needs HAL running. Set services.hal.enable to true + " ( + mkAssert (if cfg.startOpenSSHAgent + then !cfg.startGnuPGAgent + else (if cfg.startGnuPGAgent + then !cfg.startOpenSSHAgent + else true)) " + The OpenSSH agent and GnuPG agent cannot be started both. + Choose between `startOpenSSHAgent' and `startGnuPGAgent'. + " { boot.extraModulePackages = optional (elem "nvidia" driverNames) kernelPackages.nvidia_x11 ++ @@ -385,7 +380,8 @@ in environment.pathsToLink = [ "/etc/xdg" "/share/xdg" "/share/applications" "/share/icons" "/share/pixmaps" ]; - + + services.hal.enable = mkAlways cfg.enable; services.hal.packages = optional (elem "virtualbox" driverNames) kernelPackages.virtualboxGuestAdditions; jobs.xserver = @@ -538,6 +534,6 @@ in '')} ''; - }; + })); } diff --git a/modules/tasks/tty-backgrounds.nix b/modules/tasks/tty-backgrounds.nix index d376c6a4b894..b77c6b9acf75 100644 --- a/modules/tasks/tty-backgrounds.nix +++ b/modules/tasks/tty-backgrounds.nix @@ -82,13 +82,11 @@ in ###### implementation - config = mkIf config.services.ttyBackgrounds.enable { - - assertions = singleton - { assertion = kernelPackages.splashutils != null; - message = "The kernelPackages does not provide splashutils, as required by ttyBackgrounds. " + - "Either provide kernelPackages with splashutils, or disable ttyBackgrounds."; - }; + config = mkIf config.services.ttyBackgrounds.enable ( + mkAssert (kernelPackages.splashutils != null) " + The kernelPackages does not provide splashutils, as required by ttyBackgrounds. + Either provide kernelPackages with splashutils, or disable ttyBackgrounds. + " { services.ttyBackgrounds.specificThemes = singleton { tty = config.services.syslogd.tty; @@ -145,6 +143,6 @@ in ''; }; - }; + }); } diff --git a/modules/testing/test-instrumentation.nix b/modules/testing/test-instrumentation.nix index 4834df5f2523..991c5d263a5b 100644 --- a/modules/testing/test-instrumentation.nix +++ b/modules/testing/test-instrumentation.nix @@ -21,7 +21,11 @@ in { - config = { + config = + # Require a patch to the kernel to increase the 15s CIFS timeout. + mkAssert (config.boot.kernelPackages.kernel.features ? cifsTimeout) " + VM tests require that the kernel has the CIFS timeout patch. + " { jobs.backdoor = { startOn = "startup"; @@ -95,13 +99,6 @@ in networking.defaultGateway = mkOverride 150 ""; networking.nameservers = mkOverride 150 [ ]; - # Require a patch to the kernel to increase the 15s CIFS timeout. - assertions = - [ { assertion = config.boot.kernelPackages.kernel.features ? cifsTimeout; - message = "VM tests require that the kernel has the CIFS timeout patch."; - } - ]; - system.upstartEnvironment.GCOV_PREFIX = "/tmp/coverage-data"; };