0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-14 06:00:33 +03:00

pkgs/top-level: make package sets composable (reapply) (#376988)

This commit is contained in:
Wolfgang Walther 2025-02-02 11:41:17 +01:00 committed by GitHub
commit c1793a336b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 262 additions and 182 deletions

View file

@ -73,7 +73,10 @@ let
defaultPkgs = defaultPkgs =
if opt.hostPlatform.isDefined then if opt.hostPlatform.isDefined then
let let
isCross = cfg.buildPlatform != cfg.hostPlatform; isCross =
!(lib.systems.equals (lib.systems.elaborate cfg.buildPlatform) (
lib.systems.elaborate cfg.hostPlatform
));
systemArgs = systemArgs =
if isCross then if isCross then
{ {
@ -195,13 +198,10 @@ in
}; };
hostPlatform = lib.mkOption { hostPlatform = lib.mkOption {
type = lib.types.either lib.types.str lib.types.attrs; # TODO utilize lib.systems.parsedPlatform type = lib.types.either lib.types.str lib.types.attrs;
example = { example = {
system = "aarch64-linux"; system = "aarch64-linux";
}; };
# Make sure that the final value has all fields for sake of other modules
# referring to this. TODO make `lib.systems` itself use the module system.
apply = lib.systems.elaborate;
defaultText = lib.literalExpression ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform''; defaultText = lib.literalExpression ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
description = '' description = ''
Specifies the platform where the NixOS configuration will run. Specifies the platform where the NixOS configuration will run.
@ -213,22 +213,13 @@ in
}; };
buildPlatform = lib.mkOption { buildPlatform = lib.mkOption {
type = lib.types.either lib.types.str lib.types.attrs; # TODO utilize lib.systems.parsedPlatform type = lib.types.either lib.types.str lib.types.attrs;
default = cfg.hostPlatform; default = cfg.hostPlatform;
example = { example = {
system = "x86_64-linux"; system = "x86_64-linux";
}; };
# Make sure that the final value has all fields for sake of other modules # Make sure that the final value has all fields for sake of other modules
# referring to this. # referring to this.
apply =
inputBuildPlatform:
let
elaborated = lib.systems.elaborate inputBuildPlatform;
in
if lib.systems.equals elaborated cfg.hostPlatform then
cfg.hostPlatform # make identical, so that `==` equality works; see https://github.com/NixOS/nixpkgs/issues/278001
else
elaborated;
defaultText = lib.literalExpression ''config.nixpkgs.hostPlatform''; defaultText = lib.literalExpression ''config.nixpkgs.hostPlatform'';
description = '' description = ''
Specifies the platform on which NixOS should be built. Specifies the platform on which NixOS should be built.
@ -245,14 +236,11 @@ in
}; };
localSystem = lib.mkOption { localSystem = lib.mkOption {
type = lib.types.attrs; # TODO utilize lib.systems.parsedPlatform type = lib.types.attrs;
default = { inherit (cfg) system; }; default = { inherit (cfg) system; };
example = { example = {
system = "aarch64-linux"; system = "aarch64-linux";
}; };
# Make sure that the final value has all fields for sake of other modules
# referring to this. TODO make `lib.systems` itself use the module system.
apply = lib.systems.elaborate;
defaultText = lib.literalExpression ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform''; defaultText = lib.literalExpression ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
description = '' description = ''
Systems with a recently generated `hardware-configuration.nix` Systems with a recently generated `hardware-configuration.nix`
@ -280,7 +268,7 @@ in
# is a relation between at least 2 systems in the context of a # is a relation between at least 2 systems in the context of a
# specific build step, not a single system. # specific build step, not a single system.
crossSystem = lib.mkOption { crossSystem = lib.mkOption {
type = lib.types.nullOr lib.types.attrs; # TODO utilize lib.systems.parsedPlatform type = lib.types.nullOr lib.types.attrs;
default = null; default = null;
example = { example = {
system = "aarch64-linux"; system = "aarch64-linux";
@ -416,6 +404,18 @@ in
${lib.concatMapStringsSep "\n" (file: " - ${file}") opt.config.files} ${lib.concatMapStringsSep "\n" (file: " - ${file}") opt.config.files}
''; '';
} }
{
assertion =
(opt.hostPlatform.isDefined -> builtins.isAttrs cfg.buildPlatform -> !(cfg.buildPlatform ? parsed))
&& (opt.hostPlatform.isDefined -> builtins.isAttrs cfg.hostPlatform -> !(cfg.hostPlatform ? parsed))
&& (builtins.isAttrs cfg.localSystem -> !(cfg.localSystem ? parsed))
&& (builtins.isAttrs cfg.crossSystem -> !(cfg.crossSystem ? parsed));
message = ''
Passing fully elaborated systems to `nixpkgs.localSystem`, `nixpkgs.crossSystem`, `nixpkgs.buildPlatform`
or `nixpkgs.hostPlatform` will break composability of package sets in nixpkgs. For example, pkgs.pkgsStatic
would not work in modules anymore.
'';
}
]; ];
}; };

View file

@ -40,20 +40,11 @@ in
The Nixpkgs overlays that `pkgs` was initialized with. The Nixpkgs overlays that `pkgs` was initialized with.
''; '';
}; };
hostPlatform = mkOption { # buildPlatform and hostPlatform left out on purpose:
internal = true; # - They are not supposed to be changed with this read-only module.
readOnly = true; # - They are not supposed to be read either, according to the description
description = '' # of "system" in the traditional nixpkgs module.
The platform of the machine that is running the NixOS configuration. #
'';
};
buildPlatform = mkOption {
internal = true;
readOnly = true;
description = ''
The platform of the machine that built the NixOS configuration.
'';
};
# NOTE: do not add the legacy options such as localSystem here. Let's keep # NOTE: do not add the legacy options such as localSystem here. Let's keep
# this module simple and let module authors upgrade their code instead. # this module simple and let module authors upgrade their code instead.
}; };
@ -61,12 +52,8 @@ in
config = { config = {
_module.args.pkgs = _module.args.pkgs =
# find mistaken definitions # find mistaken definitions
builtins.seq cfg.config builtins.seq cfg.overlays builtins.seq cfg.hostPlatform builtins.seq builtins.seq cfg.config builtins.seq cfg.overlays cfg.pkgs;
cfg.buildPlatform
cfg.pkgs;
nixpkgs.config = cfg.pkgs.config; nixpkgs.config = cfg.pkgs.config;
nixpkgs.overlays = cfg.pkgs.overlays; nixpkgs.overlays = cfg.pkgs.overlays;
nixpkgs.hostPlatform = cfg.pkgs.stdenv.hostPlatform;
nixpkgs.buildPlatform = cfg.pkgs.stdenv.buildPlatform;
}; };
} }

View file

@ -506,8 +506,12 @@ in
config = { config = {
nixpkgs = nixpkgs =
if options.nixpkgs?hostPlatform if options.nixpkgs?hostPlatform
then { inherit (host.pkgs.stdenv) hostPlatform; } then {
else { localSystem = host.pkgs.stdenv.hostPlatform; } hostPlatform =
if host.options.nixpkgs.hostPlatform.isDefined
then host.config.nixpkgs.hostPlatform
else lib.defaultTo host.config.nixpkgs.localSystem host.config.nixpkgs.crossSystem;
} else { localSystem = lib.defaultTo host.config.nixpkgs.localSystem host.config.nixpkgs.crossSystem; }
; ;
boot.isContainer = true; boot.isContainer = true;
networking.hostName = mkDefault name; networking.hostName = mkDefault name;

View file

@ -40,7 +40,7 @@
verityStore = { verityStore = {
enable = true; enable = true;
# by default the module works with systemd-boot, for simplicity this test directly boots the UKI # by default the module works with systemd-boot, for simplicity this test directly boots the UKI
ukiPath = "/EFI/BOOT/BOOT${lib.toUpper config.nixpkgs.hostPlatform.efiArch}.EFI"; ukiPath = "/EFI/BOOT/BOOT${lib.toUpper pkgs.stdenv.hostPlatform.efiArch}.EFI";
}; };
name = "appliance-verity-store-image"; name = "appliance-verity-store-image";
@ -51,7 +51,7 @@
repartConfig = { repartConfig = {
Type = "esp"; Type = "esp";
Format = "vfat"; Format = "vfat";
SizeMinBytes = if config.nixpkgs.hostPlatform.isx86_64 then "64M" else "96M"; SizeMinBytes = if pkgs.stdenv.hostPlatform.isx86_64 then "64M" else "96M";
}; };
}; };
${partitionIds.store-verity}.repartConfig = { ${partitionIds.store-verity}.repartConfig = {

View file

@ -53,7 +53,7 @@ in
"esp" = { "esp" = {
contents = contents =
let let
efiArch = config.nixpkgs.hostPlatform.efiArch; efiArch = pkgs.stdenv.hostPlatform.efiArch;
in in
{ {
"/EFI/BOOT/BOOT${lib.toUpper efiArch}.EFI".source = "/EFI/BOOT/BOOT${lib.toUpper efiArch}.EFI".source =
@ -70,7 +70,7 @@ in
# aarch64 kernel seems to generally be a little bigger than the # aarch64 kernel seems to generally be a little bigger than the
# x86_64 kernel. To stay on the safe side, leave some more slack # x86_64 kernel. To stay on the safe side, leave some more slack
# for every platform other than x86_64. # for every platform other than x86_64.
SizeMinBytes = if config.nixpkgs.hostPlatform.isx86_64 then "64M" else "96M"; SizeMinBytes = if pkgs.stdenv.hostPlatform.isx86_64 then "64M" else "96M";
}; };
}; };
"swap" = { "swap" = {

View file

@ -0,0 +1,128 @@
# run like this:
# nix-build pkgs/test/top-level/stage.nix
{
localSystem ? {
system = builtins.currentSystem;
},
}:
with import ../../top-level { inherit localSystem; };
let
# To silence platform specific evaluation errors
discardEvaluationErrors = e: (builtins.tryEval e).success -> e;
# Basic test for idempotency of the package set, i.e:
# Applying the same package set twice should work and
# not change anything.
isIdempotent = set: discardEvaluationErrors (pkgs.${set}.stdenv == pkgs.${set}.${set}.stdenv);
# Some package sets should be noops in certain circumstances.
# This is very similar to the idempotency test, but not going
# via the super' overlay.
isNoop =
parent: child:
discardEvaluationErrors (
(lib.getAttrFromPath parent pkgs).stdenv == (lib.getAttrFromPath parent pkgs).${child}.stdenv
);
allMuslExamples = builtins.attrNames (
lib.filterAttrs (_: system: lib.hasSuffix "-musl" system.config) lib.systems.examples
);
allLLVMExamples = builtins.attrNames (
lib.filterAttrs (_: system: system.useLLVM or false) lib.systems.examples
);
# A package set should only change specific configuration, but needs
# to keep all other configuration from previous layers in place.
# Each package set has one or more key characteristics for which we
# test here. Those should be kept, even when applying the "set" package
# set.
isComposable =
set:
(
# Can't compose two different libcs...
builtins.elem set [ "pkgsLLVMLibc" ]
|| discardEvaluationErrors (
pkgsCross.mingwW64.${set}.stdenv.hostPlatform.config == "x86_64-w64-mingw32"
)
)
&& (
# Can't compose two different libcs...
builtins.elem set [ "pkgsLLVMLibc" ]
|| discardEvaluationErrors (pkgsCross.mingwW64.${set}.stdenv.hostPlatform.libc == "msvcrt")
)
&& discardEvaluationErrors (pkgsCross.ppc64-musl.${set}.stdenv.hostPlatform.gcc.abi == "elfv2")
&& discardEvaluationErrors (
builtins.elem "trivialautovarinit" pkgs.pkgsExtraHardening.${set}.stdenv.cc.defaultHardeningFlags
)
&& discardEvaluationErrors (pkgs.pkgsLLVM.${set}.stdenv.hostPlatform.useLLVM)
&& (
# Can't compose two different libcs...
builtins.elem set [
"pkgsMusl"
"pkgsStatic"
]
|| discardEvaluationErrors (pkgs.pkgsLLVMLibc.${set}.stdenv.hostPlatform.isLLVMLibc)
)
&& discardEvaluationErrors (pkgs.pkgsArocc.${set}.stdenv.hostPlatform.useArocc)
&& discardEvaluationErrors (pkgs.pkgsZig.${set}.stdenv.hostPlatform.useZig)
&& discardEvaluationErrors (pkgs.pkgsLinux.${set}.stdenv.buildPlatform.isLinux)
&& (
# Can't compose two different libcs...
builtins.elem set [ "pkgsLLVMLibc" ]
|| discardEvaluationErrors (pkgs.pkgsMusl.${set}.stdenv.hostPlatform.isMusl)
)
&& discardEvaluationErrors (pkgs.pkgsStatic.${set}.stdenv.hostPlatform.isStatic)
&& discardEvaluationErrors (pkgs.pkgsi686Linux.${set}.stdenv.hostPlatform.isx86_32)
&& discardEvaluationErrors (pkgs.pkgsx86_64Darwin.${set}.stdenv.hostPlatform.isx86_64);
in
# Appends same defaultHardeningFlags again on each .pkgsExtraHardening - thus not idempotent.
# assert isIdempotent "pkgsExtraHardening";
# TODO: Remove the isDarwin condition, which currently results in infinite recursion.
# Also see https://github.com/NixOS/nixpkgs/pull/330567#discussion_r1894653309
assert (stdenv.hostPlatform.isDarwin || isIdempotent "pkgsLLVM");
# TODO: This currently results in infinite recursion, even on Linux
# assert isIdempotent "pkgsLLVMLibc";
assert isIdempotent "pkgsArocc";
assert isIdempotent "pkgsZig";
assert isIdempotent "pkgsLinux";
assert isIdempotent "pkgsMusl";
assert isIdempotent "pkgsStatic";
assert isIdempotent "pkgsi686Linux";
assert isIdempotent "pkgsx86_64Darwin";
assert isNoop [ "pkgsStatic" ] "pkgsMusl";
assert lib.all (sys: isNoop [ "pkgsCross" sys ] "pkgsMusl") allMuslExamples;
assert lib.all (sys: isNoop [ "pkgsCross" sys ] "pkgsLLVM") allLLVMExamples;
assert isComposable "pkgsExtraHardening";
assert isComposable "pkgsLLVM";
# TODO: Results in infinite recursion
# assert isComposable "pkgsLLVMLibc";
assert isComposable "pkgsArocc";
# TODO: unexpected argument 'bintools' - uncomment once https://github.com/NixOS/nixpkgs/pull/331011 is done
# assert isComposable "pkgsZig";
assert isComposable "pkgsMusl";
assert isComposable "pkgsStatic";
assert isComposable "pkgsi686Linux";
# Special cases regarding buildPlatform vs hostPlatform
assert discardEvaluationErrors (pkgsCross.gnu64.pkgsMusl.stdenv.hostPlatform.isMusl);
assert discardEvaluationErrors (pkgsCross.gnu64.pkgsi686Linux.stdenv.hostPlatform.isx86_32);
assert discardEvaluationErrors (pkgsCross.mingwW64.pkgsLinux.stdenv.hostPlatform.isLinux);
assert discardEvaluationErrors (
pkgsCross.aarch64-darwin.pkgsx86_64Darwin.stdenv.hostPlatform.isx86_64
);
# pkgsCross should keep upper cross settings
assert discardEvaluationErrors (
with pkgsStatic.pkgsCross.gnu64.stdenv.hostPlatform; isGnu && isStatic
);
assert discardEvaluationErrors (
with pkgsLLVM.pkgsCross.musl64.stdenv.hostPlatform; isMusl && useLLVM
);
emptyFile

View file

@ -1669,9 +1669,9 @@ with pkgs;
# pkgsCross.aarch64-multiplatform.freshBootstrapTools.build # pkgsCross.aarch64-multiplatform.freshBootstrapTools.build
freshBootstrapTools = if stdenv.hostPlatform.isDarwin then freshBootstrapTools = if stdenv.hostPlatform.isDarwin then
callPackage ../stdenv/darwin/make-bootstrap-tools.nix { callPackage ../stdenv/darwin/make-bootstrap-tools.nix {
localSystem = stdenv.buildPlatform; localSystem = { config = lib.systems.parse.tripleFromSystem stdenv.buildPlatform; };
crossSystem = crossSystem =
if stdenv.buildPlatform == stdenv.hostPlatform then null else stdenv.hostPlatform; if stdenv.buildPlatform == stdenv.hostPlatform then null else { config = lib.systems.parse.tripleFromSystem stdenv.hostPlatform; };
} }
else if stdenv.hostPlatform.isLinux then else if stdenv.hostPlatform.isLinux then
callPackage ../stdenv/linux/make-bootstrap-tools.nix {} callPackage ../stdenv/linux/make-bootstrap-tools.nix {}
@ -17728,7 +17728,7 @@ with pkgs;
[( [(
{ lib, ... }: { { lib, ... }: {
config.nixpkgs.pkgs = lib.mkDefault pkgs; config.nixpkgs.pkgs = lib.mkDefault pkgs;
config.nixpkgs.localSystem = lib.mkDefault stdenv.hostPlatform; config.nixpkgs.localSystem = lib.mkDefault ({ config = lib.systems.parse.tripleFromSystem stdenv.hostPlatform; });
} }
)] ++ ( )] ++ (
if builtins.isList configuration if builtins.isList configuration

View file

@ -46,6 +46,11 @@
... ...
} @ args: } @ args:
# Passing fully elaborated systems to localSystem or crossSystem will break composability
# of package sets.
assert builtins.isAttrs localSystem -> !(localSystem ? parsed);
assert builtins.isAttrs crossSystem -> !(crossSystem ? parsed);
let # Rename the function arguments let # Rename the function arguments
config0 = config; config0 = config;
crossSystem0 = crossSystem; crossSystem0 = crossSystem;
@ -122,22 +127,18 @@ in let
config = lib.showWarnings configEval.config.warnings configEval.config; config = lib.showWarnings configEval.config.warnings configEval.config;
# A few packages make a new package set to draw their dependencies from. # A few packages make a new package set to draw their dependencies from.
# (Currently to get a cross tool chain, or forced-i686 package.) Rather than # Rather than give `all-packages.nix` all the arguments to this function,
# give `all-packages.nix` all the arguments to this function, even ones that # even ones that don't concern it, we give it this function to "re-call"
# don't concern it, we give it this function to "re-call" nixpkgs, inheriting # nixpkgs, inheriting whatever arguments it doesn't explicitly provide. This
# whatever arguments it doesn't explicitly provide. This way, # way, `all-packages.nix` doesn't know more than it needs to.
# `all-packages.nix` doesn't know more than it needs too.
# #
# It's OK that `args` doesn't include default arguments from this file: # It's OK that `args` doesn't include default arguments from this file:
# they'll be deterministically inferred. In fact we must *not* include them, # they'll be deterministically inferred. In fact we must *not* include them,
# because it's important that if some parameter which affects the default is # because it's important that if some parameter which affects the default is
# substituted with a different argument, the default is re-inferred. # substituted with a different argument, the default is re-inferred.
# #
# To put this in concrete terms, this function is basically just used today to # To put this in concrete terms, we want the provided non-native `localSystem`
# use package for a different platform for the current platform (namely cross # and `crossSystem` arguments to affect the stdenv chosen.
# compiling toolchains and 32-bit packages on x86_64). In both those cases we
# want the provided non-native `localSystem` argument to affect the stdenv
# chosen.
# #
# NB!!! This thing gets its `config` argument from `args`, i.e. it's actually # NB!!! This thing gets its `config` argument from `args`, i.e. it's actually
# `config0`. It is important to keep it to `config0` format (as opposed to the # `config0`. It is important to keep it to `config0` format (as opposed to the
@ -146,7 +147,7 @@ in let
# via `evalModules` is not idempotent. In other words, if you add `config` to # via `evalModules` is not idempotent. In other words, if you add `config` to
# `newArgs`, expect strange very hard to debug errors! (Yes, I'm speaking from # `newArgs`, expect strange very hard to debug errors! (Yes, I'm speaking from
# experience here.) # experience here.)
nixpkgsFun = newArgs: import ./. (args // newArgs); nixpkgsFun = f0: import ./. (args // f0 args);
# Partially apply some arguments for building bootstraping stage pkgs # Partially apply some arguments for building bootstraping stage pkgs
# sets. Only apply arguments which no stdenv would want to override. # sets. Only apply arguments which no stdenv would want to override.

View file

@ -180,168 +180,111 @@ let
((config.packageOverrides or (super: {})) super); ((config.packageOverrides or (super: {})) super);
# Convenience attributes for instantitating package sets. Each of # Convenience attributes for instantitating package sets. Each of
# these will instantiate a new version of allPackages. Currently the # these will instantiate a new version of allPackages.
# following package sets are provided: otherPackageSets = let
# mkPkgs = name: fn: nixpkgsFun (prevArgs: let nixpkgsArgs = fn prevArgs; in nixpkgsArgs // {
# - pkgsCross.<system> where system is a member of lib.systems.examples overlays = [
# - pkgsMusl (self': super': {
# - pkgsi686Linux "${name}" = super';
otherPackageSets = self: super: { })
] ++ nixpkgsArgs.overlays or [] ++ prevArgs.overlays or [];
});
# This is always cross.
mkCrossPkgs = name: crossAttrs: mkPkgs name (prevArgs: {
crossSystem =
(lib.systems.systemToAttrs (lib.defaultTo prevArgs.localSystem prevArgs.crossSystem or null)) // crossAttrs;
});
# This is only cross when we are already cross, otherwise local.
# For the case of "native cross", i.e. pkgsCross.gnu64 on a x86_64-linux system, we need to adjust **both**
# localSystem **and** crossSystem, otherwise they're out of sync.
mkHybridPkgs = name: hybridAttrs: mkPkgs name (prevArgs: let
newSystem = (lib.systems.systemToAttrs (lib.defaultTo prevArgs.localSystem prevArgs.crossSystem or null)) // hybridAttrs;
in { crossSystem = newSystem; }
// lib.optionalAttrs (stdenv.hostPlatform == stdenv.buildPlatform) { localSystem = newSystem; }
);
in self: super: {
# This maps each entry in lib.systems.examples to its own package # This maps each entry in lib.systems.examples to its own package
# set. Each of these will contain all packages cross compiled for # set. Each of these will contain all packages cross compiled for
# that target system. For instance, pkgsCross.raspberryPi.hello, # that target system. For instance, pkgsCross.raspberryPi.hello,
# will refer to the "hello" package built for the ARM6-based # will refer to the "hello" package built for the ARM6-based
# Raspberry Pi. # Raspberry Pi.
pkgsCross = lib.mapAttrs (n: crossSystem: pkgsCross = lib.mapAttrs (n: crossSystem:
nixpkgsFun { inherit crossSystem; }) nixpkgsFun (prevArgs: { crossSystem = (lib.systems.systemToAttrs (lib.defaultTo { } prevArgs.crossSystem or null)) // crossSystem; }))
lib.systems.examples; lib.systems.examples;
pkgsLLVM = nixpkgsFun { # Bootstrap a cross stdenv using the LLVM toolchain.
overlays = [ # This is currently not possible when compiling natively.
(self': super': { pkgsLLVM = mkCrossPkgs "pkgsLLVM" {
pkgsLLVM = super'; useLLVM = true;
}) linker = "lld";
] ++ overlays;
# Bootstrap a cross stdenv using the LLVM toolchain.
# This is currently not possible when compiling natively,
# so we don't need to check hostPlatform != buildPlatform.
crossSystem = stdenv.hostPlatform // {
useLLVM = true;
linker = "lld";
};
}; };
pkgsLLVMLibc = nixpkgsFun { # Bootstrap a cross stdenv using LLVM libc.
overlays = [ (self': super': { # This is currently not possible when compiling natively.
pkgsLLVMLibc = super'; pkgsLLVMLibc = mkCrossPkgs "pkgsLLVMLibc" {
})] ++ overlays; config = lib.systems.parse.tripleFromSystem (makeLLVMParsedPlatform stdenv.hostPlatform.parsed);
# Bootstrap a cross stdenv using LLVM libc. libc = "llvm";
# This is currently not possible when compiling natively,
# so we don't need to check hostPlatform != buildPlatform.
crossSystem = stdenv.hostPlatform // {
config = lib.systems.parse.tripleFromSystem (makeLLVMParsedPlatform stdenv.hostPlatform.parsed);
libc = "llvm";
};
}; };
pkgsArocc = nixpkgsFun { # Bootstrap a cross stdenv using the Aro C compiler.
overlays = [ # This is currently not possible when compiling natively.
(self': super': { pkgsArocc = mkCrossPkgs "pkgsArocc" {
pkgsArocc = super'; useArocc = true;
}) linker = "lld";
] ++ overlays;
# Bootstrap a cross stdenv using the Aro C compiler.
# This is currently not possible when compiling natively,
# so we don't need to check hostPlatform != buildPlatform.
crossSystem = stdenv.hostPlatform // {
useArocc = true;
linker = "lld";
};
}; };
pkgsZig = nixpkgsFun { # Bootstrap a cross stdenv using the Zig toolchain.
overlays = [ # This is currently not possible when compiling natively.
(self': super': { pkgsZig = mkCrossPkgs "pkgsZig" {
pkgsZig = super'; useZig = true;
}) linker = "lld";
] ++ overlays;
# Bootstrap a cross stdenv using the Zig toolchain.
# This is currently not possible when compiling natively,
# so we don't need to check hostPlatform != buildPlatform.
crossSystem = stdenv.hostPlatform // {
useZig = true;
linker = "lld";
};
}; };
# All packages built with the Musl libc. This will override the # All packages built with the Musl libc. This will override the
# default GNU libc on Linux systems. Non-Linux systems are not # default GNU libc on Linux systems. Non-Linux systems are not
# supported. 32-bit is also not supported. # supported. 32-bit is also not supported.
pkgsMusl = if stdenv.hostPlatform.isLinux && stdenv.buildPlatform.is64bit then nixpkgsFun { pkgsMusl = if stdenv.hostPlatform.isLinux && stdenv.buildPlatform.is64bit then mkHybridPkgs "pkgsMusl" {
overlays = [ (self': super': { config = lib.systems.parse.tripleFromSystem (makeMuslParsedPlatform stdenv.hostPlatform.parsed);
pkgsMusl = super';
})] ++ overlays;
${if stdenv.hostPlatform == stdenv.buildPlatform
then "localSystem" else "crossSystem"} = {
config = lib.systems.parse.tripleFromSystem (makeMuslParsedPlatform stdenv.hostPlatform.parsed);
};
} else throw "Musl libc only supports 64-bit Linux systems."; } else throw "Musl libc only supports 64-bit Linux systems.";
# All packages built for i686 Linux. # All packages built for i686 Linux.
# Used by wine, firefox with debugging version of Flash, ... # Used by wine, firefox with debugging version of Flash, ...
pkgsi686Linux = if stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86 then nixpkgsFun { pkgsi686Linux = if stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86 then mkHybridPkgs "pkgsi686Linux" {
overlays = [ (self': super': { config = lib.systems.parse.tripleFromSystem (stdenv.hostPlatform.parsed // {
pkgsi686Linux = super'; cpu = lib.systems.parse.cpuTypes.i686;
})] ++ overlays; });
${if stdenv.hostPlatform == stdenv.buildPlatform
then "localSystem" else "crossSystem"} = {
config = lib.systems.parse.tripleFromSystem (stdenv.hostPlatform.parsed // {
cpu = lib.systems.parse.cpuTypes.i686;
});
};
} else throw "i686 Linux package set can only be used with the x86 family."; } else throw "i686 Linux package set can only be used with the x86 family.";
# x86_64-darwin packages for aarch64-darwin users to use with Rosetta for incompatible packages # x86_64-darwin packages for aarch64-darwin users to use with Rosetta for incompatible packages
pkgsx86_64Darwin = if stdenv.hostPlatform.isDarwin then nixpkgsFun { pkgsx86_64Darwin = if stdenv.hostPlatform.isDarwin then mkHybridPkgs "pkgsx86_64Darwin" {
overlays = [ (self': super': { config = lib.systems.parse.tripleFromSystem (stdenv.hostPlatform.parsed // {
pkgsx86_64Darwin = super'; cpu = lib.systems.parse.cpuTypes.x86_64;
})] ++ overlays; });
localSystem = {
config = lib.systems.parse.tripleFromSystem (stdenv.hostPlatform.parsed // {
cpu = lib.systems.parse.cpuTypes.x86_64;
});
};
} else throw "x86_64 Darwin package set can only be used on Darwin systems."; } else throw "x86_64 Darwin package set can only be used on Darwin systems.";
# If already linux: the same package set unaltered # If already linux: the same package set unaltered
# Otherwise, return a natively built linux package set for the current cpu architecture string. # Otherwise, return a linux package set for the current cpu architecture string.
# (ABI and other details will be set to the default for the cpu/os pair) # (ABI and other details will be set to the default for the cpu/os pair)
pkgsLinux = pkgsLinux =
if stdenv.hostPlatform.isLinux if stdenv.hostPlatform.isLinux
then self then self
else nixpkgsFun { else mkHybridPkgs "pkgsLinux" {
localSystem = lib.systems.elaborate "${stdenv.hostPlatform.parsed.cpu.name}-linux"; config = lib.systems.parse.tripleFromSystem (lib.systems.elaborate "${stdenv.hostPlatform.parsed.cpu.name}-linux").parsed;
}; };
# Extend the package set with zero or more overlays. This preserves
# preexisting overlays. Prefer to initialize with the right overlays
# in one go when calling Nixpkgs, for performance and simplicity.
appendOverlays = extraOverlays:
if extraOverlays == []
then self
else nixpkgsFun { overlays = args.overlays ++ extraOverlays; };
# NOTE: each call to extend causes a full nixpkgs rebuild, adding ~130MB
# of allocations. DO NOT USE THIS IN NIXPKGS.
#
# Extend the package set with a single overlay. This preserves
# preexisting overlays. Prefer to initialize with the right overlays
# in one go when calling Nixpkgs, for performance and simplicity.
# Prefer appendOverlays if used repeatedly.
extend = f: self.appendOverlays [f];
# Fully static packages. # Fully static packages.
# Currently uses Musl on Linux (couldnt get static glibc to work). # Currently uses Musl on Linux (couldnt get static glibc to work).
pkgsStatic = nixpkgsFun ({ pkgsStatic = mkCrossPkgs "pkgsStatic" ({
overlays = [ (self': super': { isStatic = true;
pkgsStatic = super'; } // lib.optionalAttrs stdenv.hostPlatform.isLinux {
})] ++ overlays; config = lib.systems.parse.tripleFromSystem (makeMuslParsedPlatform stdenv.hostPlatform.parsed);
crossSystem = { } // lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") {
isStatic = true; gcc = { abi = "elfv2"; } // stdenv.hostPlatform.gcc or {};
config = lib.systems.parse.tripleFromSystem (
if stdenv.hostPlatform.isLinux
then makeMuslParsedPlatform stdenv.hostPlatform.parsed
else stdenv.hostPlatform.parsed
);
gcc = lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") { abi = "elfv2"; } //
stdenv.hostPlatform.gcc or {};
};
}); });
pkgsExtraHardening = nixpkgsFun { pkgsExtraHardening = mkPkgs "pkgsExtraHardening" (_: {
overlays = [ overlays = [
(self': super': { (self': super': {
pkgsExtraHardening = super';
stdenv = super'.withDefaultHardeningFlags ( stdenv = super'.withDefaultHardeningFlags (
super'.stdenv.cc.defaultHardeningFlags ++ [ super'.stdenv.cc.defaultHardeningFlags ++ [
"shadowstack" "shadowstack"
@ -360,8 +303,25 @@ let
pcre-cpp = super'.pcre-cpp.override { enableJit = false; }; pcre-cpp = super'.pcre-cpp.override { enableJit = false; };
pcre16 = super'.pcre16.override { enableJit = false; }; pcre16 = super'.pcre16.override { enableJit = false; };
}) })
] ++ overlays; ];
}; });
# Extend the package set with zero or more overlays. This preserves
# preexisting overlays. Prefer to initialize with the right overlays
# in one go when calling Nixpkgs, for performance and simplicity.
appendOverlays = extraOverlays:
if extraOverlays == []
then self
else nixpkgsFun (prevArgs: { overlays = prevArgs.overlays ++ extraOverlays; });
# NOTE: each call to extend causes a full nixpkgs rebuild, adding ~130MB
# of allocations. DO NOT USE THIS IN NIXPKGS.
#
# Extend the package set with a single overlay. This preserves
# preexisting overlays. Prefer to initialize with the right overlays
# in one go when calling Nixpkgs, for performance and simplicity.
# Prefer appendOverlays if used repeatedly.
extend = f: self.appendOverlays [f];
}; };
# The complete chain of package set builders, applied from top to bottom. # The complete chain of package set builders, applied from top to bottom.