-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use fix and extend function for all-packages.nix #14000
Changes from all commits
9444d6e
a39c5ff
11a566b
5f4cb91
f9a2988
a6e260c
a5188bd
00963c3
acaa99c
71b2fd9
a8374f2
a658645
ffcb668
8d355b8
7f3a4f4
020bb40
be3531a
f7c86ee
0b67f7c
a09683e
f043ffc
0543277
007500f
5e3ce63
32e96bb
07e549e
a543a57
ad31783
335a969
ae0471b
5cdaa7b
ff72cf1
01693ac
f8dedbb
5783f66
a190baa
598ed87
9e8c520
21b8007
800766f
1bcefcd
5ae7356
aa7f0fc
87ad35e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,133 +1,16 @@ | ||
/* This file composes the Nix Packages collection. That is, it | ||
imports the functions that build the various packages, and calls | ||
them with appropriate arguments. The result is a set of all the | ||
packages in the Nix Packages collection for some particular | ||
platform. */ | ||
{ system, bootStdenv, noSysDirs, gccWithCC, gccWithProfiling | ||
, config, crossSystem, platform, lib | ||
, pkgsWithOverrides | ||
, ... }: | ||
self: pkgs: | ||
|
||
|
||
{ # The system (e.g., `i686-linux') for which to build the packages. | ||
system ? builtins.currentSystem | ||
|
||
, # The standard environment to use. Only used for bootstrapping. If | ||
# null, the default standard environment is used. | ||
bootStdenv ? null | ||
|
||
, # Non-GNU/Linux OSes are currently "impure" platforms, with their libc | ||
# outside of the store. Thus, GCC, GFortran, & co. must always look for | ||
# files in standard system directories (/usr/include, etc.) | ||
noSysDirs ? (system != "x86_64-freebsd" && system != "i686-freebsd" | ||
&& system != "x86_64-solaris" | ||
&& system != "x86_64-kfreebsd-gnu") | ||
|
||
# More flags for the bootstrapping of stdenv. | ||
, gccWithCC ? true | ||
, gccWithProfiling ? true | ||
|
||
, # Allow a configuration attribute set to be passed in as an | ||
# argument. Otherwise, it's read from $NIXPKGS_CONFIG or | ||
# ~/.nixpkgs/config.nix. | ||
config ? null | ||
|
||
, crossSystem ? null | ||
, platform ? null | ||
}: | ||
|
||
|
||
let config_ = config; platform_ = platform; in # rename the function arguments | ||
with pkgs; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be While you've argued well that aliases should refer to the unoverriden packages, dependencies should definitely be overridden. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the final result, self is equivalent to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
let | ||
defaultScope = pkgs // pkgs.xorg; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as #14000 (comment), shouldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok based on other thread it is the fixed point being used here as I wanted all along :). |
||
in | ||
|
||
lib = import ../../lib; | ||
|
||
# The contents of the configuration file found at $NIXPKGS_CONFIG or | ||
# $HOME/.nixpkgs/config.nix. | ||
# for NIXOS (nixos-rebuild): use nixpkgs.config option | ||
config = | ||
let | ||
toPath = builtins.toPath; | ||
getEnv = x: if builtins ? getEnv then builtins.getEnv x else ""; | ||
pathExists = name: | ||
builtins ? pathExists && builtins.pathExists (toPath name); | ||
|
||
configFile = getEnv "NIXPKGS_CONFIG"; | ||
homeDir = getEnv "HOME"; | ||
configFile2 = homeDir + "/.nixpkgs/config.nix"; | ||
|
||
configExpr = | ||
if config_ != null then config_ | ||
else if configFile != "" && pathExists configFile then import (toPath configFile) | ||
else if homeDir != "" && pathExists configFile2 then import (toPath configFile2) | ||
else {}; | ||
|
||
in | ||
# allow both: | ||
# { /* the config */ } and | ||
# { pkgs, ... } : { /* the config */ } | ||
if builtins.isFunction configExpr | ||
then configExpr { inherit pkgs; } | ||
else configExpr; | ||
|
||
# Allow setting the platform in the config file. Otherwise, let's use a reasonable default (pc) | ||
|
||
platformAuto = let | ||
platforms = (import ./platforms.nix); | ||
in | ||
if system == "armv6l-linux" then platforms.raspberrypi | ||
else if system == "armv7l-linux" then platforms.armv7l-hf-multiplatform | ||
else if system == "armv5tel-linux" then platforms.sheevaplug | ||
else if system == "mips64el-linux" then platforms.fuloong2f_n32 | ||
else if system == "x86_64-linux" then platforms.pc64 | ||
else if system == "i686-linux" then platforms.pc32 | ||
else platforms.pcBase; | ||
|
||
platform = if platform_ != null then platform_ | ||
else config.platform or platformAuto; | ||
|
||
# Helper functions that are exported through `pkgs'. | ||
helperFunctions = | ||
stdenvAdapters // | ||
(import ../build-support/trivial-builders.nix { inherit lib; inherit (pkgs) stdenv; inherit (pkgs.xorg) lndir; }); | ||
|
||
stdenvAdapters = | ||
import ../stdenv/adapters.nix pkgs; | ||
|
||
|
||
# Allow packages to be overriden globally via the `packageOverrides' | ||
# configuration option, which must be a function that takes `pkgs' | ||
# as an argument and returns a set of new or overriden packages. | ||
# The `packageOverrides' function is called with the *original* | ||
# (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: {})); | ||
|
||
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 | ||
# 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); | ||
|
||
# The un-overriden packages, passed to `overrider'. | ||
pkgsOrig = pkgsFun pkgs {}; | ||
|
||
# The overriden, final packages. | ||
pkgs = pkgsFun pkgs overrides; | ||
in pkgs; | ||
|
||
|
||
# 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 // { | ||
{ | ||
|
||
# Make some arguments passed to all-packages.nix available | ||
inherit system platform; | ||
|
@@ -157,11 +40,7 @@ let | |
# | ||
# 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; | ||
overridePackages = f: pkgsWithOverrides f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This replaces let # for syntax coloring
reoverridePackages = f: fix' (extend f self.__unfix__); (bikeshed name of course) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what should be done with this I did not went for using the unfix attribute for one simple reason. The current version of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough, this can be dealt with separately. The fact that nixpkgs even has such |
||
|
||
# Override system. This is useful to build i686 packages on x86_64-linux. | ||
forceSystem = system: kernel: (import ./../..) { | ||
|
@@ -171,19 +50,31 @@ let | |
crossSystem; | ||
}; | ||
|
||
|
||
# Used by wine, firefox with debugging version of Flash, ... | ||
pkgsi686Linux = forceSystem "i686-linux" "i386"; | ||
|
||
callPackage_i686 = lib.callPackageWith (pkgsi686Linux // pkgsi686Linux.xorg); | ||
|
||
forceNativeDrv = drv : if crossSystem == null then drv else | ||
(drv // { crossDrv = drv.nativeDrv; }); | ||
|
||
stdenvCross = lowPrio (makeStdenvCross defaultStdenv crossSystem binutilsCross gccCrossStageFinal); | ||
|
||
# A stdenv capable of building 32-bit binaries. On x86_64-linux, | ||
# it uses GCC compiled with multilib support; on i686-linux, it's | ||
# just the plain stdenv. | ||
stdenv_32bit = lowPrio ( | ||
if system == "x86_64-linux" then | ||
overrideCC stdenv gcc_multi | ||
else | ||
stdenv); | ||
|
||
# For convenience, allow callers to get the path to Nixpkgs. | ||
path = ../..; | ||
|
||
|
||
### Helper functions. | ||
inherit lib config stdenvAdapters; | ||
inherit lib config; | ||
|
||
inherit (lib) lowPrio hiPrio appendToName makeOverridable; | ||
inherit (misc) versionedDerivation; | ||
|
@@ -206,49 +97,6 @@ let | |
nixpkgs-lint = callPackage ../../maintainers/scripts/nixpkgs-lint.nix { }; | ||
|
||
|
||
### STANDARD ENVIRONMENT | ||
|
||
|
||
allStdenvs = import ../stdenv { | ||
inherit system platform config lib; | ||
allPackages = args: import ./../.. ({ inherit config system; } // args); | ||
}; | ||
|
||
defaultStdenv = allStdenvs.stdenv // { inherit platform; }; | ||
|
||
stdenvCross = lowPrio (makeStdenvCross defaultStdenv crossSystem binutilsCross gccCrossStageFinal); | ||
|
||
stdenv = | ||
if bootStdenv != null then (bootStdenv // {inherit platform;}) else | ||
if crossSystem != null then | ||
stdenvCross | ||
else | ||
let | ||
changer = config.replaceStdenv or null; | ||
in if changer != null then | ||
changer { | ||
# We import again all-packages to avoid recursivities. | ||
pkgs = import ./../.. { | ||
# We remove packageOverrides to avoid recursivities | ||
config = removeAttrs config [ "replaceStdenv" ]; | ||
}; | ||
} | ||
else | ||
defaultStdenv; | ||
|
||
forceNativeDrv = drv : if crossSystem == null then drv else | ||
(drv // { crossDrv = drv.nativeDrv; }); | ||
|
||
# A stdenv capable of building 32-bit binaries. On x86_64-linux, | ||
# it uses GCC compiled with multilib support; on i686-linux, it's | ||
# just the plain stdenv. | ||
stdenv_32bit = lowPrio ( | ||
if system == "x86_64-linux" then | ||
overrideCC stdenv gcc_multi | ||
else | ||
stdenv); | ||
|
||
|
||
### BUILD SUPPORT | ||
|
||
attrSetToDir = arg: callPackage ../build-support/upstream-updater/attrset-to-dir.nix { | ||
|
@@ -303,9 +151,7 @@ let | |
dotnetfx = dotnetfx40; | ||
}; | ||
|
||
dotnetbuildhelpers = callPackage ../build-support/dotnetbuildhelpers { | ||
inherit helperFunctions; | ||
}; | ||
dotnetbuildhelpers = callPackage ../build-support/dotnetbuildhelpers { }; | ||
|
||
dispad = callPackage ../tools/X11/dispad { }; | ||
|
||
|
@@ -16468,14 +16314,5 @@ let | |
|
||
mg = callPackage ../applications/editors/mg { }; | ||
|
||
}; # self_ = | ||
|
||
|
||
aliases = import ./aliases.nix self; | ||
|
||
tweakAlias = _n: alias: with lib; | ||
if alias.recurseForDerivations or false then | ||
removeAttrs alias ["recurseForDerivations"] | ||
else alias; | ||
} | ||
|
||
in lib.mapAttrs tweakAlias aliases // self; in pkgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function can be simplified to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of that, but I have not done it because this adds extra computations, which is not desirable. For example if you have a large attribute set, you would decompose it to recompose it without one attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't
removeAttrs
return the same set if nothing has changed ? In any case this is not new code so it can stay the same.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/NixOS/nix/blob/master/src/libexpr/primops.cc#L1060-L1080
Yes, the attribute will contain the same content, but this would be a new one.
I guess this would be easy to fix in Nix.