Skip to content

Commit

Permalink
Introduce mapNullable into lib and use it in a few places
Browse files Browse the repository at this point in the history
Also simply some configure flag logic my grep also alerted me too.
  • Loading branch information
Ericson2314 committed Apr 17, 2017
1 parent f3055a3 commit 85aa500
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
3 changes: 3 additions & 0 deletions lib/trivial.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/monitoring/graphite.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/monitoring/prometheus/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
'';
Expand Down
7 changes: 4 additions & 3 deletions pkgs/development/libraries/wiredtiger/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/nvidia-x11/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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; {
Expand Down
7 changes: 4 additions & 3 deletions pkgs/servers/shishi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions pkgs/tools/filesystems/ceph/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 85aa500

Please sign in to comment.