From 244cf195c88acff952ff0304c8e48a109f4b6754 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 30 Oct 2013 18:30:23 +0100 Subject: [PATCH] Use the "assertions" option instead of mkAssert --- .../services/databases/4store-endpoint.nix | 17 ++++++----- nixos/modules/services/databases/4store.nix | 17 ++++++----- .../modules/services/networking/openfire.nix | 12 ++++---- nixos/modules/services/security/tor.nix | 18 ++++++------ nixos/modules/services/x11/xserver.nix | 28 ++++++++++--------- 5 files changed, 52 insertions(+), 40 deletions(-) diff --git a/nixos/modules/services/databases/4store-endpoint.nix b/nixos/modules/services/databases/4store-endpoint.nix index 7b03b4d8f1dc..7872ea2dc6a3 100644 --- a/nixos/modules/services/databases/4store-endpoint.nix +++ b/nixos/modules/services/databases/4store-endpoint.nix @@ -24,12 +24,12 @@ with pkgs.lib; }; listenAddress = mkOption { - default = null; + default = null; description = "IP address to listen on."; }; port = mkOption { - default = 8080; + default = 8080; description = "port to listen on."; }; @@ -45,9 +45,12 @@ with pkgs.lib; ###### implementation - config = mkIf cfg.enable ( - mkAssert (cfg.enable -> cfg.database != "") - "Must specify database name" { + config = mkIf cfg.enable { + + assertions = singleton + { assertion = cfg.enable -> cfg.database != ""; + message = "Must specify 4Store database name"; + }; users.extraUsers = singleton { name = endpointUser; @@ -63,10 +66,10 @@ with pkgs.lib; startOn = "filesystem"; exec = '' - ${run} '${pkgs.rdf4store}/bin/4s-httpd -D ${cfg.options} ${if cfg.listenAddress!=null then "-H ${cfg.listenAddress}" else "" } -p ${toString cfg.port} ${cfg.database}' + ${run} '${pkgs.rdf4store}/bin/4s-httpd -D ${cfg.options} ${if cfg.listenAddress!=null then "-H ${cfg.listenAddress}" else "" } -p ${toString cfg.port} ${cfg.database}' ''; }; - }); + }; } diff --git a/nixos/modules/services/databases/4store.nix b/nixos/modules/services/databases/4store.nix index 14990e92ea30..412d14b050cb 100644 --- a/nixos/modules/services/databases/4store.nix +++ b/nixos/modules/services/databases/4store.nix @@ -36,9 +36,12 @@ with pkgs.lib; ###### implementation - config = mkIf cfg.enable ( - mkAssert (cfg.enable -> cfg.database != "") - "Must specify database name" { + config = mkIf cfg.enable { + + assertions = singleton + { assertion = cfg.enable -> cfg.database != ""; + message = "Must specify 4Store database name."; + }; users.extraUsers = singleton { name = fourStoreUser; @@ -56,16 +59,16 @@ with pkgs.lib; preStart = '' mkdir -p ${stateDir}/ chown ${fourStoreUser} ${stateDir} - if ! test -e "${stateDir}/${cfg.database}"; then - ${run} -c '${pkgs.rdf4store}/bin/4s-backend-setup ${cfg.database}' + if ! test -e "${stateDir}/${cfg.database}"; then + ${run} -c '${pkgs.rdf4store}/bin/4s-backend-setup ${cfg.database}' fi ''; exec = '' - ${run} -c '${pkgs.rdf4store}/bin/4s-backend -D ${cfg.options} ${cfg.database}' + ${run} -c '${pkgs.rdf4store}/bin/4s-backend -D ${cfg.options} ${cfg.database}' ''; }; - }); + }; } diff --git a/nixos/modules/services/networking/openfire.nix b/nixos/modules/services/networking/openfire.nix index d5c18c0675cf..b2efb5e9c123 100644 --- a/nixos/modules/services/networking/openfire.nix +++ b/nixos/modules/services/networking/openfire.nix @@ -40,10 +40,12 @@ in ###### implementation - config = mkIf config.services.openfire.enable ( - mkAssert (!(config.services.openfire.usePostgreSQL -> config.services.postgresql.enable)) " - openfire assertion failed - " { + config = mkIf config.services.openfire.enable { + + assertions = singleton + { assertion = !(config.services.openfire.usePostgreSQL -> config.services.postgresql.enable); + message = "OpenFire assertion failed."; + }; jobs.openfire = { description = "OpenFire XMPP server"; @@ -65,6 +67,6 @@ in ''; # */ }; - }); + }; } diff --git a/nixos/modules/services/security/tor.nix b/nixos/modules/services/security/tor.nix index 2dafb4595c63..e70eb8511a63 100644 --- a/nixos/modules/services/security/tor.nix +++ b/nixos/modules/services/security/tor.nix @@ -53,9 +53,9 @@ in ''; }; - socksListenAddressFaster = mkOption { + socksListenAddressFaster = mkOption { default = "127.0.0.1:9063"; - description = '' + description = '' Same as socksListenAddress but uses weaker circuit isolation to provide performance suitable for a web browser. ''; @@ -227,10 +227,12 @@ in ###### implementation - 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 - " { + config = mkIf (cfg.client.enable || cfg.relay.enable) { + + assertions = singleton + { 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"; + }; users.extraUsers = singleton { name = torUser; @@ -270,7 +272,7 @@ in '' + optionalString cfg.client.enable '' SOCKSPort ${cfg.client.socksListenAddress} IsolateDestAddr - SOCKSPort ${cfg.client.socksListenAddressFaster} + SOCKSPort ${cfg.client.socksListenAddressFaster} ${opt "SocksPolicy" cfg.client.socksPolicy} '' + optionalString cfg.relay.enable '' @@ -316,6 +318,6 @@ in # Extra config goes here ''; - }); + }; } diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix index caa0839dbb75..da94f7cad53a 100644 --- a/nixos/modules/services/x11/xserver.nix +++ b/nixos/modules/services/x11/xserver.nix @@ -108,17 +108,6 @@ let ''; # */ }; - - checkAgent = mkAssert (!(cfg.startOpenSSHAgent && cfg.startGnuPGAgent)) - '' - The OpenSSH agent and GnuPG agent cannot be started both. - Choose between `startOpenSSHAgent' and `startGnuPGAgent'. - ''; - - checkPolkit = mkAssert config.security.polkit.enable - "X11 requires Polkit to be enabled (‘security.polkit.enable = true’)."; - - in { @@ -425,7 +414,20 @@ in ###### implementation - config = mkIf cfg.enable (checkAgent (checkPolkit { + config = mkIf cfg.enable { + + assertions = + [ { assertion = !(cfg.startOpenSSHAgent && cfg.startGnuPGAgent); + message = + '' + The OpenSSH agent and GnuPG agent cannot be started both. + Choose between `startOpenSSHAgent' and `startGnuPGAgent'. + ''; + } + { assertion = config.security.polkit.enable; + message = "X11 requires Polkit to be enabled (‘security.polkit.enable = true’)."; + } + ]; boot.extraModulePackages = optional (elem "nvidia" driverNames) kernelPackages.nvidia_x11 ++ @@ -669,7 +671,7 @@ in ${xrandrMonitorSections} ''; - })); + }; }