@@ -64,7 +64,7 @@ let
6464 # { /* the config */ } and
6565 # { pkgs, ... } : { /* the config */ }
6666 if builtins.isFunction configExpr
67− then configExpr { pkgs = pkgsFinal; }
67+ then configExpr { inherit pkgs; }
6868 else configExpr;
6969
7070 # Allow setting the platform in the config file. Otherwise, let's use a reasonable default (pc)
@@ -83,38 +83,51 @@ let
8383 platform = if platform_ != null then platform_
8484 else config.platform or platformAuto;
8585
86− # The complete set of packages, after applying the overrides
87− pkgsFinal = lib.fix' (lib.extends configOverrides (lib.extends stdenvOverrides pkgsFun));
86+ # Helper functions that are exported through `pkgs'.
87+ helperFunctions =
88+ stdenvAdapters //
89+ (import ../build-support/trivial-builders.nix { inherit lib; inherit (pkgs) stdenv; inherit (pkgs.xorg) lndir; });
90+
91+ stdenvAdapters =
92+ import ../stdenv/adapters.nix pkgs;
8893
89− stdenvOverrides =
90− # We don't want stdenv overrides in the case of cross-building,
91− # or otherwise the basic overrided packages will not be built
92− # with the crossStdenv adapter.
93− if crossSystem == null
94− then self: super: lib.optionalAttrs (super.stdenv ? overrides) (super.stdenv.overrides super)
95− else self: super: {};
9694
97− # Packages can be overriden globally via the `packageOverrides'
95+ # Allow packages to be overriden globally via the `packageOverrides'
9896 # configuration option, which must be a function that takes `pkgs'
9997 # as an argument and returns a set of new or overriden packages.
100− # The recommended usage follows this snippet:
101− # packageOverrides = super: let self = super.pkgs in ...
102− # `super' is the *original* (un-overriden) set of packages,
103− # while `self' refers to the final (overriden) set of packages.
104− configOverrides =
105− if config ? packageOverrides && bootStdenv == null # don't apply config overrides in stdenv boot
106− then self: config.packageOverrides
107− else self: super: {};
98+ # The `packageOverrides' function is called with the *original*
99+ # (un-overriden) set of packages, allowing packageOverrides
100+ # attributes to refer to the original attributes (e.g. "foo =
101+ # ... pkgs.foo ...").
102+ pkgs = applyGlobalOverrides (config.packageOverrides or (pkgs: {}));
103+
104+ mkOverrides = pkgsOrig: overrides: overrides //
105+ (lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem == null) (pkgsOrig.stdenv.overrides pkgsOrig));
106+
107+ # Return the complete set of packages, after applying the overrides
108+ # returned by the `overrider' function (see above). Warning: this
109+ # function is very expensive!
110+ applyGlobalOverrides = overrider:
111+ let
112+ # Call the overrider function. We don't want stdenv overrides
113+ # in the case of cross-building, or otherwise the basic
114+ # overrided packages will not be built with the crossStdenv
115+ # adapter.
116+ overrides = mkOverrides pkgsOrig (overrider pkgsOrig);
117+
118+ # The un-overriden packages, passed to `overrider'.
119+ pkgsOrig = pkgsFun pkgs {};
120+
121+ # The overriden, final packages.
122+ pkgs = pkgsFun pkgs overrides;
123+ in pkgs;
124+
108125
109126 # The package compositions. Yes, this isn't properly indented.
110− pkgsFun = pkgs:
111− let defaultScope = pkgs // pkgs.xorg;
112− helperFunctions = pkgs_.stdenvAdapters // pkgs_.trivial-builders;
113− pkgsRet = helperFunctions // pkgs_;
114− pkgs_ = with pkgs; {
115− # Helper functions that are exported through `pkgs'.
116− trivial-builders = import ../build-support/trivial-builders.nix { inherit lib; inherit stdenv; inherit (xorg) lndir; };
117− stdenvAdapters = import ../stdenv/adapters.nix pkgs;
127+ pkgsFun = pkgs: overrides:
128+ with helperFunctions;
129+ let defaultScope = pkgs // pkgs.xorg; self = self_ // overrides;
130+ self_ = with self; helperFunctions // {
118131
119132 # Make some arguments passed to all-packages.nix available
120133 inherit system platform;
@@ -144,7 +157,11 @@ let
144157 #
145158 # The result is `pkgs' where all the derivations depending on `foo'
146159 # will use the new version.
147− overridePackages = f: lib.fix' (lib.extends f pkgs.__unfix__);
160+ overridePackages = f:
161+ let
162+ newpkgs = pkgsFun newpkgs overrides;
163+ overrides = mkOverrides pkgs (f newpkgs pkgs);
164+ in newpkgs;
148165
149166 # Override system. This is useful to build i686 packages on x86_64-linux.
150167 forceSystem = system: kernel: (import ./all-packages.nix) {
@@ -166,7 +183,7 @@ let
166183
167184
168185 ### Helper functions.
169− inherit lib config;
186+ inherit lib config stdenvAdapters;
170187
171188 inherit (lib) lowPrio hiPrio appendToName makeOverridable;
172189 inherit (misc) versionedDerivation;
@@ -197,8 +214,7 @@ let
197214 allPackages = args: import ./all-packages.nix ({ inherit config system; } // args);
198215 };
199216
200− # We use pkgs_ because accessing pkgs would lead to an infinite recursion in stdenvOverrides
201− defaultStdenv = pkgs_.allStdenvs.stdenv // { inherit platform; };
217+ defaultStdenv = allStdenvs.stdenv // { inherit platform; };
202218
203219 stdenvCross = lowPrio (makeStdenvCross defaultStdenv crossSystem binutilsCross gccCrossStageFinal);
204220
@@ -218,7 +234,7 @@ let
218234 };
219235 }
220236 else
221− pkgs_.defaultStdenv;
237+ defaultStdenv;
222238
223239 forceNativeDrv = drv : if crossSystem == null then drv else
224240 (drv // { crossDrv = drv.nativeDrv; });
@@ -5988,8 +6004,8 @@ let
59886004 gotty = goPackages.gotty.bin // { outputs = [ "bin" ]; };
59896005
59906006 gradleGen = callPackage ../development/tools/build-managers/gradle { };
5991− gradle = gradleGen.gradleLatest;
5992− gradle25 = gradleGen.gradle25;
6007+ gradle = self.gradleGen.gradleLatest;
6008+ gradle25 = self.gradleGen.gradle25;
59936009
59946010 gperf = callPackage ../development/tools/misc/gperf { };
59956011
@@ -11824,7 +11840,7 @@ let
1182411840 AppKit Carbon Cocoa IOKit OSAKit Quartz QuartzCore WebKit
1182511841 ImageCaptureCore GSS ImageIO;
1182611842 });
11827− emacs24Macport = emacs24Macport_24_5;
11843+ emacs24Macport = self.emacs24Macport_24_5;
1182811844
1182911845 emacs25pre = lowPrio (callPackage ../applications/editors/emacs-25 {
1183011846 # use override to enable additional features
@@ -16200,13 +16216,12 @@ let
1620016216
1620116217 mg = callPackage ../applications/editors/mg { };
1620216218
16203−};
16204−# end pkgs_ =
16219+}; # self_ =
1620516220
1620616221
1620716222 ### Deprecated aliases - for backward compatibility
1620816223
16209−aliases = with pkgs; {
16224+aliases = with self; rec {
1621016225 accounts-qt = qt5.accounts-qt; # added 2015-12-19
1621116226 adobeReader = adobe-reader;
1621216227 aircrackng = aircrack-ng; # added 2016-01-14
@@ -16295,7 +16310,4 @@ tweakAlias = _n: alias: with lib;
1629516310 removeAttrs alias ["recurseForDerivations"]
1629616311 else alias;
1629716312
16298−in lib.mapAttrs tweakAlias aliases // pkgsRet;
16299−# end pkgsFun
16300−
16301−in pkgsFinal
16313+in lib.mapAttrs tweakAlias aliases // self; in pkgs