summary refs log tree commit diff
path: root/pkgs/lib/default.nix
diff options
context:
space:
mode:
authorMarc Weber <marco-oweber@gmx.de>2008-12-02 12:26:43 +0000
committerMarc Weber <marco-oweber@gmx.de>2008-12-02 12:26:43 +0000
commit429df4f86447c3b57d6d11079e4a8fb68713196f (patch)
treeb46539e472cf7bf6c4de55ef165d1dbf923603f9 /pkgs/lib/default.nix
parent570a103136cef7180a681d0c550fa9149488ccbc (diff)
downloadnixlib-429df4f86447c3b57d6d11079e4a8fb68713196f.tar
nixlib-429df4f86447c3b57d6d11079e4a8fb68713196f.tar.gz
nixlib-429df4f86447c3b57d6d11079e4a8fb68713196f.tar.bz2
nixlib-429df4f86447c3b57d6d11079e4a8fb68713196f.tar.lz
nixlib-429df4f86447c3b57d6d11079e4a8fb68713196f.tar.xz
nixlib-429df4f86447c3b57d6d11079e4a8fb68713196f.tar.zst
nixlib-429df4f86447c3b57d6d11079e4a8fb68713196f.zip
added prepareDerivationArgs
svn path=/nixpkgs/trunk/; revision=13545
Diffstat (limited to 'pkgs/lib/default.nix')
-rw-r--r--pkgs/lib/default.nix55
1 files changed, 55 insertions, 0 deletions
diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix
index 137d5dee5011..01aecfeae8cd 100644
--- a/pkgs/lib/default.nix
+++ b/pkgs/lib/default.nix
@@ -725,6 +725,61 @@ rec {
           then r ++ [ (  nv attr ( f (__getAttr attr attrs) ) ) ] else r ) []
       subset_attr_names );
 
+  # prepareDerivationArgs tries to make writing configurable derivations easier
+  # example:
+  #  prepareDerivationArgs {
+  #    mergeAttrBy = {
+  #       myScript = x : y : x ++ "\n" ++ y;
+  #    };
+  #    cfg = {
+  #      readlineSupport = true;
+  #    };
+  #    flags = {
+  #      readline = {
+  #        set = {
+  #           configureFlags = [ "--with-compiler=${compiler}" ];
+  #           buildInputs = [ compiler ];
+  #           pass = { inherit compiler; READLINE=1; };
+  #           assertion = compiler.dllSupport;
+  #           myScript = "foo";
+  #        };
+  #        unset = { configureFlags = ["--without-compiler"]; };
+  #      };
+  #    };
+  #    src = ...
+  #    buildPhase = '' ... '';
+  #    name = ...
+  #    myScript = "bar";
+  #  };
+  # if you don't have need for unset you can omit the surrounding set = { .. } attr
+  # all attrs except flags cfg and mergeAttrBy will be merged with the
+  # additional data from flags depending on config settings
+  # It's used in composableDerivation in all-packages.nix. It's also used
+  # heavily in the new python and libs implementation
+  prepareDerivationArgs = args:
+    let args2 = { cfg = {}; flags = {}; } // args;
+        flagName = name : "${name}Support";
+        cfgWithDefaults = (listToAttrs (map (n : nv (flagName n) false) (attrNames args2.flags)))
+                          // args2.cfg;
+        opts = flattenAttrs (mapAttrs (a : v :
+                let v2 = if (v ? set || v ? unset) then v else { set = v; };
+                    n = if (__getAttr (flagName a) cfgWithDefaults) then "set" else "unset";
+                    attr = maybeAttr n {} v2; in
+                if (maybeAttr "assertion" true attr)
+                  then attr
+                  else throw "assertion of flag ${a} of derivation ${args.name} failed"
+               ) args2.flags );
+    in removeAttrs
+      (fold (mergeOrApply mergeAttrByFunc) {} ([args] ++ opts))
+      ["flags" "cfg" "mergeAttrBy" "fixed" ]; # fixed may be passed as fix argument or such
+  # supportFlag functions for convinience
+  sFlagEnable = { name, buildInputs ? [], propagatedBuildInputs ? [] } : {
+      set = { configureFlags = "--enable-${name}"; inherit buildInputs; inherit propagatedBuildInputs; };
+      unset = { configureFlags = "--disable-${name}"; };
+    };
+
+
+
 # Marc 2nd proposal: (not everything has been tested in detail yet..)
 # depreceated because it's too complicated. use prepareDerivationArgs instead