| Tim Windelschmidt | 778649e | 2025-07-23 03:50:27 +0200 | [diff] [blame] | 1 | let |
| 2 | # We want our overrides to only apply when building for static environments. |
| 3 | conditionalOverlay = condition: overlay: (if condition then overlay else { }); |
| 4 | |
| 5 | pkgs = import ../../../third_party/nix/default.nix { |
| 6 | overlays = [ |
| 7 | # Overrides for allowing static builds |
| 8 | (self: super: conditionalOverlay super.stdenv.hostPlatform.isStatic (with self; { |
| 9 | # A minimal version of qemu allowing for static builds. |
| 10 | qemu-minimal = self.callPackage ./pkgs/qemu { inherit super; }; |
| 11 | |
| 12 | # Static perl builds are a rabbit hole as they need patches |
| 13 | # and use of undocumented options. Check the derivation for more infos. |
| 14 | perl = self.callPackage ./pkgs/perl { inherit super; }; |
| 15 | |
| 16 | # Bison requires an override for not hardcoding nix paths. |
| 17 | bison = self.callPackage ./pkgs/bison { inherit super; }; |
| 18 | |
| 19 | # Provide a custom minimal version of util-linux |
| 20 | util-linux-minimal = super.util-linux.override (old: { |
| 21 | pamSupport = false; |
| 22 | ncursesSupport = false; |
| 23 | capabilitiesSupport = false; |
| 24 | systemdSupport = false; |
| 25 | translateManpages = false; |
| 26 | nlsSupport = false; |
| 27 | shadowSupport = false; |
| 28 | writeSupport = false; |
| 29 | }); |
| 30 | |
| 31 | # Revert "fixup" which hardcodes a nix path. |
| 32 | python3Minimal = super.python3Minimal.overrideAttrs (old: { |
| 33 | postPatch = old.postPatch + '' |
| 34 | substituteInPlace Lib/subprocess.py \ |
| 35 | --replace-fail "'${bashNonInteractive}/bin/sh'" "'/bin/sh'" |
| 36 | ''; |
| 37 | }); |
| 38 | |
| 39 | # Disable tests as they fail when static build. |
| 40 | diffutils = super.diffutils.overrideAttrs (_: { |
| 41 | doCheck = false; |
| 42 | doInstallCheck = false; |
| 43 | }); |
| 44 | |
| 45 | # vde2 currently doesn't build without these additional flags. |
| 46 | vde2 = super.vde2.overrideAttrs (oldAttrs: { |
| 47 | env.NIX_CFLAGS_COMPILE = (oldAttrs.NIX_CFLAGS_COMPILE or "") + " -Wno-error=int-conversion -Wno-error=implicit-function-declaration"; |
| 48 | }); |
| 49 | })) |
| 50 | ]; |
| 51 | |
| 52 | config.replaceCrossStdenv = { buildPackages, baseStdenv }: |
| 53 | (buildPackages.withCFlags [ "-fPIC" ]) baseStdenv; |
| 54 | }; |
| 55 | |
| 56 | # All platforms we want to build for. |
| 57 | mkPlatforms = platforms: with platforms; [ |
| 58 | aarch64-multiplatform-musl |
| 59 | musl64 |
| 60 | ]; |
| 61 | |
| 62 | # All packages that we want in our bundle. |
| 63 | mkPackages = platformPkgs: with platformPkgs; [ |
| 64 | gnumake |
| 65 | flex |
| 66 | bison |
| 67 | lz4 |
| 68 | busybox |
| 69 | findutils |
| 70 | bc |
| 71 | util-linux-minimal # custom pkg |
| 72 | perl |
| 73 | nasm |
| 74 | acpica-tools |
| 75 | patch |
| 76 | diffutils |
| 77 | qemu-minimal # custom pkg |
| 78 | m4 |
| 79 | strace |
| 80 | python3Minimal |
| 81 | ]; |
| 82 | |
| 83 | mkPackagesEnv = platform: pkgs.buildEnv { |
| 84 | name = "toolchain-${platform.hostPlatform.config}"; |
| 85 | paths = mkPackages platform.pkgsStatic; |
| 86 | }; |
| 87 | |
| 88 | mkBundle = platform: pkgs.stdenv.mkDerivation rec { |
| 89 | name = "toolchain-bundle-${platform.hostPlatform.config}"; |
| 90 | buildInputs = [ pkgs.gnutar pkgs.zstd ]; |
| 91 | |
| 92 | phases = [ "buildPhase" ]; |
| 93 | buildPhase = |
| 94 | let |
| 95 | merged = mkPackagesEnv platform; |
| 96 | in |
| 97 | '' |
| 98 | mkdir $out |
| 99 | tar --zstd --sort=name --hard-dereference -hcf $out/${name}.tar.zst -C ${merged} . |
| 100 | ''; |
| 101 | }; |
| 102 | in |
| 103 | with pkgs; symlinkJoin { |
| Tim Windelschmidt | 98000a5 | 2025-03-06 14:22:15 +0100 | [diff] [blame] | 104 | name = "toolchain"; |
| 105 | paths = |
| 106 | let |
| Tim Windelschmidt | 778649e | 2025-07-23 03:50:27 +0200 | [diff] [blame] | 107 | platforms = mkPlatforms pkgs.pkgsCross; |
| Tim Windelschmidt | 98000a5 | 2025-03-06 14:22:15 +0100 | [diff] [blame] | 108 | in |
| Tim Windelschmidt | 778649e | 2025-07-23 03:50:27 +0200 | [diff] [blame] | 109 | map mkBundle platforms; |
| Tim Windelschmidt | 98000a5 | 2025-03-06 14:22:15 +0100 | [diff] [blame] | 110 | } |