fix(bun): fix bun and bun-dependent packages on old CPUs

This commit is contained in:
2026-07-09 07:59:27 +02:00
parent 76fa31e3d2
commit 1504173111
5 changed files with 98 additions and 12 deletions
+3 -2
View File
@@ -96,7 +96,8 @@
flake-utils.lib.eachDefaultSystem ( flake-utils.lib.eachDefaultSystem (
system: let system: let
inherit (self) outputs; inherit (self) outputs;
pkgs = nixpkgs.legacyPackages.${system};
pkgs = import nixpkgs {inherit system;};
in { in {
formatter = pkgs.alejandra; formatter = pkgs.alejandra;
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
@@ -111,7 +112,7 @@
packages = { packages = {
homeConfigurations = let homeConfigurations = let
extraSpecialArgs = {inherit inputs outputs system;}; extraSpecialArgs = {inherit inputs outputs system;};
pkgs = nixpkgs.legacyPackages.x86_64-linux; pkgs = import nixpkgs {inherit system;};
defaultUserModules = [ defaultUserModules = [
inputs.sops-nix.homeManagerModules.sops inputs.sops-nix.homeManagerModules.sops
inputs.spicetify.homeManagerModules.default inputs.spicetify.homeManagerModules.default
+70
View File
@@ -0,0 +1,70 @@
# Baseline variant of Bun for x86_64-linux CPUs without AVX2 support.
# The regular `bun` from nixpkgs requires AVX2 and crashes with SIGILL on older hardware.
#
# Version is typically kept in sync with nixpkgs's `bun` (passed via `callPackage`).
{
lib,
stdenvNoCC,
fetchurl,
autoPatchelfHook,
unzip,
makeBinaryWrapper,
glibc,
stdenv,
version ? "1.3.13",
}: let
# When updating `version`, compute the new hash with:
# nix store prefetch-file "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-linux-x64-baseline.zip"
hash = {
"1.3.13" = "sha256-nYokKSpwaAkCBdqsCloiP19pc29Sh+N7+I07QDHtx1A=";
};
in
stdenvNoCC.mkDerivation {
pname = "bun-baseline";
inherit version;
src = fetchurl {
url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-linux-x64-baseline.zip";
hash = hash.${version};
};
nativeBuildInputs =
[unzip]
++ lib.optionals stdenvNoCC.hostPlatform.isLinux [
autoPatchelfHook
makeBinaryWrapper
];
buildInputs = lib.optionals stdenvNoCC.hostPlatform.isLinux [
glibc
(lib.getLib stdenv.cc.cc)
];
dontConfigure = true;
dontBuild = true;
unpackPhase = ''
runHook preUnpack
mkdir -p source
cd source
${lib.getExe unzip} -q $src
runHook postUnpack
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
find . -type f -name "bun" -not -path "./__MACOSX/*" -exec cp {} $out/bin/bun \;
chmod +x $out/bin/bun
ln -s $out/bin/bun $out/bin/bunx
runHook postInstall
'';
meta = {
description = "Bun JavaScript runtime (baseline variant, works without AVX2)";
homepage = "https://bun.sh";
license = lib.licenses.mit;
platforms = ["x86_64-linux"];
mainProgram = "bun";
};
}
+21 -6
View File
@@ -1,15 +1,30 @@
{ {
config, config,
lib, lib,
inputs,
pkgs, pkgs,
... ...
}: }:
with lib; let with lib; let
inherit (pkgs.stdenv.hostPlatform) system;
cfg = config.home.dev.ai.opencode; cfg = config.home.dev.ai.opencode;
defaultPackageCli = inputs.opencode.packages.${system}.opencode;
defaultPackageDesktop = inputs.opencode.packages.${system}.desktop; # On x86_64-linux CPUs without AVX2, use the baseline bun variant
# when building opencode - the regular `bun` from nixpkgs requires
# AVX2 and crashes on older hardware, such as my Thinkpad x220s
# Intel Core i5 2640M.
needsBaselineBun =
pkgs.stdenv.hostPlatform.isx86_64 && !pkgs.stdenv.hostPlatform.avx2Support;
bunBaseline = pkgs.callPackage ../../../../packages/bun-baseline.nix {};
defaultPackageCli =
if needsBaselineBun
then pkgs.opencode.override {bun = bunBaseline;}
else pkgs.opencode;
defaultPackageDesktop =
if needsBaselineBun
then pkgs.opencode-desktop.override {bun = bunBaseline;}
else pkgs.opencode-desktop;
corsList = domains: lists.remove "" (lists.forEach (strings.splitString "," domains) trim); corsList = domains: lists.remove "" (lists.forEach (strings.splitString "," domains) trim);
in { in {
options.home.dev.ai.opencode = { options.home.dev.ai.opencode = {
@@ -66,9 +81,9 @@ in {
}; };
}; };
config.programs.opencode = mkIf cfg.enable { config.programs.opencode = mkIf cfg.enable {
inherit (cfg) enable tui; inherit (cfg) enable tui package;
enableMcpIntegration = true; enableMcpIntegration = true;
extraPackages = with pkgs; [uv]; extraPackages = with pkgs; [uv] ++ lists.optional cfg.desktop.enable cfg.desktop.package;
settings = settings =
{ {
server = mkIf cfg.web.mdns.enable { server = mkIf cfg.web.mdns.enable {