diff options
author | Lluís Batlle i Rossell <viric@vicerveza.homeunix.net> | 2009-11-19 19:09:10 +0000 |
---|---|---|
committer | Lluís Batlle i Rossell <viric@vicerveza.homeunix.net> | 2009-11-19 19:09:10 +0000 |
commit | e85500987b7df503b37a127a5ea49a07f92e70f0 (patch) | |
tree | 5f66b5de9aadaf0ff3ba52c394dc0066114e11e2 /pkgs/lib | |
parent | 7ade207f6b75da0fde94cec621ac6d8fa6c3e586 (diff) | |
parent | 58f543f19f1a2eed8a46202b36a855836cfc9e0f (diff) | |
download | nixpkgs-e85500987b7df503b37a127a5ea49a07f92e70f0.tar nixpkgs-e85500987b7df503b37a127a5ea49a07f92e70f0.tar.gz nixpkgs-e85500987b7df503b37a127a5ea49a07f92e70f0.tar.bz2 nixpkgs-e85500987b7df503b37a127a5ea49a07f92e70f0.tar.lz nixpkgs-e85500987b7df503b37a127a5ea49a07f92e70f0.tar.xz nixpkgs-e85500987b7df503b37a127a5ea49a07f92e70f0.tar.zst nixpkgs-e85500987b7df503b37a127a5ea49a07f92e70f0.zip |
Merging from trunk. I had to do two manual merges, quite trivial I think.
svn path=/nixpkgs/branches/stdenv-updates/; revision=18472
Diffstat (limited to 'pkgs/lib')
-rw-r--r-- | pkgs/lib/attrsets.nix | 4 | ||||
-rw-r--r-- | pkgs/lib/customisation.nix | 61 | ||||
-rw-r--r-- | pkgs/lib/debug.nix | 7 | ||||
-rw-r--r-- | pkgs/lib/default.nix | 2 | ||||
-rw-r--r-- | pkgs/lib/maintainers.nix | 1 | ||||
-rw-r--r-- | pkgs/lib/misc.nix | 31 |
6 files changed, 71 insertions, 35 deletions
diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix index 4b2496c1987..4be944d8494 100644 --- a/pkgs/lib/attrsets.nix +++ b/pkgs/lib/attrsets.nix @@ -15,7 +15,7 @@ rec { /* Return an attribute from nested attribute sets. For instance ["x" "y"] applied to some set e returns e.x.y, if it exists. The - default value is returned otherwise. */ + default value is returned otherwise. */ attrByPath = attrPath: default: e: let attr = head attrPath; in @@ -200,7 +200,7 @@ rec { /* Does the same as the update operator '//' except that attributes are merged until the given pedicate is verified. The predicate should - except 3 arguments which are the path to reach the attribute, a part of + accept 3 arguments which are the path to reach the attribute, a part of the first attribute set and a part of the second attribute set. When the predicate is verified, the value of the first attribute set is replaced by the value of the second attribute set. diff --git a/pkgs/lib/customisation.nix b/pkgs/lib/customisation.nix new file mode 100644 index 00000000000..76d019a73c2 --- /dev/null +++ b/pkgs/lib/customisation.nix @@ -0,0 +1,61 @@ +let lib = import ./default.nix; in + +rec { + + + /* `overrideDerivation drv f' takes a derivation (i.e., the result + of a call to the builtin function `derivation') and returns a new + derivation in which the attributes of the original are overriden + according to the function `f'. The function `f' is called with + the original derivation attributes. + + `overrideDerivation' allows certain "ad-hoc" customisation + scenarios (e.g. in ~/.nixpkgs/config.nix). For instance, if you + want to "patch" the derivation returned by a package function in + Nixpkgs to build another version than what the function itself + provides, you can do something like this: + + mySed = overrideDerivation pkgs.gnused (oldAttrs: { + name = "sed-4.2.2-pre"; + src = fetchurl { + url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2; + sha256 = "11nq06d131y4wmf3drm0yk502d2xc6n5qy82cg88rb9nqd2lj41k"; + }; + patches = []; + }); + + For another application, see build-support/vm, where this + function is used to build arbitrary derivations inside a QEMU + virtual machine. */ + + overrideDerivation = drv: f: + let + # Filter out special attributes. + attrs = removeAttrs drv ["meta" "passthru" "outPath" "drvPath"]; + newDrv = derivation (attrs // (f drv)); + in newDrv // + { meta = if drv ? meta then drv.meta else {}; + passthru = if drv ? passthru then drv.passthru else {}; + }; + + + # usage: (you can use override multiple times) + # let d = makeOverridable stdenv.mkDerivation { name = ..; buildInputs; } + # noBuildInputs = d.override { buildInputs = []; } + # additionalBuildInputs = d.override ( args : args // { buildInputs = args.buildInputs ++ [ additional ]; } ) + makeOverridable = f: origArgs: f origArgs // + { override = newArgs: + makeOverridable f (origArgs // (if builtins.isFunction newArgs then newArgs origArgs else newArgs)); + deepOverride = newArgs: + makeOverridable f ((lib.mapAttrs (deepOverride newArgs) origArgs) // newArgs); + origArgs = origArgs; + }; + + + deepOverride = newArgs: name: x: if builtins.isAttrs x then ( + if x ? deepOverride then (x.deepOverride newArgs) else + if x ? override then (x.override newArgs) else + x) else x; + + +} diff --git a/pkgs/lib/debug.nix b/pkgs/lib/debug.nix index 4f757653bc0..5d411b864ec 100644 --- a/pkgs/lib/debug.nix +++ b/pkgs/lib/debug.nix @@ -1,6 +1,6 @@ let lib = import ./default.nix; -inherit (builtins) trace attrNamesToStr isAttrs isFunction isList head substring attrNames; +inherit (builtins) trace attrNamesToStr isAttrs isFunction isList isInt isString head substring attrNames; in @@ -37,7 +37,10 @@ rec { else if x == true then "x is boolean true" else if x == false then "x is boolean false" else if x == null then "x is null" - else "x is probably a string `${substring 0 50 x}...'"; + else if isInt x then "x is an integer `${toString x}'" + else if isString x then "x is a string `${substring 0 50 x}...'" + else "x is probably a path `${substring 0 50 (toString x)}'"; + # trace the arguments passed to function and its result traceCall = n : f : a : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a)); traceCall2 = n : f : a : b : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b)); diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix index 86c45fe8334..6276009ec19 100644 --- a/pkgs/lib/default.nix +++ b/pkgs/lib/default.nix @@ -16,6 +16,7 @@ let maintainers = import ./maintainers.nix; platforms = import ./platforms.nix; systems = import ./systems.nix; + customisation = import ./customisation.nix; in { inherit trivial lists strings stringsWithDeps attrsets sources options @@ -26,3 +27,4 @@ in // trivial // lists // strings // stringsWithDeps // attrsets // sources // properties // options // types // meta // debug // misc // modules // systems + // customisation diff --git a/pkgs/lib/maintainers.nix b/pkgs/lib/maintainers.nix index 892b3e21044..9127c8c7308 100644 --- a/pkgs/lib/maintainers.nix +++ b/pkgs/lib/maintainers.nix @@ -8,6 +8,7 @@ eelco = "Eelco Dolstra <e.dolstra@tudelft.nl>"; ludo = "Ludovic Courtès <ludo@gnu.org>"; marcweber = "Marc Weber <marco-oweber@gmx.de>"; + pierron = "Nicolas B. Pierron <nixos@nbp.name>"; raskin = "Michael Raskin <7c6f434c@mail.ru>"; sander = "Sander van der Burg <s.vanderburg@tudelft.nl>"; viric = "Lluís Batlle i Rossell <viriketo@gmail.com>"; diff --git a/pkgs/lib/misc.nix b/pkgs/lib/misc.nix index ba7488ff70e..c1fee190268 100644 --- a/pkgs/lib/misc.nix +++ b/pkgs/lib/misc.nix @@ -9,23 +9,6 @@ with import ./strings.nix; rec { - - # accumulates / merges all attr sets until null is fed. - # example: sumArgs id { a = 'a'; x = 'x'; } { y = 'y'; x = 'X'; } null - # result : { a = 'a'; x = 'X'; y = 'Y'; } - innerSumArgs = f : x : y : (if y == null then (f x) - else (innerSumArgs f (x // y))); - sumArgs = f : innerSumArgs f {}; - - # Advanced sumArgs version. Hm, twice as slow, I'm afraid. - # composedArgs id (x:x//{a="b";}) (x:x//{b=x.a + "c";}) null; - # {a="b" ; b="bc";}; - innerComposedArgs = f : x : y : (if y==null then (f x) - else (if (builtins.isAttrs y) then - (innerComposedArgs f (x//y)) - else (innerComposedArgs f (y x)))); - composedArgs = f: innerComposedArgs f {}; - defaultMergeArg = x : y: if builtins.isAttrs y then y else @@ -105,14 +88,6 @@ rec { # } composedArgsAndFun = f: foldArgs defaultMerge f {}; - # example a = pairMap (x : y : x + y) ["a" "b" "c" "d"]; - # result: ["ab" "cd"] - innerPairMap = acc: f: l: - if l == [] then acc else - innerPairMap (acc ++ [(f (head l)(head (tail l)))]) - f (tail (tail l)); - pairMap = innerPairMap []; - # shortcut for attrByPath ["name"] default attrs maybeAttr = name: default: attrs: @@ -321,12 +296,6 @@ rec { flattenAttrs = set : map ( attr : builtins.getAttr attr set) (attrNames set); mapIf = cond : f : fold ( x : l : if (cond x) then [(f x)] ++ l else l) []; - # pick attrs subset_attr_names and apply f - subsetmap = f : attrs : subset_attr_names : - listToAttrs (fold ( attr : r : if hasAttr attr attrs - then r ++ [ ( nameValuePair attr ( f (getAttr attr attrs) ) ) ] else r ) [] - subset_attr_names ); - # prepareDerivationArgs tries to make writing configurable derivations easier # example: # prepareDerivationArgs { |