summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Ericson <Ericson2314@Yahoo.com>2017-04-17 16:48:10 -0400
committerJohn Ericson <Ericson2314@Yahoo.com>2017-04-17 17:04:04 -0400
commit85aa5005af530fef199cc41148e374e54d70e01e (patch)
tree296a184cc5e710e197f45a91babb107bf8509eae
parentf3055a3c508b6ff3e926ece201887467dc2b5d73 (diff)
downloadnixpkgs-85aa5005af530fef199cc41148e374e54d70e01e.tar
nixpkgs-85aa5005af530fef199cc41148e374e54d70e01e.tar.gz
nixpkgs-85aa5005af530fef199cc41148e374e54d70e01e.tar.bz2
nixpkgs-85aa5005af530fef199cc41148e374e54d70e01e.tar.lz
nixpkgs-85aa5005af530fef199cc41148e374e54d70e01e.tar.xz
nixpkgs-85aa5005af530fef199cc41148e374e54d70e01e.tar.zst
nixpkgs-85aa5005af530fef199cc41148e374e54d70e01e.zip
Introduce `mapNullable` into lib and use it in a few places
Also simply some configure flag logic my grep also alerted me too.
-rw-r--r--lib/trivial.nix3
-rw-r--r--nixos/modules/services/monitoring/graphite.nix2
-rw-r--r--nixos/modules/services/monitoring/prometheus/default.nix2
-rw-r--r--pkgs/development/libraries/wiredtiger/default.nix7
-rw-r--r--pkgs/os-specific/linux/nvidia-x11/generic.nix2
-rw-r--r--pkgs/servers/shishi/default.nix7
-rw-r--r--pkgs/tools/filesystems/ceph/generic.nix9
7 files changed, 18 insertions, 14 deletions
diff --git a/lib/trivial.nix b/lib/trivial.nix
index 40499b2b509..b7b9d25922a 100644
--- a/lib/trivial.nix
+++ b/lib/trivial.nix
@@ -108,6 +108,9 @@ rec {
   # Flip the order of the arguments of a binary function.
   flip = f: a: b: f b a;
 
+  # Apply function if argument is non-null
+  mapNullable = f: a: if isNull a then a else f a;
+
   # Pull in some builtins not included elsewhere.
   inherit (builtins)
     pathExists readFile isBool isFunction
diff --git a/nixos/modules/services/monitoring/graphite.nix b/nixos/modules/services/monitoring/graphite.nix
index c5352e5887d..98931e65bb5 100644
--- a/nixos/modules/services/monitoring/graphite.nix
+++ b/nixos/modules/services/monitoring/graphite.nix
@@ -4,7 +4,7 @@ with lib;
 
 let
   cfg = config.services.graphite;
-  writeTextOrNull = f: t: if t == null then null else pkgs.writeTextDir f t;
+  writeTextOrNull = f: t: mapNullable (pkgs.writeTextDir f) t;
 
   dataDir = cfg.dataDir;
 
diff --git a/nixos/modules/services/monitoring/prometheus/default.nix b/nixos/modules/services/monitoring/prometheus/default.nix
index cf9deccbffe..5c4a48a7db4 100644
--- a/nixos/modules/services/monitoring/prometheus/default.nix
+++ b/nixos/modules/services/monitoring/prometheus/default.nix
@@ -134,7 +134,7 @@ let
           };
         });
         default = null;
-        apply = x: if x == null then null else _filter x;
+        apply = x: mapNullable _filter x;
         description = ''
           Optional http login credentials for metrics scraping.
         '';
diff --git a/pkgs/development/libraries/wiredtiger/default.nix b/pkgs/development/libraries/wiredtiger/default.nix
index 347686014d1..e4b95fc1cb9 100644
--- a/pkgs/development/libraries/wiredtiger/default.nix
+++ b/pkgs/development/libraries/wiredtiger/default.nix
@@ -7,9 +7,10 @@
 
 with stdenv.lib;
 let
-  mkFlag = trueStr: falseStr: cond: name: val:
-    if cond == null then null else
-      "--${if cond != false then trueStr else falseStr}${name}${if val != null && cond != false then "=${val}" else ""}";
+  mkFlag = trueStr: falseStr: cond: name: val: "--"
+    + (if cond then trueStr else falseStr)
+    + name
+    + optionalString (val != null && cond != false) "=${val}";
   mkEnable = mkFlag "enable-" "disable-";
   mkWith = mkFlag "with-" "without-";
   mkOther = mkFlag "" "" true;
diff --git a/pkgs/os-specific/linux/nvidia-x11/generic.nix b/pkgs/os-specific/linux/nvidia-x11/generic.nix
index 4573766b78b..d6d1daaf3ce 100644
--- a/pkgs/os-specific/linux/nvidia-x11/generic.nix
+++ b/pkgs/os-specific/linux/nvidia-x11/generic.nix
@@ -73,7 +73,7 @@ let
         withGtk2 = preferGtk2;
         withGtk3 = !preferGtk2;
       };
-      persistenced = if persistencedSha256 == null then null else callPackage (import ./persistenced.nix self persistencedSha256) { };
+      persistenced = mapNullable (hash: callPackage (import ./persistenced.nix self hash) { }) persistencedSha256;
     };
 
     meta = with stdenv.lib; {
diff --git a/pkgs/servers/shishi/default.nix b/pkgs/servers/shishi/default.nix
index 3e340ba7df4..535571f46e2 100644
--- a/pkgs/servers/shishi/default.nix
+++ b/pkgs/servers/shishi/default.nix
@@ -6,9 +6,10 @@
 }:
 
 let
-  mkFlag = trueStr: falseStr: cond: name: val:
-    if cond == null then null else
-      "--${if cond != false then trueStr else falseStr}${name}${if val != null && cond != false then "=${val}" else ""}";
+  mkFlag = trueStr: falseStr: cond: name: val: "--"
+    + (if cond then trueStr else falseStr)
+    + name
+    + stdenv.lib.optionalString (val != null && cond != false) "=${val}";
   mkEnable = mkFlag "enable-" "disable-";
   mkWith = mkFlag "with-" "without-";
   mkOther = mkFlag "" "" true;
diff --git a/pkgs/tools/filesystems/ceph/generic.nix b/pkgs/tools/filesystems/ceph/generic.nix
index d21d790dac8..e4c8b0f33bc 100644
--- a/pkgs/tools/filesystems/ceph/generic.nix
+++ b/pkgs/tools/filesystems/ceph/generic.nix
@@ -31,11 +31,10 @@ with stdenv;
 with stdenv.lib;
 let
   inherit (python2Packages) python;
-  mkFlag = trueStr: falseStr: cond: name: val:
-    if cond == null then null else
-      "--${if cond != false then trueStr else falseStr}${name}"
-      + "${if val != null && cond != false then "=${val}" else ""}";
-
+  mkFlag = trueStr: falseStr: cond: name: val: "--"
+    + (if cond then trueStr else falseStr)
+    + name
+    + optionalString (val != null && cond != false) "=${val}";
   mkEnable = mkFlag "enable-" "disable-";
   mkWith = mkFlag "with-" "without-";
   mkOther = mkFlag "" "" true;