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 # An overlay to auto-call packages in ../by-name.
13 # By defining it at the top of the file,
14 # this value gets reused even if this file is imported multiple times,
15 # thanks to Nix's import-value cache.
16 autoCalledPackages = import ./by-name-overlay.nix ../by-name;
19 { ## Misc parameters kept the same for all stages
22 # Utility functions, could just import but passing in for efficiency
25 , # Use to reevaluate Nixpkgs
31 , # Either null or an object in the form:
34 # pkgsBuildBuild = ...;
35 # pkgsBuildHost = ...;
36 # pkgsBuildTarget = ...;
38 # # pkgsHostTarget skipped on purpose.
39 # pkgsTargetTarget ...;
42 # These are references to adjacent bootstrapping stages. The more familiar
43 # `buildPackages` and `targetPackages` are defined in terms of them. If null,
44 # they are instead defined internally as the current stage. This allows us to
45 # avoid expensive splicing. `pkgsHostTarget` is skipped because it is always
46 # defined as the current stage.
49 , # The standard environment to use for building packages.
52 , # This is used because stdenv replacement and the stdenvCross do benefit from
53 # the overridden configuration provided by the user, as opposed to the normal
54 # bootstrapping stdenvs.
57 , # Non-GNU/Linux OSes are currently "impure" platforms, with their libc
58 # outside of the store. Thus, GCC, GFortran, & co. must always look for files
59 # in standard system directories (/usr/include, etc.)
60 noSysDirs ? stdenv.buildPlatform.system != "x86_64-freebsd"
61 && stdenv.buildPlatform.system != "i686-freebsd"
62 && stdenv.buildPlatform.system != "x86_64-solaris"
63 && stdenv.buildPlatform.system != "x86_64-kfreebsd-gnu"
65 , # The configuration attribute set
68 , # A list of overlays (Additional `self: super: { .. }` customization
69 # functions) to be fixed together in the produced package set
74 # This is a function from parsed platforms (like
75 # stdenv.hostPlatform.parsed) to parsed platforms.
76 makeMuslParsedPlatform = parsed:
77 # The following line guarantees that the output of this function
78 # is a well-formed platform with no missing fields. It will be
79 # uncommented in a separate PR, in case it breaks the build.
80 #(x: lib.trivial.pipe x [ (x: builtins.removeAttrs x [ "_type" ]) lib.systems.parse.mkSystem ])
83 gnu = lib.systems.parse.abis.musl;
84 gnueabi = lib.systems.parse.abis.musleabi;
85 gnueabihf = lib.systems.parse.abis.musleabihf;
86 gnuabin32 = lib.systems.parse.abis.muslabin32;
87 gnuabi64 = lib.systems.parse.abis.muslabi64;
88 gnuabielfv2 = lib.systems.parse.abis.musl;
89 gnuabielfv1 = lib.systems.parse.abis.musl;
90 # The following two entries ensure that this function is idempotent.
91 musleabi = lib.systems.parse.abis.musleabi;
92 musleabihf = lib.systems.parse.abis.musleabihf;
93 muslabin32 = lib.systems.parse.abis.muslabin32;
94 muslabi64 = lib.systems.parse.abis.muslabi64;
96 or lib.systems.parse.abis.musl;
100 stdenvAdapters = self: super:
102 res = import ../stdenv/adapters.nix {
107 stdenvAdapters = res;
110 trivialBuilders = self: super:
111 import ../build-support/trivial-builders {
113 inherit (self) config;
114 inherit (self) runtimeShell stdenv stdenvNoCC;
115 inherit (self.pkgsBuildHost) jq shellcheck-minimal;
116 inherit (self.pkgsBuildHost.xorg) lndir;
119 stdenvBootstappingAndPlatforms = self: super: let
120 withFallback = thisPkgs:
121 (if adjacentPackages == null then self else thisPkgs)
122 // { recurseForDerivations = false; };
124 # Here are package sets of from related stages. They are all in the form
125 # `pkgs{theirHost}{theirTarget}`. For example, `pkgsBuildHost` means their
126 # host platform is our build platform, and their target platform is our host
127 # platform. We only care about their host/target platforms, not their build
128 # platform, because the the former two alone affect the interface of the
129 # final package; the build platform is just an implementation detail that
131 pkgsBuildBuild = withFallback adjacentPackages.pkgsBuildBuild;
132 pkgsBuildHost = withFallback adjacentPackages.pkgsBuildHost;
133 pkgsBuildTarget = withFallback adjacentPackages.pkgsBuildTarget;
134 pkgsHostHost = withFallback adjacentPackages.pkgsHostHost;
135 pkgsHostTarget = self // { recurseForDerivations = false; }; # always `self`
136 pkgsTargetTarget = withFallback adjacentPackages.pkgsTargetTarget;
138 # Older names for package sets. Use these when only the host platform of the
139 # package set matter (i.e. use `buildPackages` where any of `pkgsBuild*`
140 # would do, and `targetPackages` when any of `pkgsTarget*` would do (if we
141 # had more than just `pkgsTargetTarget`).)
142 buildPackages = self.pkgsBuildHost;
143 pkgs = self.pkgsHostTarget;
144 targetPackages = self.pkgsTargetTarget;
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
210 # supported. 32-bit is also not supported.
211 pkgsMusl = if stdenv.hostPlatform.isLinux && stdenv.buildPlatform.is64bit 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 64-bit 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 # If already linux: the same package set unaltered
248 # Otherwise, return a natively built linux package set for the current cpu architecture string.
249 # (ABI and other details will be set to the default for the cpu/os pair)
251 if stdenv.hostPlatform.isLinux
254 localSystem = lib.systems.elaborate "${stdenv.hostPlatform.parsed.cpu.name}-linux";
257 # Extend the package set with zero or more overlays. This preserves
258 # preexisting overlays. Prefer to initialize with the right overlays
259 # in one go when calling Nixpkgs, for performance and simplicity.
260 appendOverlays = extraOverlays:
261 if extraOverlays == []
263 else nixpkgsFun { overlays = args.overlays ++ extraOverlays; };
265 # NOTE: each call to extend causes a full nixpkgs rebuild, adding ~130MB
266 # of allocations. DO NOT USE THIS IN NIXPKGS.
268 # Extend the package set with a single overlay. This preserves
269 # preexisting overlays. Prefer to initialize with the right overlays
270 # in one go when calling Nixpkgs, for performance and simplicity.
271 # Prefer appendOverlays if used repeatedly.
272 extend = f: self.appendOverlays [f];
274 # Fully static packages.
275 # Currently uses Musl on Linux (couldn’t get static glibc to work).
276 pkgsStatic = nixpkgsFun ({
277 overlays = [ (self': super': {
284 then makeMuslParsedPlatform stdenv.hostPlatform.parsed
285 else stdenv.hostPlatform.parsed;
286 } // lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") {
291 pkgsExtraHardening = nixpkgsFun {
294 pkgsExtraHardening = super';
295 stdenv = super'.withDefaultHardeningFlags (
296 super'.stdenv.cc.defaultHardeningFlags ++ [
306 # The complete chain of package set builders, applied from top to bottom.
307 # stdenvOverlays must be last as it brings package forward from the
308 # previous bootstrapping phases which have already been overlayed.
309 toFix = lib.foldl' (lib.flip lib.extends) (self: {}) ([
310 stdenvBootstappingAndPlatforms
323 # Return the complete set of packages.