From 57568a5baac16db473d8b15948daa8e0087b01a9 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 7 Jun 2015 12:50:25 -0700 Subject: [PATCH 1/4] This line is extraneous because `helperFunctions` is part of `self` --- pkgs/top-level/all-packages.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ddf2f907ebca4..ffc1375fc0572 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -124,7 +124,6 @@ let # The package compositions. Yes, this isn't properly indented. pkgsFun = pkgs: overrides: - with helperFunctions; let defaultScope = pkgs // pkgs.xorg; self = self_ // overrides; self_ = with self; helperFunctions // { From 52c13a68c3f32f6ffc010eb00301740bafebad5c Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 14 Jun 2015 20:18:52 -0700 Subject: [PATCH 2/4] Lift fix-points out from within `pkgFun` to `pkgFun`'s callsites --- pkgs/top-level/all-packages.nix | 115 ++++++++++++++++---------------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ffc1375fc0572..ab8d59beb7113 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -115,17 +115,67 @@ let overrides = mkOverrides pkgsOrig (overrider pkgsOrig); # The un-overriden packages, passed to `overrider'. - pkgsOrig = pkgsFun pkgs {}; + pkgsOrig = pkgsFun pkgs pkgsOrig; # The overriden, final packages. - pkgs = pkgsFun pkgs overrides; + pkgs = pkgsFun pkgs pkgs // overrides; in pkgs; # The package compositions. Yes, this isn't properly indented. - pkgsFun = pkgs: overrides: - let defaultScope = pkgs // pkgs.xorg; self = self_ // overrides; - self_ = with self; helperFunctions // { + pkgsFun = pkgs: self: let + defaultScope = pkgs // pkgs.xorg; + + rawAliases = with self; rec { + adobeReader = adobe-reader; + arduino_core = arduino-core; # added 2015-02-04 + asciidocFull = asciidoc-full; # added 2014-06-22 + bridge_utils = bridge-utils; # added 2015-02-20 + buildbotSlave = buildbot-slave; # added 2014-12-09 + cheetahTemplate = pythonPackages.cheetah; # 2015-06-15 + clangAnalyzer = clang-analyzer; # added 2015-02-20 + cool-old-term = cool-retro-term; # added 2015-01-31 + cv = progress; # added 2015-09-06 + enblendenfuse = enblend-enfuse; # 2015-09-30 + exfat-utils = exfat; # 2015-09-11 + firefoxWrapper = firefox-wrapper; + fuse_exfat = exfat; # 2015-09-11 + haskell-ng = haskell; # 2015-04-19 + haskellngPackages = haskellPackages; # 2015-04-19 + htmlTidy = html-tidy; # added 2014-12-06 + inherit (haskell.compiler) jhc uhc; # 2015-05-15 + inotifyTools = inotify-tools; + jquery_ui = jquery-ui; # added 2014-09-07 + libtidy = html-tidy; # added 2014-12-21 + lttngTools = lttng-tools; # added 2014-07-31 + lttngUst = lttng-ust; # added 2014-07-31 + nfsUtils = nfs-utils; # added 2014-12-06 + quassel_qt5 = kf5Packages.quassel_qt5; # added 2015-09-30 + quasselClient_qt5 = kf5Packages.quasselClient_qt5; # added 2015-09-30 + quasselDaemon_qt5 = kf5Packages.quasselDaemon; # added 2015-09-30 + quassel_kf5 = kf5Packages.quassel; # added 2015-09-30 + quasselClient_kf5 = kf5Packages.quasselClient; # added 2015-09-30 + rdiff_backup = rdiff-backup; # added 2014-11-23 + rssglx = rss-glx; #added 2015-03-25 + rxvt_unicode_with-plugins = rxvt_unicode-with-plugins; # added 2015-04-02 + speedtest_cli = speedtest-cli; # added 2015-02-17 + sqliteInteractive = sqlite-interactive; # added 2014-12-06 + x11 = xlibsWrapper; # added 2015-09 + xf86_video_nouveau = xorg.xf86videonouveau; # added 2015-09 + xlibs = xorg; # added 2015-09 + youtube-dl = pythonPackages.youtube-dl; # added 2015-06-07 + youtubeDL = youtube-dl; # added 2014-10-26 + pidginlatexSF = pidginlatex; # added 2014-11-02 + }; + + tweakAlias = _n: alias: with lib; + if alias.recurseForDerivations or false + then removeAttrs alias ["recurseForDerivations"] + else alias; + + aliases = lib.mapAttrs tweakAlias rawAliases; + + in with self; helperFunctions // aliases // { # Make some arguments passed to all-packages.nix available inherit system platform; @@ -157,7 +207,7 @@ let # will use the new version. overridePackages = f: let - newpkgs = pkgsFun newpkgs overrides; + newpkgs = pkgsFun newpkgs newpkgs // overrides; overrides = mkOverrides pkgs (f newpkgs pkgs); in newpkgs; @@ -15349,56 +15399,5 @@ let mg = callPackage ../applications/editors/mg { }; -}; # self_ = - - - ### Deprecated aliases - for backward compatibility - -aliases = with self; rec { - adobeReader = adobe-reader; - arduino_core = arduino-core; # added 2015-02-04 - asciidocFull = asciidoc-full; # added 2014-06-22 - bridge_utils = bridge-utils; # added 2015-02-20 - buildbotSlave = buildbot-slave; # added 2014-12-09 - cheetahTemplate = pythonPackages.cheetah; # 2015-06-15 - clangAnalyzer = clang-analyzer; # added 2015-02-20 - cool-old-term = cool-retro-term; # added 2015-01-31 - cv = progress; # added 2015-09-06 - enblendenfuse = enblend-enfuse; # 2015-09-30 - exfat-utils = exfat; # 2015-09-11 - firefoxWrapper = firefox-wrapper; - fuse_exfat = exfat; # 2015-09-11 - haskell-ng = haskell; # 2015-04-19 - haskellngPackages = haskellPackages; # 2015-04-19 - htmlTidy = html-tidy; # added 2014-12-06 - inherit (haskell.compiler) jhc uhc; # 2015-05-15 - inotifyTools = inotify-tools; - jquery_ui = jquery-ui; # added 2014-09-07 - libtidy = html-tidy; # added 2014-12-21 - lttngTools = lttng-tools; # added 2014-07-31 - lttngUst = lttng-ust; # added 2014-07-31 - nfsUtils = nfs-utils; # added 2014-12-06 - quassel_qt5 = kf5Packages.quassel_qt5; # added 2015-09-30 - quasselClient_qt5 = kf5Packages.quasselClient_qt5; # added 2015-09-30 - quasselDaemon_qt5 = kf5Packages.quasselDaemon; # added 2015-09-30 - quassel_kf5 = kf5Packages.quassel; # added 2015-09-30 - quasselClient_kf5 = kf5Packages.quasselClient; # added 2015-09-30 - rdiff_backup = rdiff-backup; # added 2014-11-23 - rssglx = rss-glx; #added 2015-03-25 - rxvt_unicode_with-plugins = rxvt_unicode-with-plugins; # added 2015-04-02 - speedtest_cli = speedtest-cli; # added 2015-02-17 - sqliteInteractive = sqlite-interactive; # added 2014-12-06 - x11 = xlibsWrapper; # added 2015-09 - xf86_video_nouveau = xorg.xf86videonouveau; # added 2015-09 - xlibs = xorg; # added 2015-09 - youtube-dl = pythonPackages.youtube-dl; # added 2015-06-07 - youtubeDL = youtube-dl; # added 2014-10-26 - pidginlatexSF = pidginlatex; # added 2014-11-02 }; - -tweakAlias = _n: alias: with lib; - if alias.recurseForDerivations or false then - removeAttrs alias ["recurseForDerivations"] - else alias; - -in lib.mapAttrs tweakAlias aliases // self; in pkgs +in pkgs From 56056f83643b868b9a9e5b883c61914f77028116 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 17 Nov 2015 17:26:06 -0800 Subject: [PATCH 3/4] Massage fix-points `pkgFun` just takes one pkg argument, completing the task of moving all fix-point complexity outside it. applyGlobalOverrides uses pkg set which isn't affected by package overrides for stdenv purposes. Probably this could be cleaner still. --- pkgs/top-level/all-packages.nix | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ab8d59beb7113..f976ae0fb3b21 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -100,33 +100,36 @@ let # ... pkgs.foo ..."). pkgs = applyGlobalOverrides (config.packageOverrides or (pkgs: {})); - mkOverrides = pkgsOrig: overrides: overrides // - (lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem == null) (pkgsOrig.stdenv.overrides pkgsOrig)); + # 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. + mkOverrides = pkgsVanilla: overrides: overrides // (lib.optionalAttrs + (pkgsVanilla.stdenv ? overrides && crossSystem == null) + (pkgsVanilla.stdenv.overrides pkgsVanilla)); # 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); + # Call the overrider function. + overrides = mkOverrides pkgsVanilla (overrider pkgsOrig); - # The un-overriden packages, passed to `overrider'. - pkgsOrig = pkgsFun pkgs pkgsOrig; + # Absolutely un-overriden packages, used to define stdenv before pkg overridesx + pkgsVanilla = pkgsFun pkgsVanilla; + + # The shallowly un-overriden packages, passed to `overrider'. + pkgsOrig = pkgsFun pkgs; # The overriden, final packages. - pkgs = pkgsFun pkgs pkgs // overrides; + pkgs = pkgsOrig // overrides; in pkgs; - # The package compositions. Yes, this isn't properly indented. - pkgsFun = pkgs: self: let + pkgsFun = pkgs: let defaultScope = pkgs // pkgs.xorg; - rawAliases = with self; rec { + rawAliases = with pkgs; rec { adobeReader = adobe-reader; arduino_core = arduino-core; # added 2015-02-04 asciidocFull = asciidoc-full; # added 2014-06-22 @@ -175,7 +178,7 @@ let aliases = lib.mapAttrs tweakAlias rawAliases; - in with self; helperFunctions // aliases // { + in with pkgs; helperFunctions // aliases // { # Make some arguments passed to all-packages.nix available inherit system platform; @@ -207,7 +210,7 @@ let # will use the new version. overridePackages = f: let - newpkgs = pkgsFun newpkgs newpkgs // overrides; + newpkgs = pkgsFun newpkgs // overrides; overrides = mkOverrides pkgs (f newpkgs pkgs); in newpkgs; From fae1f0da9a3097bb104add4c1eea06a9f2f8ed19 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 17 Nov 2015 19:18:39 -0800 Subject: [PATCH 4/4] WIP: Combined `applyGlobalOverrides` and `overridePackages` Also support "chained" usage --- doc/functions.xml | 29 ++++++++++--- pkgs/top-level/all-packages.nix | 72 ++++++++++++++++----------------- 2 files changed, 59 insertions(+), 42 deletions(-) diff --git a/doc/functions.xml b/doc/functions.xml index 39010f8ab1455..e75dc5a965932 100644 --- a/doc/functions.xml +++ b/doc/functions.xml @@ -1,6 +1,6 @@ + xmlns:xlink="http://www.w3.org/1999/xlink" + xml:id="chap-functions"> Functions reference @@ -30,6 +30,25 @@ in ... + + It can be used multiple times in succession to "chain" overrides: + + let + pkgs0 = import <nixpkgs> {}; + pkgs1 = pkgs0.overridePackages (self: super: { + foo = null; + }; + pkgs2 = pkgs1.overridePackages (self: super: { + foo = 1; + bar = super.foo; + baz = self.bar; + }; + pkgs3 = pkgs2.overridePackages (self: super: { + bar = super.foo; + }; +in assert foo == 1; assert bar == 1; assert baz = 1; ... + + The resulting newpkgs will have the new foo expression, and all other expressions depending on foo will also @@ -37,7 +56,7 @@ in ... - The behavior of this function is similar to config.packageOverrides. @@ -49,7 +68,7 @@ in ... The super parameter refers to the old package set. - It's equivalent to pkgs in the above example. + It's equivalent to pkgs in the first example. @@ -91,7 +110,7 @@ in ... The function overrideDerivation is usually available for all the derivations in the nixpkgs expression (pkgs). - + It is used to create a new derivation by overriding the attributes of the original derivation according to the given function. diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f976ae0fb3b21..7475080925861 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -98,32 +98,47 @@ let # (un-overriden) set of packages, allowing packageOverrides # attributes to refer to the original attributes (e.g. "foo = # ... pkgs.foo ..."). - pkgs = applyGlobalOverrides (config.packageOverrides or (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. - mkOverrides = pkgsVanilla: overrides: overrides // (lib.optionalAttrs - (pkgsVanilla.stdenv ? overrides && crossSystem == null) - (pkgsVanilla.stdenv.overrides pkgsVanilla)); - - # 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: + pkgs = let + # Absolutely un-overriden packages, used to define stdenv before pkg overrides + pkgsVanilla = pkgsFun pkgsVanilla; + in overridePackages + pkgsVanilla + pkgsFun + # TODO: break compat and use self and super in config too. + (self: super: (config.packageOverrides or (pkgs: {})) super); + + + # Easily override this package set. + # Warning: this function is very expensive and must not be used + # from within the nixpkgs repository. + # + # See manual / XML for more documentation. + overridePackages = pkgsForStdenv: # pkgSet + oldOverriders: # pkgSet -> pkgSet + overrider: # pkgSet -> pkgSet -> pkgSet let - # Call the overrider function. - overrides = mkOverrides pkgsVanilla (overrider pkgsOrig); + rawOverrides = overrider self super; - # Absolutely un-overriden packages, used to define stdenv before pkg overridesx - pkgsVanilla = pkgsFun pkgsVanilla; + # 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 = rawOverrides // (lib.optionalAttrs + (pkgsForStdenv.stdenv ? overrides && crossSystem == null) + (pkgsForStdenv.stdenv.overrides pkgsForStdenv)); # The shallowly un-overriden packages, passed to `overrider'. - pkgsOrig = pkgsFun pkgs; + super = oldOverriders self; + + # Allow downstream overriding + overrideMore = nextOverrider: overridePackages + self + (self: ((overrider self) (oldOverriders self))) + nextOverrider; # The overriden, final packages. - pkgs = pkgsOrig // overrides; - in pkgs; + self = super // overrides // { overridePackages = overrideMore; }; + in self; + # The package compositions. Yes, this isn't properly indented. pkgsFun = pkgs: let @@ -197,23 +212,6 @@ let 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: - 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. forceSystem = system: kernel: (import ./all-packages.nix) { inherit system;