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 , # `stdenv` without a C compiler. Passing in this helps avoid infinite
53 # recursions, and may eventually replace passing in the full stdenv.
54 stdenvNoCC ? stdenv.override { cc = null; hasCC = false; }
56 , # This is used because stdenv replacement and the stdenvCross do benefit from
57 # the overridden configuration provided by the user, as opposed to the normal
58 # bootstrapping stdenvs.
61 , # Non-GNU/Linux OSes are currently "impure" platforms, with their libc
62 # outside of the store. Thus, GCC, GFortran, & co. must always look for files
63 # in standard system directories (/usr/include, etc.)
64 noSysDirs ? stdenv.buildPlatform.system != "x86_64-solaris"
65 && stdenv.buildPlatform.system != "x86_64-kfreebsd-gnu"
67 , # The configuration attribute set
70 , # A list of overlays (Additional `self: super: { .. }` customization
71 # functions) to be fixed together in the produced package set
76 # This is a function from parsed platforms (like
77 # stdenv.hostPlatform.parsed) to parsed platforms.
78 makeMuslParsedPlatform = parsed:
79 # The following line guarantees that the output of this function
80 # is a well-formed platform with no missing fields. It will be
81 # uncommented in a separate PR, in case it breaks the build.
82 #(x: lib.trivial.pipe x [ (x: builtins.removeAttrs x [ "_type" ]) lib.systems.parse.mkSystem ])
85 gnu = lib.systems.parse.abis.musl;
86 gnueabi = lib.systems.parse.abis.musleabi;
87 gnueabihf = lib.systems.parse.abis.musleabihf;
88 gnuabin32 = lib.systems.parse.abis.muslabin32;
89 gnuabi64 = lib.systems.parse.abis.muslabi64;
90 gnuabielfv2 = lib.systems.parse.abis.musl;
91 gnuabielfv1 = lib.systems.parse.abis.musl;
92 # The following two entries ensure that this function is idempotent.
93 musleabi = lib.systems.parse.abis.musleabi;
94 musleabihf = lib.systems.parse.abis.musleabihf;
95 muslabin32 = lib.systems.parse.abis.muslabin32;
96 muslabi64 = lib.systems.parse.abis.muslabi64;
98 or lib.systems.parse.abis.musl;
102 stdenvAdapters = self: super:
104 res = import ../stdenv/adapters.nix {
109 stdenvAdapters = res;
112 trivialBuilders = self: super:
113 import ../build-support/trivial-builders {
115 inherit (self) config;
116 inherit (self) runtimeShell stdenv stdenvNoCC;
117 inherit (self.pkgsBuildHost) jq shellcheck-minimal;
118 inherit (self.pkgsBuildHost.xorg) lndir;
121 stdenvBootstappingAndPlatforms = self: super: let
122 withFallback = thisPkgs:
123 (if adjacentPackages == null then self else thisPkgs)
124 // { recurseForDerivations = false; };
126 # Here are package sets of from related stages. They are all in the form
127 # `pkgs{theirHost}{theirTarget}`. For example, `pkgsBuildHost` means their
128 # host platform is our build platform, and their target platform is our host
129 # platform. We only care about their host/target platforms, not their build
130 # platform, because the the former two alone affect the interface of the
131 # final package; the build platform is just an implementation detail that
133 pkgsBuildBuild = withFallback adjacentPackages.pkgsBuildBuild;
134 pkgsBuildHost = withFallback adjacentPackages.pkgsBuildHost;
135 pkgsBuildTarget = withFallback adjacentPackages.pkgsBuildTarget;
136 pkgsHostHost = withFallback adjacentPackages.pkgsHostHost;
137 pkgsHostTarget = self // { recurseForDerivations = false; }; # always `self`
138 pkgsTargetTarget = withFallback adjacentPackages.pkgsTargetTarget;
140 # Older names for package sets. Use these when only the host platform of the
141 # package set matter (i.e. use `buildPackages` where any of `pkgsBuild*`
142 # would do, and `targetPackages` when any of `pkgsTarget*` would do (if we
143 # had more than just `pkgsTargetTarget`).)
144 buildPackages = self.pkgsBuildHost;
145 pkgs = self.pkgsHostTarget;
146 targetPackages = self.pkgsTargetTarget;
148 inherit stdenv stdenvNoCC;
151 splice = self: super: import ./splice.nix lib self (adjacentPackages != null);
153 allPackages = self: super:
154 let res = import ./all-packages.nix
155 { inherit lib noSysDirs config overlays; }
159 aliases = self: super: lib.optionalAttrs config.allowAliases (import ./aliases.nix lib self super);
161 # stdenvOverrides is used to avoid having multiple of versions
162 # of certain dependencies that were used in bootstrapping the
163 # standard environment.
164 stdenvOverrides = self: super:
165 (super.stdenv.overrides or (_: _: {})) self super;
167 # Allow packages to be overridden globally via the `packageOverrides'
168 # configuration option, which must be a function that takes `pkgs'
169 # as an argument and returns a set of new or overridden packages.
170 # The `packageOverrides' function is called with the *original*
171 # (un-overridden) set of packages, allowing packageOverrides
172 # attributes to refer to the original attributes (e.g. "foo =
173 # ... pkgs.foo ...").
174 configOverrides = self: super:
175 lib.optionalAttrs allowCustomOverrides
176 ((config.packageOverrides or (super: {})) super);
178 # Convenience attributes for instantitating package sets. Each of
179 # these will instantiate a new version of allPackages. Currently the
180 # following package sets are provided:
182 # - pkgsCross.<system> where system is a member of lib.systems.examples
185 otherPackageSets = self: super: {
186 # This maps each entry in lib.systems.examples to its own package
187 # set. Each of these will contain all packages cross compiled for
188 # that target system. For instance, pkgsCross.raspberryPi.hello,
189 # will refer to the "hello" package built for the ARM6-based
191 pkgsCross = lib.mapAttrs (n: crossSystem:
192 nixpkgsFun { inherit crossSystem; })
193 lib.systems.examples;
195 pkgsLLVM = nixpkgsFun {
201 # Bootstrap a cross stdenv using the LLVM toolchain.
202 # This is currently not possible when compiling natively,
203 # so we don't need to check hostPlatform != buildPlatform.
204 crossSystem = stdenv.targetPlatform // {
210 pkgsArocc = nixpkgsFun {
216 # Bootstrap a cross stdenv using the Aro C compiler.
217 # This is currently not possible when compiling natively,
218 # so we don't need to check hostPlatform != buildPlatform.
219 crossSystem = stdenv.hostPlatform // {
225 pkgsZig = nixpkgsFun {
231 # Bootstrap a cross stdenv using the Zig toolchain.
232 # This is currently not possible when compiling natively,
233 # so we don't need to check hostPlatform != buildPlatform.
234 crossSystem = stdenv.hostPlatform // {
240 # All packages built with the Musl libc. This will override the
241 # default GNU libc on Linux systems. Non-Linux systems are not
242 # supported. 32-bit is also not supported.
243 pkgsMusl = if stdenv.hostPlatform.isLinux && stdenv.buildPlatform.is64bit then nixpkgsFun {
244 overlays = [ (self': super': {
247 ${if stdenv.hostPlatform == stdenv.buildPlatform
248 then "localSystem" else "crossSystem"} = {
249 parsed = makeMuslParsedPlatform stdenv.hostPlatform.parsed;
251 } else throw "Musl libc only supports 64-bit Linux systems.";
253 # All packages built for i686 Linux.
254 # Used by wine, firefox with debugging version of Flash, ...
255 pkgsi686Linux = if stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86 then nixpkgsFun {
256 overlays = [ (self': super': {
257 pkgsi686Linux = super';
259 ${if stdenv.hostPlatform == stdenv.buildPlatform
260 then "localSystem" else "crossSystem"} = {
261 parsed = stdenv.hostPlatform.parsed // {
262 cpu = lib.systems.parse.cpuTypes.i686;
265 } else throw "i686 Linux package set can only be used with the x86 family.";
267 # x86_64-darwin packages for aarch64-darwin users to use with Rosetta for incompatible packages
268 pkgsx86_64Darwin = if stdenv.hostPlatform.isDarwin then nixpkgsFun {
269 overlays = [ (self': super': {
270 pkgsx86_64Darwin = super';
273 parsed = stdenv.hostPlatform.parsed // {
274 cpu = lib.systems.parse.cpuTypes.x86_64;
277 } else throw "x86_64 Darwin package set can only be used on Darwin systems.";
279 # If already linux: the same package set unaltered
280 # Otherwise, return a natively built linux package set for the current cpu architecture string.
281 # (ABI and other details will be set to the default for the cpu/os pair)
283 if stdenv.hostPlatform.isLinux
286 localSystem = lib.systems.elaborate "${stdenv.hostPlatform.parsed.cpu.name}-linux";
289 # Extend the package set with zero or more overlays. This preserves
290 # preexisting overlays. Prefer to initialize with the right overlays
291 # in one go when calling Nixpkgs, for performance and simplicity.
292 appendOverlays = extraOverlays:
293 if extraOverlays == []
295 else nixpkgsFun { overlays = args.overlays ++ extraOverlays; };
297 # NOTE: each call to extend causes a full nixpkgs rebuild, adding ~130MB
298 # of allocations. DO NOT USE THIS IN NIXPKGS.
300 # Extend the package set with a single overlay. This preserves
301 # preexisting overlays. Prefer to initialize with the right overlays
302 # in one go when calling Nixpkgs, for performance and simplicity.
303 # Prefer appendOverlays if used repeatedly.
304 extend = f: self.appendOverlays [f];
306 # Fully static packages.
307 # Currently uses Musl on Linux (couldn’t get static glibc to work).
308 pkgsStatic = nixpkgsFun ({
309 overlays = [ (self': super': {
315 if stdenv.hostPlatform.isLinux
316 then makeMuslParsedPlatform stdenv.hostPlatform.parsed
317 else stdenv.hostPlatform.parsed;
318 gcc = lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") { abi = "elfv2"; } //
319 stdenv.hostPlatform.gcc or {};
323 pkgsExtraHardening = nixpkgsFun {
326 pkgsExtraHardening = super';
327 stdenv = super'.withDefaultHardeningFlags (
328 super'.stdenv.cc.defaultHardeningFlags ++ [
331 "stackclashprotection"
335 glibc = super'.glibc.override rec {
336 enableCET = if self'.stdenv.hostPlatform.isx86_64 then "permissive" else false;
337 enableCETRuntimeDefault = enableCET != false;
339 } // lib.optionalAttrs (with super'.stdenv.hostPlatform; isx86_64 && isLinux) {
340 # causes shadowstack disablement
341 pcre = super'.pcre.override { enableJit = false; };
342 pcre-cpp = super'.pcre-cpp.override { enableJit = false; };
343 pcre16 = super'.pcre16.override { enableJit = false; };
349 # The complete chain of package set builders, applied from top to bottom.
350 # stdenvOverlays must be last as it brings package forward from the
351 # previous bootstrapping phases which have already been overlayed.
352 toFix = lib.foldl' (lib.flip lib.extends) (self: {}) ([
353 stdenvBootstappingAndPlatforms
366 # Return the complete set of packages.