git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #19496 from Ericson2314/overridePackages
ca2b034Charles Strahan
doc/functions.xml+14
@@ -52,6 +52,20 @@ in ...</programlisting>
52 It's equivalent to <varname>pkgs</varname> in the above example.
52 It's equivalent to <varname>pkgs</varname> in the above example.
53 </para>
53 </para>
54
54
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+
55</section>
69</section>
56
70
57<section xml:id="sec-pkg-override">
71<section xml:id="sec-pkg-override">
lib/trivial.nix+6−2
@@ -69,9 +69,13 @@ rec {
69 #
69 #
70 # nix-repl> obj
70 # nix-repl> obj
71 # { __unfix__ = «lambda»; bar = "bar"; extend = «lambda»; foo = "foo + "; foobar = "foo + bar"; }
71 # { __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:
73 fix' rattrs // {
77 fix' rattrs // {
74− extend = f: makeExtensible (extends f rattrs);
78+ ${extenderName} = f: makeExtensibleWithCustomName extenderName (extends f rattrs);
75 };
79 };
76
80
77 # Flip the order of the arguments of a binary function.
81 # Flip the order of the arguments of a binary function.
pkgs/top-level/all-packages.nix−14
@@ -6,7 +6,6 @@
6 * Hint: ### starts category names.
6 * Hint: ### starts category names.
7 */
7 */
8{ system, bootStdenv, noSysDirs, config, crossSystem, platform, lib
8{ system, bootStdenv, noSysDirs, config, crossSystem, platform, lib
9−, pkgsWithOverrides
10, ... }:
9, ... }:
11self: pkgs:
10self: pkgs:
12
11
@@ -35,19 +34,6 @@ in
35
34
36 newScope = extra: lib.callPackageWith (defaultScope // extra);
35 newScope = extra: lib.callPackageWith (defaultScope // extra);
37
36
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−
51 # Override system. This is useful to build i686 packages on x86_64-linux.
37 # Override system. This is useful to build i686 packages on x86_64-linux.
52 forceSystem = system: kernel: (import ../..) {
38 forceSystem = system: kernel: (import ../..) {
53 inherit system;
39 inherit system;
pkgs/top-level/default.nix+60−51
@@ -61,6 +61,35 @@ let
61 inherit system bootStdenv noSysDirs config crossSystem platform lib;
61 inherit system bootStdenv noSysDirs config crossSystem platform lib;
62 };
62 };
63
63
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+
64 # Allow packages to be overridden globally via the `packageOverrides'
93 # Allow packages to be overridden globally via the `packageOverrides'
65 # configuration option, which must be a function that takes `pkgs'
94 # configuration option, which must be a function that takes `pkgs'
66 # as an argument and returns a set of new or overridden packages.
95 # as an argument and returns a set of new or overridden packages.
@@ -68,54 +97,34 @@ let
68 # (un-overridden) set of packages, allowing packageOverrides
97 # (un-overridden) set of packages, allowing packageOverrides
69 # attributes to refer to the original attributes (e.g. "foo =
98 # attributes to refer to the original attributes (e.g. "foo =
70 # ... pkgs.foo ...").
99 # ... pkgs.foo ...").
100+ configOverrides = self: super:
101+ lib.optionalAttrs (bootStdenv == null)
71− pkgs = pkgsWithOverrides (self: config.packageOverrides or (super: {}));
102+ ((config.packageOverrides or (super: {})) super);
72−
103+
73− # Return the complete set of packages, after applying the overrides
104+ # The complete chain of package set builders, applied from top to bottom
74− # returned by the `overrider' function (see above). Warning: this
105+ toFix = lib.foldl' (lib.flip lib.extends) (self: {}) [
75− # function is very expensive!
106+ stdenvAdapters
76− pkgsWithOverrides = overrider:
107+ trivialBuilders
77− let
108+ stdenvDefault
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:
109+ allPackages
92− let res = import ./all-packages.nix allPackagesArgs res self;
110+ aliases
93− in res;
111+ stdenvOverrides
94−
112+ configOverrides
95− aliases = self: super: import ./aliases.nix super;
113+ ];
96−
114+
97− # stdenvOverrides is used to avoid circular dependencies for building
115+ # Use `overridePackages` to easily override this package set.
98− # the standard build environment. This mechanism uses the override
116+ # Warning: this function is very expensive and must not be used
99− # mechanism to implement some staged compilation of the stdenv.
117+ # from within the nixpkgs repository.
100− #
118+ #
101− # We don't want stdenv overrides in the case of cross-building, or
119+ # Example:
102− # otherwise the basic overridden packages will not be built with the
120+ # pkgs.overridePackages (self: super: {
103− # crossStdenv adapter.
121+ # foo = super.foo.override { ... };
104− stdenvOverrides = self: super:
122+ # }
105− lib.optionalAttrs (crossSystem == null && super.stdenv ? overrides)
123+ #
106− (super.stdenv.overrides super);
124+ # The result is `pkgs' where all the derivations depending on `foo'
107−
125+ # will use the new version.
108− customOverrides = self: super:
126+
109− lib.optionalAttrs (bootStdenv == null) (overrider self super);
127+ # Return the complete set of packages. Warning: this function is very
110− in
128+ # expensive!
111− lib.fix' (
129+ pkgs = lib.makeExtensibleWithCustomName "overridePackages" toFix;
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
130+in pkgs