|
| 1 | +{ pkgs, lib, toolbox, toolboxLib }: |
| 2 | + |
| 3 | +let |
| 4 | + inherit (toolboxLib.readData ./data.json) meta versions; |
| 5 | + |
| 6 | + system = pkgs.stdenv.hostPlatform.system; |
| 7 | + |
| 8 | + supportedPlatforms = { |
| 9 | + "x86_64-linux" = "linux-x64-baseline"; |
| 10 | + "x86_64-darwin" = "darwin-x64-baseline"; |
| 11 | + }; |
| 12 | + |
| 13 | + platformKey = supportedPlatforms.${system} or null; |
| 14 | + |
| 15 | + # Only include versions that have binaries for the current platform |
| 16 | + filteredVersions = lib.filterAttrs (_: versionData: versionData ? ${system}) versions; |
| 17 | + |
| 18 | + builders = { |
| 19 | + default = version: versionData: |
| 20 | + let |
| 21 | + platformData = versionData.${system}; |
| 22 | + in |
| 23 | + pkgs.stdenv.mkDerivation { |
| 24 | + pname = "bun-baseline"; |
| 25 | + inherit version; |
| 26 | + |
| 27 | + src = pkgs.fetchurl { |
| 28 | + url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-${platformKey}.zip"; |
| 29 | + hash = platformData.sha256; |
| 30 | + }; |
| 31 | + |
| 32 | + sourceRoot = "bun-${platformKey}"; |
| 33 | + |
| 34 | + nativeBuildInputs = [ |
| 35 | + pkgs.unzip |
| 36 | + ] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ |
| 37 | + pkgs.autoPatchelfHook |
| 38 | + ]; |
| 39 | + |
| 40 | + buildInputs = lib.optionals pkgs.stdenv.hostPlatform.isLinux [ |
| 41 | + pkgs.stdenv.cc.cc.lib |
| 42 | + ]; |
| 43 | + |
| 44 | + dontConfigure = true; |
| 45 | + dontBuild = true; |
| 46 | + dontStrip = true; |
| 47 | + |
| 48 | + installPhase = '' |
| 49 | + runHook preInstall |
| 50 | +
|
| 51 | + mkdir -p $out/bin |
| 52 | + install -m 755 bun $out/bin/bun |
| 53 | + ln -s $out/bin/bun $out/bin/bunx |
| 54 | +
|
| 55 | + runHook postInstall |
| 56 | + ''; |
| 57 | + |
| 58 | + meta = { |
| 59 | + description = "Bun JavaScript runtime (baseline build, no AVX2 requirement)"; |
| 60 | + homepage = "https://bun.sh"; |
| 61 | + license = lib.licenses.mit; |
| 62 | + platforms = builtins.attrNames supportedPlatforms; |
| 63 | + }; |
| 64 | + }; |
| 65 | + }; |
| 66 | +in |
| 67 | +# On unsupported platforms, expose no versions so the flake skips this package gracefully |
| 68 | +if filteredVersions == {} then { |
| 69 | + versions = {}; |
| 70 | + default = meta.default; |
| 71 | +} else { |
| 72 | + versions = toolboxLib.buildVersions "bun-baseline" builders filteredVersions; |
| 73 | + default = meta.default; |
| 74 | +} |
0 commit comments