From 81c5c44ddb806eaec3c12088716db58e6f2e6b4f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 19 Nov 2009 17:30:21 +0000 Subject: [PATCH] * Move makeOverridable out of all-packages.nix. svn path=/nixpkgs/trunk/; revision=18469 --- pkgs/lib/customisation.nix | 27 ++++++++++++++++++++++++--- pkgs/top-level/all-packages.nix | 19 +------------------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/pkgs/lib/customisation.nix b/pkgs/lib/customisation.nix index 889ce04547f2..76d019a73c20 100644 --- a/pkgs/lib/customisation.nix +++ b/pkgs/lib/customisation.nix @@ -1,11 +1,13 @@ -{ +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'. This function is called with the - original derivation attributes. + 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 @@ -37,4 +39,23 @@ }; + # 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/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 79f296b92ab4..8f66c381677e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -125,7 +125,7 @@ let inherit lib config getConfig; - inherit (lib) lowPrio appendToName; + inherit (lib) lowPrio appendToName makeOverridable; # Applying this to an attribute set will cause nix-env to look # inside the set for derivations. @@ -157,23 +157,6 @@ let stringsWithDeps = lib.stringsWithDeps; - 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; - - # 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; - }; - ### STANDARD ENVIRONMENT