From 3cfc942bdc9fcf78620ea34152a8749904bc25dd Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 3 Sep 2010 10:46:18 +0000 Subject: [PATCH] * Added a function `applyGlobalOverrides' to return Nixpkgs with the specified overrides applied. This does the same as the `packageOverrides' attribute in ~/.nixpkgs/config.nix, but can be used within all-packages.nix to do a "deep" override for some specific package. For instance, to build Thunderbird with an older version of Glib, you can say: thunderbird3 = let pkgs = applyGlobalOverrides (pkgsOrig: { gtkLibs220 = pkgsOrig.gtkLibs220 // { glib = pkgsOrig.gtkLibs218.glib; }; }); in pkgs.callPackage .../thunderbird/3.x.nix { inherit (pkgs.gnome) libIDL; }; Note that `pkgsFun' now has an argument `pkgs' to refer to its own result. * Moved callPackage etc. into pkgsFun so that it uses the right overriden packages, if applicable. `defaultScope' isn't in the result set because that causes nix-env to go into an apparently infinite recursion. * Dropped the optional pkgsOrig argument to ~/.nixpkgs/config.nix, because it's probably not useful or used. svn path=/nixpkgs/trunk/; revision=23613 --- pkgs/top-level/all-packages.nix | 62 ++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 748a49e5d8f..afbb99d36d7 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -65,9 +65,9 @@ let in # allow both: # { /* the config */ } and - # { pkgsOrig, pkgs, ... } : { /* the config */ } + # { pkgs, ... } : { /* the config */ } if builtins.isFunction configExpr - then configExpr { inherit pkgs pkgsOrig; } + then configExpr { inherit pkgs; } else configExpr; # Return an attribute from the Nixpkgs configuration file, or @@ -87,21 +87,42 @@ let # Allow packages to be overriden globally via the `packageOverrides' # configuration option, which must be a function that takes `pkgs' # as an argument and returns a set of new or overriden packages. - # `__overrides' is a magic attribute that causes the attributes in - # its value to be added to the surrounding `rec'. The - # `packageOverrides' function is called with the *original* + # The `packageOverrides' function is called with the *original* # (un-overriden) set of packages, allowing packageOverrides # attributes to refer to the original attributes (e.g. "foo = # ... pkgs.foo ..."). - # We don't want stdenv overrides in the case of cross-building, or - # otherwise the basic overrided packages will not be built with the - # crossStdenv adapter. - overrides = (getConfig ["packageOverrides"] (pkgs: {})) pkgsOrig // - (if pkgsOrig.stdenv ? overrides && crossSystem == null - then pkgsOrig.stdenv.overrides else { }); + pkgs = applyGlobalOverrides (getConfig ["packageOverrides"] (pkgs: {})); - pkgsOrig = pkgsFun { }; # the un-overriden packages, passed to packageOverrides - pkgs = pkgsFun overrides; # the overriden, final packages + + # Return the complete set of packages, after applying the overrides + # returned by the `overrider' function (see above). + applyGlobalOverrides = overrider: + let + # Call the overrider function. We don't want stdenv overrides + # in the case of cross-building, or otherwise the basic + # overrided packages will not be built with the crossStdenv + # adapter. + overrides = overrider pkgsOrig // + (lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem == null) pkgsOrig.stdenv.overrides); + + # The un-overriden packages, passed to `overrider'. + pkgsOrig = pkgsFun pkgs {}; + + # The overriden, final packages. + pkgs = pkgsFun pkgs overrides; + in pkgs; + + + # The package compositions. Yes, this isn't properly indented. + pkgsFun = pkgs: __overrides: + with helperFunctions; + let defaultScope = pkgs // pkgs.xorg; in + helperFunctions // rec { + + # `__overrides' is a magic attribute that causes the attributes in + # its value to be added to the surrounding `rec'. We'll remove this + # eventually. + inherit __overrides; # We use `callPackage' to be able to omit function arguments that @@ -112,26 +133,19 @@ let newScope = extra: lib.callPackageWith (defaultScope // extra); - defaultScope = pkgs // pkgs.xorg; - - - # The package compositions. Yes, this isn't properly indented. - pkgsFun = __overrides: with helperFunctions; helperFunctions // rec { - - + # Override system. This is useful to build i686 packages on x86_64-linux. forceSystem = system: (import ./all-packages.nix) { inherit system; inherit bootStdenv noSysDirs gccWithCC gccWithProfiling config; }; + # Used by wine, firefox with debugging version of Flash, ... pkgsi686Linux = forceSystem "i686-linux"; callPackage_i686 = lib.callPackageWith (pkgsi686Linux // pkgsi686Linux.xorg); - inherit __overrides; - # For convenience, allow callers to get the path to Nixpkgs. path = ../..; @@ -853,7 +867,7 @@ let nbd = callPackage ../tools/networking/nbd { glib = gtkLibs.glib.override { stdenv = makeStaticBinaries stdenv; - }; + }; }; nc6 = callPackage ../tools/networking/nc6 { }; @@ -2082,7 +2096,7 @@ let python24 = lowPrio (callPackage ../development/interpreters/python/2.4 { }); python26Base = lowPrio (makeOverridable (import ../development/interpreters/python/2.6) { - inherit fetchurl stdenv zlib bzip2 gdbm; + inherit (pkgs) fetchurl stdenv zlib bzip2 gdbm; arch = if stdenv.isDarwin then darwinArchUtility else null; sw_vers = if stdenv.isDarwin then darwinSwVersUtility else null; });