top-level: Make overridePackages extend rather than replace existing overrides

This commit is contained in:
John Ericson 2016-10-12 15:14:49 -04:00
parent da36847d92
commit e4cd45a30c
4 changed files with 77 additions and 64 deletions

View file

@ -52,6 +52,20 @@ in ...</programlisting>
It's equivalent to <varname>pkgs</varname> in the above example. It's equivalent to <varname>pkgs</varname> in the above example.
</para> </para>
<para>
Note that in previous versions of nixpkgs, this method replaced any changes from <link
linkend="sec-modify-via-packageOverrides">config.packageOverrides</link>,
along with that from previous calls if this function was called repeatedly.
Now those previous changes will be preserved so this function can be "chained" meaningfully.
To recover the old behavior, make sure <varname>config.packageOverrides<varname> is unset,
and call this only once off a "freshly" imported nixpkgs:
<programlisting>let
pkgs = import &lt;nixpkgs&gt; { config: {}; };
newpkgs = pkgs.overridePackages ...;
in ...</programlisting>
</para>
</section> </section>
<section xml:id="sec-pkg-override"> <section xml:id="sec-pkg-override">

View file

@ -69,9 +69,13 @@ rec {
# #
# nix-repl> obj # nix-repl> obj
# { __unfix__ = «lambda»; bar = "bar"; extend = «lambda»; foo = "foo + "; foobar = "foo + bar"; } # { __unfix__ = «lambda»; bar = "bar"; extend = «lambda»; foo = "foo + "; foobar = "foo + bar"; }
makeExtensible = rattrs: makeExtensible = makeExtensibleWithCustomName "extend";
# Same as `makeExtensible` but the name of the extending attribute is
# customized.
makeExtensibleWithCustomName = extenderName: rattrs:
fix' rattrs // { fix' rattrs // {
extend = f: makeExtensible (extends f rattrs); ${extenderName} = f: makeExtensibleWithCustomName extenderName (extends f rattrs);
}; };
# Flip the order of the arguments of a binary function. # Flip the order of the arguments of a binary function.

View file

@ -6,7 +6,6 @@
* Hint: ### starts category names. * Hint: ### starts category names.
*/ */
{ system, bootStdenv, noSysDirs, config, crossSystem, platform, lib { system, bootStdenv, noSysDirs, config, crossSystem, platform, lib
, pkgsWithOverrides
, ... }: , ... }:
self: pkgs: self: pkgs:
@ -35,19 +34,6 @@ in
newScope = extra: lib.callPackageWith (defaultScope // extra); newScope = extra: lib.callPackageWith (defaultScope // extra);
# Easily override this package set.
# Warning: this function is very expensive and must not be used
# from within the nixpkgs repository.
#
# Example:
# pkgs.overridePackages (self: super: {
# foo = super.foo.override { ... };
# }
#
# The result is `pkgs' where all the derivations depending on `foo'
# will use the new version.
overridePackages = f: pkgsWithOverrides f;
# 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 ../..) { forceSystem = system: kernel: (import ../..) {
inherit system; inherit system;

View file

@ -61,20 +61,6 @@ let
inherit system bootStdenv noSysDirs config crossSystem platform lib; inherit system bootStdenv noSysDirs config crossSystem platform lib;
}; };
# Allow packages to be overridden globally via the `packageOverrides'
# configuration option, which must be a function that takes `pkgs'
# as an argument and returns a set of new or overridden packages.
# The `packageOverrides' function is called with the *original*
# (un-overridden) set of packages, allowing packageOverrides
# attributes to refer to the original attributes (e.g. "foo =
# ... pkgs.foo ...").
pkgs = pkgsWithOverrides (self: config.packageOverrides or (super: {}));
# Return the complete set of packages, after applying the overrides
# returned by the `overrider' function (see above). Warning: this
# function is very expensive!
pkgsWithOverrides = overrider:
let
stdenvAdapters = self: super: stdenvAdapters = self: super:
let res = import ../stdenv/adapters.nix self; in res // { let res = import ../stdenv/adapters.nix self; in res // {
stdenvAdapters = res; stdenvAdapters = res;
@ -87,9 +73,8 @@ let
stdenvDefault = self: super: (import ./stdenv.nix topLevelArguments) {} pkgs; stdenvDefault = self: super: (import ./stdenv.nix topLevelArguments) {} pkgs;
allPackagesArgs = topLevelArguments // { inherit pkgsWithOverrides; };
allPackages = self: super: allPackages = self: super:
let res = import ./all-packages.nix allPackagesArgs res self; let res = import ./all-packages.nix topLevelArguments res self;
in res; in res;
aliases = self: super: import ./aliases.nix super; aliases = self: super: import ./aliases.nix super;
@ -105,17 +90,41 @@ let
lib.optionalAttrs (crossSystem == null && super.stdenv ? overrides) lib.optionalAttrs (crossSystem == null && super.stdenv ? overrides)
(super.stdenv.overrides super); (super.stdenv.overrides super);
customOverrides = self: super: # Allow packages to be overridden globally via the `packageOverrides'
lib.optionalAttrs (bootStdenv == null) (overrider self super); # configuration option, which must be a function that takes `pkgs'
in # as an argument and returns a set of new or overridden packages.
lib.fix' ( # The `packageOverrides' function is called with the *original*
lib.extends customOverrides ( # (un-overridden) set of packages, allowing packageOverrides
lib.extends stdenvOverrides ( # attributes to refer to the original attributes (e.g. "foo =
lib.extends aliases ( # ... pkgs.foo ...").
lib.extends allPackages ( configOverrides = self: super:
lib.extends stdenvDefault ( lib.optionalAttrs (bootStdenv == null)
lib.extends trivialBuilders ( ((config.packageOverrides or (super: {})) super);
lib.extends stdenvAdapters (
self: {})))))))); # The complete chain of package set builders, applied from bottom to top
in toFix = lib.fold lib.extends (self: {}) [
pkgs configOverrides
stdenvOverrides
aliases
allPackages
stdenvDefault
trivialBuilders
stdenvAdapters
];
# Use `overridePackages` to easily override this package set.
# Warning: this function is very expensive and must not be used
# from within the nixpkgs repository.
#
# Example:
# pkgs.overridePackages (self: super: {
# foo = super.foo.override { ... };
# }
#
# The result is `pkgs' where all the derivations depending on `foo'
# will use the new version.
# Return the complete set of packages. Warning: this function is very
# expensive!
pkgs = lib.makeExtensibleWithCustomName "overridePackages" toFix;
in pkgs