all-packages: Rewrite packageOverrides to use fix'/extends

This way is cleaner, slightly faster (as shown by
some quick tests) and causes no rebuilds.

It could cause some evaluation errors though.
This commit is contained in:
Mathnerd314 2015-10-19 09:11:12 -06:00
parent 80131f4731
commit 9c0121be81

View File

@ -64,7 +64,7 @@ let
# { /* the config */ } and # { /* the config */ } and
# { pkgs, ... } : { /* the config */ } # { pkgs, ... } : { /* the config */ }
if builtins.isFunction configExpr if builtins.isFunction configExpr
then configExpr { inherit pkgs; } then configExpr { pkgs = pkgsFinal; }
else configExpr; else configExpr;
# Allow setting the platform in the config file. Otherwise, let's use a reasonable default (pc) # Allow setting the platform in the config file. Otherwise, let's use a reasonable default (pc)
@ -83,51 +83,38 @@ let
platform = if platform_ != null then platform_ platform = if platform_ != null then platform_
else config.platform or platformAuto; else config.platform or platformAuto;
# Helper functions that are exported through `pkgs'. # The complete set of packages, after applying the overrides
helperFunctions = pkgsFinal = lib.fix' (lib.extends configOverrides (lib.extends stdenvOverrides pkgsFun));
stdenvAdapters //
(import ../build-support/trivial-builders.nix { inherit lib; inherit (pkgs) stdenv; inherit (pkgs.xorg) lndir; });
stdenvAdapters = stdenvOverrides =
import ../stdenv/adapters.nix pkgs; # 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.
if crossSystem == null
then self: super: lib.optionalAttrs (super.stdenv ? overrides) (super.stdenv.overrides super)
else self: super: {};
# Packages can be overriden globally via the `packageOverrides'
# Allow packages to be overriden globally via the `packageOverrides'
# configuration option, which must be a function that takes `pkgs' # configuration option, which must be a function that takes `pkgs'
# as an argument and returns a set of new or overriden packages. # as an argument and returns a set of new or overriden packages.
# The `packageOverrides' function is called with the *original* # The recommended usage follows this snippet:
# (un-overriden) set of packages, allowing packageOverrides # packageOverrides = super: let self = super.pkgs in ...
# attributes to refer to the original attributes (e.g. "foo = # `super' is the *original* (un-overriden) set of packages,
# ... pkgs.foo ..."). # while `self' refers to the final (overriden) set of packages.
pkgs = applyGlobalOverrides (config.packageOverrides or (pkgs: {})); configOverrides =
if config ? packageOverrides && bootStdenv == null # don't apply config overrides in stdenv boot
mkOverrides = pkgsOrig: overrides: overrides // then self: config.packageOverrides
(lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem == null) (pkgsOrig.stdenv.overrides pkgsOrig)); else self: super: {};
# Return the complete set of packages, after applying the overrides
# returned by the `overrider' function (see above). Warning: this
# function is very expensive!
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 = mkOverrides pkgsOrig (overrider pkgsOrig);
# 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. # The package compositions. Yes, this isn't properly indented.
pkgsFun = pkgs: overrides: pkgsFun = pkgs:
with helperFunctions; let defaultScope = pkgs // pkgs.xorg;
let defaultScope = pkgs // pkgs.xorg; self = self_ // overrides; helperFunctions = pkgs_.stdenvAdapters // pkgs_.trivial-builders;
self_ = with self; helperFunctions // { pkgsRet = helperFunctions // pkgs_;
pkgs_ = with pkgs; {
# Helper functions that are exported through `pkgs'.
trivial-builders = import ../build-support/trivial-builders.nix { inherit lib; inherit stdenv; inherit (xorg) lndir; };
stdenvAdapters = import ../stdenv/adapters.nix pkgs;
# Make some arguments passed to all-packages.nix available # Make some arguments passed to all-packages.nix available
inherit system platform; inherit system platform;
@ -157,11 +144,7 @@ let
# #
# The result is `pkgs' where all the derivations depending on `foo' # The result is `pkgs' where all the derivations depending on `foo'
# will use the new version. # will use the new version.
overridePackages = f: overridePackages = f: lib.fix' (lib.extends f pkgs.__unfix__);
let
newpkgs = pkgsFun newpkgs overrides;
overrides = mkOverrides pkgs (f newpkgs pkgs);
in newpkgs;
# Override system. This is useful to build i686 packages on x86_64-linux. # Override system. This is useful to build i686 packages on x86_64-linux.
forceSystem = system: kernel: (import ./all-packages.nix) { forceSystem = system: kernel: (import ./all-packages.nix) {
@ -183,7 +166,7 @@ let
### Helper functions. ### Helper functions.
inherit lib config stdenvAdapters; inherit lib config;
inherit (lib) lowPrio hiPrio appendToName makeOverridable; inherit (lib) lowPrio hiPrio appendToName makeOverridable;
inherit (misc) versionedDerivation; inherit (misc) versionedDerivation;
@ -214,7 +197,8 @@ let
allPackages = args: import ./all-packages.nix ({ inherit config system; } // args); allPackages = args: import ./all-packages.nix ({ inherit config system; } // args);
}; };
defaultStdenv = allStdenvs.stdenv // { inherit platform; }; # We use pkgs_ because accessing pkgs would lead to an infinite recursion in stdenvOverrides
defaultStdenv = pkgs_.allStdenvs.stdenv // { inherit platform; };
stdenvCross = lowPrio (makeStdenvCross defaultStdenv crossSystem binutilsCross gccCrossStageFinal); stdenvCross = lowPrio (makeStdenvCross defaultStdenv crossSystem binutilsCross gccCrossStageFinal);
@ -234,7 +218,7 @@ let
}; };
} }
else else
defaultStdenv; pkgs_.defaultStdenv;
forceNativeDrv = drv : if crossSystem == null then drv else forceNativeDrv = drv : if crossSystem == null then drv else
(drv // { crossDrv = drv.nativeDrv; }); (drv // { crossDrv = drv.nativeDrv; });
@ -5927,8 +5911,8 @@ let
gotty = goPackages.gotty.bin // { outputs = [ "bin" ]; }; gotty = goPackages.gotty.bin // { outputs = [ "bin" ]; };
gradleGen = callPackage ../development/tools/build-managers/gradle { }; gradleGen = callPackage ../development/tools/build-managers/gradle { };
gradle = self.gradleGen.gradleLatest; gradle = gradleGen.gradleLatest;
gradle25 = self.gradleGen.gradle25; gradle25 = gradleGen.gradle25;
gperf = callPackage ../development/tools/misc/gperf { }; gperf = callPackage ../development/tools/misc/gperf { };
@ -11761,7 +11745,7 @@ let
AppKit Carbon Cocoa IOKit OSAKit Quartz QuartzCore WebKit AppKit Carbon Cocoa IOKit OSAKit Quartz QuartzCore WebKit
ImageCaptureCore GSS ImageIO; ImageCaptureCore GSS ImageIO;
}); });
emacs24Macport = self.emacs24Macport_24_5; emacs24Macport = emacs24Macport_24_5;
emacs25pre = lowPrio (callPackage ../applications/editors/emacs-25 { emacs25pre = lowPrio (callPackage ../applications/editors/emacs-25 {
# use override to enable additional features # use override to enable additional features
@ -16103,12 +16087,13 @@ let
mg = callPackage ../applications/editors/mg { }; mg = callPackage ../applications/editors/mg { };
}; # self_ = };
# end pkgs_ =
### Deprecated aliases - for backward compatibility ### Deprecated aliases - for backward compatibility
aliases = with self; rec { aliases = with pkgs; {
accounts-qt = qt5.accounts-qt; # added 2015-12-19 accounts-qt = qt5.accounts-qt; # added 2015-12-19
adobeReader = adobe-reader; adobeReader = adobe-reader;
arduino_core = arduino-core; # added 2015-02-04 arduino_core = arduino-core; # added 2015-02-04
@ -16195,4 +16180,7 @@ tweakAlias = _n: alias: with lib;
removeAttrs alias ["recurseForDerivations"] removeAttrs alias ["recurseForDerivations"]
else alias; else alias;
in lib.mapAttrs tweakAlias aliases // self; in pkgs in lib.mapAttrs tweakAlias aliases // pkgsRet;
# end pkgsFun
in pkgsFinal