From 7f5f9072ad487ff6b3bffce716943d46fb167813 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Wed, 24 Jun 2015 22:57:37 +0200 Subject: [PATCH] all-packages.nix: Add pkgs.overridePackages --- doc/functions.xml | 57 +++++++++++++++++++++++++++++++++ doc/manual.xml | 1 + pkgs/top-level/all-packages.nix | 21 ++++++++++-- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 doc/functions.xml diff --git a/doc/functions.xml b/doc/functions.xml new file mode 100644 index 00000000000..16f4f262a25 --- /dev/null +++ b/doc/functions.xml @@ -0,0 +1,57 @@ + + +Functions reference + + + The nixpkgs repository has several utility functions to manipulate Nix expressions. + + +
+ pkgs.overridePackages + + + This function inside the nixpkgs expression (pkgs) + can be used to override the set of packages itself. + + + Warning: this function is expensive and must not be used from within + the nixpkgs repository. + + + Example usage: + + let + pkgs = import <nixpkgs> {}; + newpkgs = pkgs.overridePackages (self: super: { + foo = super.foo.override { ... }; + }; +in ... + + + + The resulting newpkgs will have the new foo + expression, and all other expressions depending on foo will also + use the new foo expression. + + + + The behavior of this function is similar to config.packageOverrides. + + + + The self parameter refers to the final package set with the + applied overrides. Using this parameter may lead to infinite recursion if not + used consciously. + + + + The super parameter refers to the old package set. + It's equivalent to pkgs in the above example. + + +
+ +
diff --git a/doc/manual.xml b/doc/manual.xml index a6400c98d6e..11f37184e6d 100644 --- a/doc/manual.xml +++ b/doc/manual.xml @@ -13,6 +13,7 @@ + diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e7d5caa4471..876db4b0236 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -100,6 +100,8 @@ let # ... pkgs.foo ..."). pkgs = applyGlobalOverrides (config.packageOverrides or (pkgs: {})); + mkOverrides = pkgsOrig: overrides: overrides // + (lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem == null) (pkgsOrig.stdenv.overrides pkgsOrig)); # Return the complete set of packages, after applying the overrides # returned by the `overrider' function (see above). Warning: this @@ -110,8 +112,7 @@ let # in the case of cross-building, or otherwise the basic # overrided packages will not be built with the crossStdenv # adapter. - overrides = overrider pkgsOrig // - (lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem == null) (pkgsOrig.stdenv.overrides pkgsOrig)); + overrides = mkOverrides pkgsOrig (overrider pkgsOrig); # The un-overriden packages, passed to `overrider'. pkgsOrig = pkgsFun pkgs {}; @@ -142,6 +143,22 @@ 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) {