diff --git a/.changeset/fix-nix-bun-pin.md b/.changeset/fix-nix-bun-pin.md new file mode 100644 index 0000000000..5facef0667 --- /dev/null +++ b/.changeset/fix-nix-bun-pin.md @@ -0,0 +1,5 @@ +--- +"@kilocode/cli": patch +--- + +Keep Nix builds on the Bun version required by the repository. diff --git a/flake.nix b/flake.nix index 7383da725d..280d60035c 100644 --- a/flake.nix +++ b/flake.nix @@ -21,59 +21,7 @@ devShells = forEachSystem (pkgs: { default = let - # Pin bun to the version declared in package.json (packageManager: "bun@1.3.14"). - # The locked nixpkgs revision ships 1.3.11, so we fetch the official release directly. - bun = - let - sources = { - "aarch64-linux" = { - name = "bun-linux-aarch64"; - hash = "sha256-on/7Y6gxA3WDbg1vZorhf6jY0YuIw3yCHGUzGXOhmjs="; - }; - "x86_64-linux" = { - name = "bun-linux-x64"; - hash = "sha256-lR7iruhV8IWVruxiJSJqKY0/6oOj3NZGXAnLzN9+hI8="; - }; - "aarch64-darwin" = { - name = "bun-darwin-aarch64"; - hash = "sha256-2LliIYKK1vl6x6wKt+lYcjQa92MAHogD6CZ2UsJlJiA="; - }; - "x86_64-darwin" = { - name = "bun-darwin-x64"; - hash = "sha256-QYPfM3RiPlurMVxUfPoJdFM81FfYa3O2OfeoeXTNZjM="; - }; - }; - source = - sources.${pkgs.stdenv.hostPlatform.system} - or (throw "Unsupported system for bun: ${pkgs.stdenv.hostPlatform.system}"); - in - pkgs.stdenv.mkDerivation rec { - pname = "bun"; - version = "1.3.14"; - src = pkgs.fetchurl { - url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/${source.name}.zip"; - inherit (source) hash; - }; - nativeBuildInputs = [ - pkgs.unzip - ] ++ pkgs.lib.optional pkgs.stdenv.isLinux pkgs.autoPatchelfHook; - buildInputs = pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.stdenv.cc.cc.lib ]; - dontConfigure = true; - dontBuild = true; - installPhase = '' - runHook preInstall - install -Dm755 bun $out/bin/bun - ln -s $out/bin/bun $out/bin/bunx - runHook postInstall - ''; - meta = { - description = "Fast all-in-one JavaScript runtime"; - homepage = "https://bun.sh"; - license = pkgs.lib.licenses.mit; - mainProgram = "bun"; - platforms = builtins.attrNames sources; - }; - }; + bun = pkgs.callPackage ./nix/bun.nix { }; kilo-dev = pkgs.writeShellScriptBin "kilo-dev" '' set -euo pipefail @@ -279,11 +227,12 @@ packages = forEachSystem ( pkgs: let + bun = pkgs.callPackage ./nix/bun.nix { }; node_modules = pkgs.callPackage ./nix/node_modules.nix { - inherit rev; + inherit bun rev; }; kilo = pkgs.callPackage ./nix/kilo.nix { - inherit node_modules; + inherit bun node_modules; }; in { diff --git a/nix/bun.nix b/nix/bun.nix new file mode 100644 index 0000000000..a880895349 --- /dev/null +++ b/nix/bun.nix @@ -0,0 +1,60 @@ +{ + lib, + stdenv, + fetchurl, + unzip, + autoPatchelfHook, +}: +let + package = lib.pipe ../package.json [ + builtins.readFile + builtins.fromJSON + ]; + version = lib.removePrefix "bun@" package.packageManager; + sources = { + "aarch64-linux" = { + name = "bun-linux-aarch64"; + hash = "sha256-on/7Y6gxA3WDbg1vZorhf6jY0YuIw3yCHGUzGXOhmjs="; + }; + "x86_64-linux" = { + name = "bun-linux-x64"; + hash = "sha256-lR7iruhV8IWVruxiJSJqKY0/6oOj3NZGXAnLzN9+hI8="; + }; + "aarch64-darwin" = { + name = "bun-darwin-aarch64"; + hash = "sha256-2LliIYKK1vl6x6wKt+lYcjQa92MAHogD6CZ2UsJlJiA="; + }; + "x86_64-darwin" = { + name = "bun-darwin-x64"; + hash = "sha256-QYPfM3RiPlurMVxUfPoJdFM81FfYa3O2OfeoeXTNZjM="; + }; + }; + source = + sources.${stdenv.hostPlatform.system} + or (throw "Unsupported system for bun: ${stdenv.hostPlatform.system}"); +in +stdenv.mkDerivation { + pname = "bun"; + inherit version; + src = fetchurl { + url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/${source.name}.zip"; + inherit (source) hash; + }; + nativeBuildInputs = [ unzip ] ++ lib.optional stdenv.isLinux autoPatchelfHook; + buildInputs = lib.optionals stdenv.isLinux [ stdenv.cc.cc.lib ]; + dontConfigure = true; + dontBuild = true; + installPhase = '' + runHook preInstall + install -Dm755 bun $out/bin/bun + ln -s $out/bin/bun $out/bin/bunx + runHook postInstall + ''; + meta = { + description = "Fast all-in-one JavaScript runtime"; + homepage = "https://bun.sh"; + license = lib.licenses.mit; + mainProgram = "bun"; + platforms = builtins.attrNames sources; + }; +}