diff options
author | William A. Kennington III <william@wkennington.com> | 2015-05-22 12:59:21 -0700 |
---|---|---|
committer | William A. Kennington III <william@wkennington.com> | 2015-05-22 13:26:55 -0700 |
commit | 25a148fa196b944b3f134527da87e43d88c066f9 (patch) | |
tree | b75635c87759b11e52eba1bd7d02116257571b8a /lib/customisation.nix | |
parent | 50fa9d8eeab5e90e8d673c5d65a0af2a7c57b2fe (diff) | |
download | nixpkgs-25a148fa196b944b3f134527da87e43d88c066f9.tar nixpkgs-25a148fa196b944b3f134527da87e43d88c066f9.tar.gz nixpkgs-25a148fa196b944b3f134527da87e43d88c066f9.tar.bz2 nixpkgs-25a148fa196b944b3f134527da87e43d88c066f9.tar.lz nixpkgs-25a148fa196b944b3f134527da87e43d88c066f9.tar.xz nixpkgs-25a148fa196b944b3f134527da87e43d88c066f9.tar.zst nixpkgs-25a148fa196b944b3f134527da87e43d88c066f9.zip |
Refactor mkFlag / shouldUsePkg into the nixpkgs libraries
Diffstat (limited to 'lib/customisation.nix')
-rw-r--r-- | lib/customisation.nix | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/customisation.nix b/lib/customisation.nix index 91a25055df2..ca3dd4980da 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -158,4 +158,27 @@ rec { drv' = (lib.head outputsList).value; in lib.deepSeq drv' drv'; + + /* Tests whether a derivation can be used by the current platform + Returns the derivation if true, otherwise null. */ + shouldUsePkgSystem = system: pkg_: let pkg = (builtins.tryEval pkg_).value; + in if lib.any (x: x == system) (pkg.meta.platforms or []) + then pkg + else null; + + /* Returns a configure flag string in an autotools format + trueStr: Prepended when cond is true + falseStr: Prepended when cond is false + cond: The condition for the prepended string type and value + name: The flag name + val: The value of the flag only set when cond is true */ + 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 ""}"; + + /* Flag setting helpers for autotools like packages */ + mkEnable = mkFlag "enable-" "disable-"; + mkWith = mkFlag "with-" "without-"; + mkOther = mkFlag "" "" true; } |