1 /* This file composes a single bootstrapping stage of the Nix Packages
2 collection. That is, it imports the functions that build the various
3 packages, and calls them with appropriate arguments. The result is a set of
4 all the packages in the Nix Packages collection for some particular platform
5 for some particular stage.
7 Default arguments are only provided for bootstrapping
8 arguments. Normal users should not import this directly but instead
9 import `pkgs/default.nix` or `default.nix`. */
12 { ## Misc parameters kept the same for all stages
15 # Utility functions, could just import but passing in for efficiency
18 , # Use to reevaluate Nixpkgs
24 , # Either null or an object in the form:
27 # pkgsBuildBuild = ...;
28 # pkgsBuildHost = ...;
29 # pkgsBuildTarget = ...;
31 # # pkgsHostTarget skipped on purpose.
32 # pkgsTargetTarget ...;
35 # These are references to adjacent bootstrapping stages. The more familiar
36 # `buildPackages` and `targetPackages` are defined in terms of them. If null,
37 # they are instead defined internally as the current stage. This allows us to
38 # avoid expensive splicing. `pkgsHostTarget` is skipped because it is always
39 # defined as the current stage.
42 , # The standard environment to use for building packages.
45 , # This is used because stdenv replacement and the stdenvCross do benefit from
46 # the overridden configuration provided by the user, as opposed to the normal
47 # bootstrapping stdenvs.
50 , # Non-GNU/Linux OSes are currently "impure" platforms, with their libc
51 # outside of the store. Thus, GCC, GFortran, & co. must always look for files
52 # in standard system directories (/usr/include, etc.)
53 noSysDirs ? stdenv.buildPlatform.system != "x86_64-freebsd"
54 && stdenv.buildPlatform.system != "i686-freebsd"
55 && stdenv.buildPlatform.system != "x86_64-solaris"
56 && stdenv.buildPlatform.system != "x86_64-kfreebsd-gnu"
58 , # The configuration attribute set
61 , # A list of overlays (Additional `self: super: { .. }` customization
62 # functions) to be fixed together in the produced package set
67 # This is a function from parsed platforms (like
68 # stdenv.hostPlatform.parsed) to parsed platforms.
69 makeMuslParsedPlatform = parsed:
70 # The following line guarantees that the output of this function
71 # is a well-formed platform with no missing fields. It will be
72 # uncommented in a separate PR, in case it breaks the build.
73 #(x: lib.trivial.pipe x [ (x: builtins.removeAttrs x [ "_type" ]) lib.systems.parse.mkSystem ])
76 gnu = lib.systems.parse.abis.musl;
77 gnueabi = lib.systems.parse.abis.musleabi;
78 gnueabihf = lib.systems.parse.abis.musleabihf;
79 gnuabin32 = lib.systems.parse.abis.muslabin32;
80 gnuabi64 = lib.systems.parse.abis.muslabi64;
81 gnuabielfv2 = lib.systems.parse.abis.musl;
82 gnuabielfv1 = lib.systems.parse.abis.musl;
83 # The following two entries ensure that this function is idempotent.
84 musleabi = lib.systems.parse.abis.musleabi;
85 musleabihf = lib.systems.parse.abis.musleabihf;
86 muslabin32 = lib.systems.parse.abis.muslabin32;
87 muslabi64 = lib.systems.parse.abis.muslabi64;
89 or lib.systems.parse.abis.musl;
93 stdenvAdapters = self: super:
95 res = import ../stdenv/adapters.nix {
100 stdenvAdapters = res;
103 trivialBuilders = self: super:
104 import ../build-support/trivial-builders.nix {
106 inherit (self) runtimeShell stdenv stdenvNoCC;
107 inherit (self.pkgsBuildHost) shellcheck;
108 inherit (self.pkgsBuildHost.xorg) lndir;
111 stdenvBootstappingAndPlatforms = self: super: let
112 withFallback = thisPkgs:
113 (if adjacentPackages == null then self else thisPkgs)
114 // { recurseForDerivations = false; };
116 # Here are package sets of from related stages. They are all in the form
117 # `pkgs{theirHost}{theirTarget}`. For example, `pkgsBuildHost` means their
118 # host platform is our build platform, and their target platform is our host
119 # platform. We only care about their host/target platforms, not their build
120 # platform, because the the former two alone affect the interface of the
121 # final package; the build platform is just an implementation detail that
123 pkgsBuildBuild = withFallback adjacentPackages.pkgsBuildBuild;
124 pkgsBuildHost = withFallback adjacentPackages.pkgsBuildHost;
125 pkgsBuildTarget = withFallback adjacentPackages.pkgsBuildTarget;
126 pkgsHostHost = withFallback adjacentPackages.pkgsHostHost;
127 pkgsHostTarget = self // { recurseForDerivations = false; }; # always `self`
128 pkgsTargetTarget = withFallback adjacentPackages.pkgsTargetTarget;
130 # Older names for package sets. Use these when only the host platform of the
131 # package set matter (i.e. use `buildPackages` where any of `pkgsBuild*`
132 # would do, and `targetPackages` when any of `pkgsTarget*` would do (if we
133 # had more than just `pkgsTargetTarget`).)
134 buildPackages = self.pkgsBuildHost;
135 pkgs = self.pkgsHostTarget;
136 targetPackages = self.pkgsTargetTarget;
141 # The old identifiers for cross-compiling. These should eventually be removed,
142 # and the packages that rely on them refactored accordingly.
143 platformCompat = self: super: let
144 inherit (super.stdenv) buildPlatform hostPlatform targetPlatform;
146 inherit buildPlatform hostPlatform targetPlatform;
149 splice = self: super: import ./splice.nix lib self (adjacentPackages != null);
151 allPackages = self: super:
152 let res = import ./all-packages.nix
153 { inherit lib noSysDirs config overlays; }
157 aliases = self: super: lib.optionalAttrs config.allowAliases (import ./aliases.nix lib self super);
159 # stdenvOverrides is used to avoid having multiple of versions
160 # of certain dependencies that were used in bootstrapping the
161 # standard environment.
162 stdenvOverrides = self: super:
163 (super.stdenv.overrides or (_: _: {})) self super;
165 # Allow packages to be overridden globally via the `packageOverrides'
166 # configuration option, which must be a function that takes `pkgs'
167 # as an argument and returns a set of new or overridden packages.
168 # The `packageOverrides' function is called with the *original*
169 # (un-overridden) set of packages, allowing packageOverrides
170 # attributes to refer to the original attributes (e.g. "foo =
171 # ... pkgs.foo ...").
172 configOverrides = self: super:
173 lib.optionalAttrs allowCustomOverrides
174 ((config.packageOverrides or (super: {})) super);
176 # Convenience attributes for instantitating package sets. Each of
177 # these will instantiate a new version of allPackages. Currently the
178 # following package sets are provided:
180 # - pkgsCross.<system> where system is a member of lib.systems.examples
183 otherPackageSets = self: super: {
184 # This maps each entry in lib.systems.examples to its own package
185 # set. Each of these will contain all packages cross compiled for
186 # that target system. For instance, pkgsCross.raspberryPi.hello,
187 # will refer to the "hello" package built for the ARM6-based
189 pkgsCross = lib.mapAttrs (n: crossSystem:
190 nixpkgsFun { inherit crossSystem; })
191 lib.systems.examples;
193 pkgsLLVM = nixpkgsFun {
199 # Bootstrap a cross stdenv using the LLVM toolchain.
200 # This is currently not possible when compiling natively,
201 # so we don't need to check hostPlatform != buildPlatform.
202 crossSystem = stdenv.hostPlatform // {
208 # All packages built with the Musl libc. This will override the
209 # default GNU libc on Linux systems. Non-Linux systems are not
211 pkgsMusl = if stdenv.hostPlatform.isLinux then nixpkgsFun {
212 overlays = [ (self': super': {
215 ${if stdenv.hostPlatform == stdenv.buildPlatform
216 then "localSystem" else "crossSystem"} = {
217 parsed = makeMuslParsedPlatform stdenv.hostPlatform.parsed;
219 } else throw "Musl libc only supports Linux systems.";
221 # All packages built for i686 Linux.
222 # Used by wine, firefox with debugging version of Flash, ...
223 pkgsi686Linux = if stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86 then nixpkgsFun {
224 overlays = [ (self': super': {
225 pkgsi686Linux = super';
227 ${if stdenv.hostPlatform == stdenv.buildPlatform
228 then "localSystem" else "crossSystem"} = {
229 parsed = stdenv.hostPlatform.parsed // {
230 cpu = lib.systems.parse.cpuTypes.i686;
233 } else throw "i686 Linux package set can only be used with the x86 family.";
235 # x86_64-darwin packages for aarch64-darwin users to use with Rosetta for incompatible packages
236 pkgsx86_64Darwin = if stdenv.hostPlatform.isDarwin then nixpkgsFun {
237 overlays = [ (self': super': {
238 pkgsx86_64Darwin = super';
241 parsed = stdenv.hostPlatform.parsed // {
242 cpu = lib.systems.parse.cpuTypes.x86_64;
245 } else throw "x86_64 Darwin package set can only be used on Darwin systems.";
247 # Extend the package set with zero or more overlays. This preserves
248 # preexisting overlays. Prefer to initialize with the right overlays
249 # in one go when calling Nixpkgs, for performance and simplicity.
250 appendOverlays = extraOverlays:
251 if extraOverlays == []
253 else nixpkgsFun { overlays = args.overlays ++ extraOverlays; };
255 # NOTE: each call to extend causes a full nixpkgs rebuild, adding ~130MB
256 # of allocations. DO NOT USE THIS IN NIXPKGS.
258 # Extend the package set with a single overlay. This preserves
259 # preexisting overlays. Prefer to initialize with the right overlays
260 # in one go when calling Nixpkgs, for performance and simplicity.
261 # Prefer appendOverlays if used repeatedly.
262 extend = f: self.appendOverlays [f];
264 # Fully static packages.
265 # Currently uses Musl on Linux (couldn’t get static glibc to work).
266 pkgsStatic = nixpkgsFun ({
267 overlays = [ (self': super': {
270 } // lib.optionalAttrs stdenv.hostPlatform.isLinux {
273 parsed = makeMuslParsedPlatform stdenv.hostPlatform.parsed;
274 } // lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") {
280 # The complete chain of package set builders, applied from top to bottom.
281 # stdenvOverlays must be last as it brings package forward from the
282 # previous bootstrapping phases which have already been overlayed.
283 toFix = lib.foldl' (lib.flip lib.extends) (self: {}) ([
284 stdenvBootstappingAndPlatforms
297 # Return the complete set of packages.