summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorMarc Weber <marco-oweber@gmx.de>2007-08-19 17:24:05 +0000
committerMarc Weber <marco-oweber@gmx.de>2007-08-19 17:24:05 +0000
commit8f3a8b50066c7c8e0c71d7dbce7fe978a186e7f7 (patch)
tree3f70e6d9c5fbfcb270785a28d04d4ad62a07f7ce /pkgs
parentee347e49c177286ee879e5fb464a2d8fd9992f85 (diff)
downloadnixpkgs-8f3a8b50066c7c8e0c71d7dbce7fe978a186e7f7.tar
nixpkgs-8f3a8b50066c7c8e0c71d7dbce7fe978a186e7f7.tar.gz
nixpkgs-8f3a8b50066c7c8e0c71d7dbce7fe978a186e7f7.tar.bz2
nixpkgs-8f3a8b50066c7c8e0c71d7dbce7fe978a186e7f7.tar.lz
nixpkgs-8f3a8b50066c7c8e0c71d7dbce7fe978a186e7f7.tar.xz
nixpkgs-8f3a8b50066c7c8e0c71d7dbce7fe978a186e7f7.tar.zst
nixpkgs-8f3a8b50066c7c8e0c71d7dbce7fe978a186e7f7.zip
renamed chosenOptions to chooseOptionsByFlags and added support for optionals
(thus you don't need to write flag definitions, passing a dependency or not is enough)

svn path=/nixpkgs/trunk/; revision=9167
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/lib/default-unstable.nix16
1 files changed, 13 insertions, 3 deletions
diff --git a/pkgs/lib/default-unstable.nix b/pkgs/lib/default-unstable.nix
index e5df0d40ac6..ff50cbf3756 100644
--- a/pkgs/lib/default-unstable.nix
+++ b/pkgs/lib/default-unstable.nix
@@ -17,7 +17,6 @@ rec {
     if list == []
     then nul
     else op (head list) (fold op nul (tail list));
-
     
   # Concatenate a list of lists.
   concatLists =
@@ -198,6 +197,7 @@ rec {
   catAttrs = attr : l : fold ( s : l : if (__hasAttr attr s) then [(__getAttr attr s)] ++ l else l) [] l;
 
   flattenSet = set : map ( attr : __getAttr attr set) (__attrNames set);
+  mapIf = cond : f :  fold ( x : l : if (cond x) then [(f x)] ++ l else l) [];
 
 # Marc 2nd proposal: (not everything has been tested in detail yet..)
 # One example showing how to use mandatory dependencies [1], default flags [2], ..
@@ -218,7 +218,7 @@ rec {
     #    alternativeAddOn  = { cfgOption = "--enable-add-ons-alt"; blocks = ["addOns", "addOns2"]; };
     #    justAOption =  { };
     #  };
-    #  co = chosenOptions flagDescr args args.flags;
+    #  co = chooseOptionsByFlags flagDescr ["libpng", "libjpg"] args;
 
     #in args.stdenv.mkDerivation {
 
@@ -256,7 +256,17 @@ rec {
   #          flags = { flagName = true/ false for each attribute in flagDescr
   #                     ... }
            
-  chosenOptions = flagDescr : args : flags : 
+  # optionals is a list of dependency names. If passed as attribute in args they'll be automatically added
+  # to flags and flagDescr ( optionalName = { buildInputs = optionalName } )
+  chooseOptionsByFlags = flagDescr : optionals : args :
+    let givenOptionals = listToAttrs 
+        (mapIf ( a : (__hasAttr a args) ) 
+               ( x: av x { buildInputs = x; } ) 
+               optionals );
+        fd = flagDescr // givenOptionals;
+    in chooseOptionsByFlags2 fd args ( getAttr ["flags"] [] args ++ (__attrNames givenOptionals ) );
+
+  chooseOptionsByFlags2 = flagDescr : args : flags : 
     let   
         # helper function
         collectFlags = state : flags :