Skip to content

Commit

Permalink
pkgs/top-level: refactor mkPkgs
Browse files Browse the repository at this point in the history
Sharing a first piece of common code between all package sets makes it
easier to maintain and less likely to introduce a new package set
without this.
  • Loading branch information
wolfgangwalther committed Dec 21, 2024
1 parent ead6d65 commit ec88803
Showing 1 changed file with 20 additions and 41 deletions.
61 changes: 20 additions & 41 deletions pkgs/top-level/stage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,15 @@ let

# Convenience attributes for instantitating package sets. Each of
# these will instantiate a new version of allPackages.
otherPackageSets = self: super: {
otherPackageSets = let
mkPkgs = name: nixpkgsArgs: nixpkgsFun (nixpkgsArgs // {
overlays = [
(self': super': {
"${name}" = super';
})
] ++ nixpkgsArgs.overlays or [] ++ overlays;
});
in self: super: {
# This maps each entry in lib.systems.examples to its own package
# set. Each of these will contain all packages cross compiled for
# that target system. For instance, pkgsCross.raspberryPi.hello,
Expand All @@ -187,12 +195,7 @@ let
nixpkgsFun { inherit crossSystem; })
lib.systems.examples;

pkgsLLVM = nixpkgsFun {
overlays = [
(self': super': {
pkgsLLVM = super';
})
] ++ overlays;
pkgsLLVM = mkPkgs "pkgsLLVM" {
# 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.
Expand All @@ -202,12 +205,7 @@ let
};
};

pkgsArocc = nixpkgsFun {
overlays = [
(self': super': {
pkgsArocc = super';
})
] ++ overlays;
pkgsArocc = mkPkgs "pkgsArocc" {
# 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.
Expand All @@ -217,12 +215,7 @@ let
};
};

pkgsZig = nixpkgsFun {
overlays = [
(self': super': {
pkgsZig = super';
})
] ++ overlays;
pkgsZig = mkPkgs "pkgsZig" {
# 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.
Expand All @@ -235,10 +228,7 @@ let
# All packages built with the Musl libc. This will override the
# default GNU libc on Linux systems. Non-Linux systems are not
# supported. 32-bit is also not supported.
pkgsMusl = if stdenv.hostPlatform.isLinux && stdenv.buildPlatform.is64bit then nixpkgsFun {
overlays = [ (self': super': {
pkgsMusl = super';
})] ++ overlays;
pkgsMusl = if stdenv.hostPlatform.isLinux && stdenv.buildPlatform.is64bit then mkPkgs "pkgsMusl" {
${if stdenv.hostPlatform == stdenv.buildPlatform
then "localSystem" else "crossSystem"} = {
config = lib.systems.parse.tripleFromSystem (makeMuslParsedPlatform stdenv.hostPlatform.parsed);
Expand All @@ -247,10 +237,7 @@ let

# All packages built for i686 Linux.
# Used by wine, firefox with debugging version of Flash, ...
pkgsi686Linux = if stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86 then nixpkgsFun {
overlays = [ (self': super': {
pkgsi686Linux = super';
})] ++ overlays;
pkgsi686Linux = if stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86 then mkPkgs "pkgsi686Linux" {
${if stdenv.hostPlatform == stdenv.buildPlatform
then "localSystem" else "crossSystem"} = {
config = lib.systems.parse.tripleFromSystem (stdenv.hostPlatform.parsed // {
Expand All @@ -260,10 +247,7 @@ let
} 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
pkgsx86_64Darwin = if stdenv.hostPlatform.isDarwin then nixpkgsFun {
overlays = [ (self': super': {
pkgsx86_64Darwin = super';
})] ++ overlays;
pkgsx86_64Darwin = if stdenv.hostPlatform.isDarwin then mkPkgs "pkgsx86_64Darwin" {
localSystem = {
config = lib.systems.parse.tripleFromSystem (stdenv.hostPlatform.parsed // {
cpu = lib.systems.parse.cpuTypes.x86_64;
Expand All @@ -273,20 +257,16 @@ let

# If already linux: the same package set unaltered
# Otherwise, return a natively built linux package set for the current cpu architecture string.
# (ABI and other details will be set to the default for the cpu/os pair)
pkgsLinux =
if stdenv.hostPlatform.isLinux
then self
else nixpkgsFun {
else mkPkgs "pkgsLinux" {
localSystem = lib.systems.elaborate "${stdenv.hostPlatform.parsed.cpu.name}-linux";
};

# Fully static packages.
# Currently uses Musl on Linux (couldn’t get static glibc to work).
pkgsStatic = nixpkgsFun ({
overlays = [ (self': super': {
pkgsStatic = super';
})] ++ overlays;
pkgsStatic = mkPkgs "pkgsStatic" {
crossSystem = {
isStatic = true;
config = lib.systems.parse.tripleFromSystem (
Expand All @@ -297,12 +277,11 @@ let
gcc = lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") { abi = "elfv2"; } //
stdenv.hostPlatform.gcc or {};
};
});
};

pkgsExtraHardening = nixpkgsFun {
pkgsExtraHardening = mkPkgs "pkgsExtraHardening" {
overlays = [
(self': super': {
pkgsExtraHardening = super';
stdenv = super'.withDefaultHardeningFlags (
super'.stdenv.cc.defaultHardeningFlags ++ [
"shadowstack"
Expand All @@ -321,7 +300,7 @@ let
pcre-cpp = super'.pcre-cpp.override { enableJit = false; };
pcre16 = super'.pcre16.override { enableJit = false; };
})
] ++ overlays;
];
};

# Extend the package set with zero or more overlays. This preserves
Expand Down

0 comments on commit ec88803

Please sign in to comment.