git.iko.soy/typeable/nixpkgs
on master help sign in
top-level: Make `overridePackages` extend rather than replace existing overrides
commite4cd45a30c92a19a240df835cdaf6da5f76ea9fc authorJohn Ericson <jericson@galois.com> dateWed 12 Oct 2016, 15:14 (10 years ago) parentda36847
4 files changed+80−67
doc/functions.xml+14 lib/trivial.nix+6−2 pkgs/top-level/all-packages.nix−14 pkgs/top-level/default.nix+60−51
doc/functions.xml+14
@@ -52,6 +52,20 @@ in ...</programlisting>
5252 It's equivalent to <varname>pkgs</varname> in the above example.
5353 </para>
5454
55+ <para>
56+ Note that in previous versions of nixpkgs, this method replaced any changes from <link
57+ linkend="sec-modify-via-packageOverrides">config.packageOverrides</link>,
58+ along with that from previous calls if this function was called repeatedly.
59+ Now those previous changes will be preserved so this function can be "chained" meaningfully.
60+ To recover the old behavior, make sure <varname>config.packageOverrides<varname> is unset,
61+ and call this only once off a "freshly" imported nixpkgs:
62+
63+ <programlisting>let
64+ pkgs = import &lt;nixpkgs&gt; { config: {}; };
65+ newpkgs = pkgs.overridePackages ...;
66+in ...</programlisting>
67+ </para>
68+
5569</section>
5670
5771<section xml:id="sec-pkg-override">
lib/trivial.nix+6−2
@@ -69,9 +69,13 @@ rec {
6969 #
7070 # nix-repl> obj
7171 # { __unfix__ = «lambda»; bar = "bar"; extend = «lambda»; foo = "foo + "; foobar = "foo + bar"; }
72− makeExtensible = rattrs:
72+ makeExtensible = makeExtensibleWithCustomName "extend";
73+
74+ # Same as `makeExtensible` but the name of the extending attribute is
75+ # customized.
76+ makeExtensibleWithCustomName = extenderName: rattrs:
7377 fix' rattrs // {
74− extend = f: makeExtensible (extends f rattrs);
78+ ${extenderName} = f: makeExtensibleWithCustomName extenderName (extends f rattrs);
7579 };
7680
7781 # Flip the order of the arguments of a binary function.
pkgs/top-level/all-packages.nix−14
@@ -6,7 +6,6 @@
66 * Hint: ### starts category names.
77 */
88{ system, bootStdenv, noSysDirs, config, crossSystem, platform, lib
9−, pkgsWithOverrides
109, ... }:
1110self: pkgs:
1211
@@ -35,19 +34,6 @@ in
3534
3635 newScope = extra: lib.callPackageWith (defaultScope // extra);
3736
38− # Easily override this package set.
39− # Warning: this function is very expensive and must not be used
40− # from within the nixpkgs repository.
41− #
42− # Example:
43− # pkgs.overridePackages (self: super: {
44− # foo = super.foo.override { ... };
45− # }
46− #
47− # The result is `pkgs' where all the derivations depending on `foo'
48− # will use the new version.
49− overridePackages = f: pkgsWithOverrides f;
50−
5137 # Override system. This is useful to build i686 packages on x86_64-linux.
5238 forceSystem = system: kernel: (import ../..) {
5339 inherit system;
pkgs/top-level/default.nix+60−51
@@ -61,6 +61,35 @@ let
6161 inherit system bootStdenv noSysDirs config crossSystem platform lib;
6262 };
6363
64+ stdenvAdapters = self: super:
65+ let res = import ../stdenv/adapters.nix self; in res // {
66+ stdenvAdapters = res;
67+ };
68+
69+ trivialBuilders = self: super:
70+ (import ../build-support/trivial-builders.nix {
71+ inherit lib; inherit (self) stdenv stdenvNoCC; inherit (self.xorg) lndir;
72+ });
73+
74+ stdenvDefault = self: super: (import ./stdenv.nix topLevelArguments) {} pkgs;
75+
76+ allPackages = self: super:
77+ let res = import ./all-packages.nix topLevelArguments res self;
78+ in res;
79+
80+ aliases = self: super: import ./aliases.nix super;
81+
82+ # stdenvOverrides is used to avoid circular dependencies for building
83+ # the standard build environment. This mechanism uses the override
84+ # mechanism to implement some staged compilation of the stdenv.
85+ #
86+ # We don't want stdenv overrides in the case of cross-building, or
87+ # otherwise the basic overridden packages will not be built with the
88+ # crossStdenv adapter.
89+ stdenvOverrides = self: super:
90+ lib.optionalAttrs (crossSystem == null && super.stdenv ? overrides)
91+ (super.stdenv.overrides super);
92+
6493 # Allow packages to be overridden globally via the `packageOverrides'
6594 # configuration option, which must be a function that takes `pkgs'
6695 # as an argument and returns a set of new or overridden packages.
@@ -68,54 +97,34 @@ let
6897 # (un-overridden) set of packages, allowing packageOverrides
6998 # attributes to refer to the original attributes (e.g. "foo =
7099 # ... pkgs.foo ...").
71− pkgs = pkgsWithOverrides (self: config.packageOverrides or (super: {}));
72−
73− # Return the complete set of packages, after applying the overrides
74− # returned by the `overrider' function (see above). Warning: this
75− # function is very expensive!
76− pkgsWithOverrides = overrider:
77− let
78− stdenvAdapters = self: super:
79− let res = import ../stdenv/adapters.nix self; in res // {
80− stdenvAdapters = res;
81− };
82−
83− trivialBuilders = self: super:
84− (import ../build-support/trivial-builders.nix {
85− inherit lib; inherit (self) stdenv stdenvNoCC; inherit (self.xorg) lndir;
86− });
87−
88− stdenvDefault = self: super: (import ./stdenv.nix topLevelArguments) {} pkgs;
89−
90− allPackagesArgs = topLevelArguments // { inherit pkgsWithOverrides; };
91− allPackages = self: super:
92− let res = import ./all-packages.nix allPackagesArgs res self;
93− in res;
94−
95− aliases = self: super: import ./aliases.nix super;
96−
97− # stdenvOverrides is used to avoid circular dependencies for building
98− # the standard build environment. This mechanism uses the override
99− # mechanism to implement some staged compilation of the stdenv.
100− #
101− # We don't want stdenv overrides in the case of cross-building, or
102− # otherwise the basic overridden packages will not be built with the
103− # crossStdenv adapter.
104− stdenvOverrides = self: super:
105− lib.optionalAttrs (crossSystem == null && super.stdenv ? overrides)
106− (super.stdenv.overrides super);
107−
108− customOverrides = self: super:
109− lib.optionalAttrs (bootStdenv == null) (overrider self super);
110− in
111− lib.fix' (
112− lib.extends customOverrides (
113− lib.extends stdenvOverrides (
114− lib.extends aliases (
115− lib.extends allPackages (
116− lib.extends stdenvDefault (
117− lib.extends trivialBuilders (
118− lib.extends stdenvAdapters (
119− self: {}))))))));
120−in
121− pkgs
100+ configOverrides = self: super:
101+ lib.optionalAttrs (bootStdenv == null)
102+ ((config.packageOverrides or (super: {})) super);
103+
104+ # The complete chain of package set builders, applied from bottom to top
105+ toFix = lib.fold lib.extends (self: {}) [
106+ configOverrides
107+ stdenvOverrides
108+ aliases
109+ allPackages
110+ stdenvDefault
111+ trivialBuilders
112+ stdenvAdapters
113+ ];
114+
115+ # Use `overridePackages` to easily override this package set.
116+ # Warning: this function is very expensive and must not be used
117+ # from within the nixpkgs repository.
118+ #
119+ # Example:
120+ # pkgs.overridePackages (self: super: {
121+ # foo = super.foo.override { ... };
122+ # }
123+ #
124+ # The result is `pkgs' where all the derivations depending on `foo'
125+ # will use the new version.
126+
127+ # Return the complete set of packages. Warning: this function is very
128+ # expensive!
129+ pkgs = lib.makeExtensibleWithCustomName "overridePackages" toFix;
130+in pkgs