feat: replace local opencode with upstream flake input v1.1.27

- Add `opencode` flake input pinned to v1.1.27 for stability
- Remove local `pkgs/opencode` derivation and overlay
- Add `opencode` and `opencode-desktop` to `pkgs/default.nix` from input
This commit is contained in:
m3tm3re
2026-01-20 18:32:28 +01:00
parent d3809a7b5e
commit de3850fb1b
7 changed files with 46 additions and 273 deletions

38
flake.lock generated
View File

@@ -16,9 +16,45 @@
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1768569498,
"narHash": "sha256-bB6Nt99Cj8Nu5nIUq0GLmpiErIT5KFshMQJGMZwgqUo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "be5afa0fcb31f0a96bf9ecba05a516c66fcd8114",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"opencode": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1768911228,
"narHash": "sha256-iJ4WLNyP9i8baxp1FJJLv2VBD3XcE8nCruwO3GmSmK4=",
"owner": "anomalyco",
"repo": "opencode",
"rev": "e521fee0023a604bb6d5ef39b4b892cbf1a0f9d4",
"type": "github"
},
"original": {
"owner": "anomalyco",
"ref": "v1.1.27",
"repo": "opencode",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"opencode": "opencode"
}
}
},

View File

@@ -3,6 +3,7 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
opencode.url = "github:anomalyco/opencode/v1.1.27";
# Optional: Add stable channel if needed
# nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-24.05";
@@ -36,18 +37,18 @@
system: let
pkgs = pkgsFor system;
in
import ./pkgs {inherit pkgs;}
import ./pkgs {inherit pkgs inputs;}
);
# Overlays - can be imported in your system configuration
overlays = {
# Default overlay: adds all custom packages
default = final: prev:
import ./pkgs {pkgs = final;};
import ./pkgs {pkgs = final; inputs = inputs;};
# Individual overlays for more granular control
additions = final: prev:
import ./pkgs {pkgs = final;};
import ./pkgs {pkgs = final; inputs = inputs;};
modifications = final: prev:
import ./overlays/mods {inherit prev;};

View File

@@ -3,7 +3,6 @@
# This overlay contains package overrides and modifications
# n8n = import ./n8n.nix {inherit prev;};
# opencode = import ./opencode.nix {inherit prev;};
# beads = import ./beads.nix {inherit prev;};
# Add more modifications here as needed

View File

@@ -1,16 +0,0 @@
{prev}:
prev.opencode.overrideAttrs (oldAttrs: rec {
version = "1.1.18";
src = prev.fetchFromGitHub {
owner = "anomalyco";
repo = "opencode";
tag = "v${version}";
hash = "sha256-3A4s0FpjZuGB0HGMQVBXfWq+0yHmeIvnEQTSX3amV4I=";
};
node_modules = oldAttrs.node_modules.overrideAttrs (old: {
inherit version src;
outputHash = "sha256-zSco4ORQQOqV3vMPuP+M/q/hBa+MJGnTKIlxgngMA3g=";
});
})

View File

@@ -1,4 +1,4 @@
{pkgs, ...}: {
{pkgs, inputs ? null, ...}: {
# Custom packages registry
# Each package is defined in its own directory under pkgs/
beads = pkgs.callPackage ./beads {};
@@ -8,10 +8,13 @@
mem0 = pkgs.callPackage ./mem0 {};
msty-studio = pkgs.callPackage ./msty-studio {};
n8n = pkgs.callPackage ./n8n {};
opencode = pkgs.callPackage ./opencode {};
pomodoro-timer = pkgs.callPackage ./pomodoro-timer {};
rofi-project-opener = pkgs.callPackage ./rofi-project-opener {};
stt-ptt = pkgs.callPackage ./stt-ptt {};
tuxedo-backlight = pkgs.callPackage ./tuxedo-backlight {};
zellij-ps = pkgs.callPackage ./zellij-ps {};
# Imported from flake inputs
opencode = inputs.opencode.packages.${pkgs.system}.opencode;
opencode-desktop = inputs.opencode.packages.${pkgs.system}.desktop;
}

View File

@@ -1,222 +0,0 @@
{
lib,
stdenvNoCC,
bun,
fetchFromGitHub,
fzf,
makeBinaryWrapper,
models-dev,
nix-update-script,
ripgrep,
testers,
installShellFiles,
writableTmpDirAsHomeHook,
}: let
pname = "opencode";
version = "1.1.25";
src = fetchFromGitHub {
owner = "anomalyco";
repo = "opencode";
tag = "v${version}";
hash = "sha256-aF+4LL0x9wU2Ktrv/nJE2VXgUeXFrwJ16pa1sGNhpi4=";
};
node_modules = stdenvNoCC.mkDerivation {
pname = "${pname}-node_modules";
inherit version src;
impureEnvVars =
lib.fetchers.proxyImpureEnvVars
++ ["GIT_PROXY_COMMAND" "SOCKS_SERVER"];
nativeBuildInputs = [bun writableTmpDirAsHomeHook];
dontConfigure = true;
buildPhase = ''
runHook preBuild
export BUN_INSTALL_CACHE_DIR=$(mktemp -d)
bun install \
--cpu="*" \
--filter=./packages/opencode \
--force \
--frozen-lockfile \
--ignore-scripts \
--no-progress \
--os="*" \
--production
bun run ./nix/scripts/canonicalize-node-modules.ts
bun run ./nix/scripts/normalize-bun-binaries.ts
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
find . -type d -name node_modules -exec cp -R --parents {} $out \;
runHook postInstall
'';
# NOTE: Required else we get errors that our fixed-output derivation references store paths
dontFixup = true;
outputHash = "sha256-qheQCN71VM3M35+j9XhaCdxQNo5ze8mV8sDFaX0WVWM=";
outputHashAlgo = "sha256";
outputHashMode = "recursive";
};
in
stdenvNoCC.mkDerivation (finalAttrs: {
inherit pname version src node_modules;
nativeBuildInputs = [
bun
installShellFiles
makeBinaryWrapper
models-dev
writableTmpDirAsHomeHook
];
patches = [
# NOTE: Relax Bun version check to be a warning instead of an error
./relax-bun-version-check.patch
];
dontConfigure = true;
env.MODELS_DEV_API_JSON = "${models-dev}/dist/_api.json";
env.OPENCODE_VERSION = finalAttrs.version;
env.OPENCODE_CHANNEL = "stable";
buildPhase = ''
runHook preBuild
# Copy all node_modules including the .bun directory with actual packages
cp -r ${finalAttrs.node_modules}/node_modules .
cp -r ${finalAttrs.node_modules}/packages .
(
cd packages/opencode
# Fix symlinks to workspace packages
chmod -R u+w ./node_modules
mkdir -p ./node_modules/@opencode-ai
rm -f ./node_modules/@opencode-ai/{script,sdk,plugin}
ln -s $(pwd)/../../packages/script ./node_modules/@opencode-ai/script
ln -s $(pwd)/../../packages/sdk/js ./node_modules/@opencode-ai/sdk
ln -s $(pwd)/../../packages/plugin ./node_modules/@opencode-ai/plugin
# Use upstream bundle.ts for Nix-compatible bundling
cp ../../nix/bundle.ts ./bundle.ts
chmod +x ./bundle.ts
bun run ./bundle.ts
)
runHook postBuild
'';
installPhase = ''
runHook preInstall
cd packages/opencode
if [ ! -d dist ]; then
echo "ERROR: dist directory missing after bundle step"
exit 1
fi
mkdir -p $out/lib/opencode
cp -r dist $out/lib/opencode/
chmod -R u+w $out/lib/opencode/dist
# Select bundled worker assets deterministically (sorted find output)
worker_file=$(find "$out/lib/opencode/dist" -type f \( -path '*/tui/worker.*' -o -name 'worker.*' \) | sort | head -n1)
parser_worker_file=$(find "$out/lib/opencode/dist" -type f -name 'parser.worker.*' | sort | head -n1)
if [ -z "$worker_file" ]; then
echo "ERROR: bundled worker not found"
exit 1
fi
main_wasm=$(printf '%s\n' "$out"/lib/opencode/dist/tree-sitter-*.wasm | sort | head -n1)
wasm_list=$(find "$out/lib/opencode/dist" -maxdepth 1 -name 'tree-sitter-*.wasm' -print)
for patch_file in "$worker_file" "$parser_worker_file"; do
[ -z "$patch_file" ] && continue
[ ! -f "$patch_file" ] && continue
if [ -n "$wasm_list" ] && grep -q 'tree-sitter' "$patch_file"; then
# Rewrite wasm references to absolute store paths to avoid runtime resolve failures.
bun --bun ../../nix/scripts/patch-wasm.ts "$patch_file" "$main_wasm" $wasm_list
fi
done
mkdir -p $out/lib/opencode/node_modules
cp -r ../../node_modules/.bun $out/lib/opencode/node_modules/
mkdir -p $out/lib/opencode/node_modules/@opentui
# Generate and install JSON schema
mkdir -p $out/share/opencode
HOME=$TMPDIR bun --bun script/schema.ts $out/share/opencode/schema.json
mkdir -p $out/bin
makeWrapper ${lib.getExe bun} $out/bin/opencode \
--add-flags "run" \
--add-flags "$out/lib/opencode/dist/src/index.js" \
--prefix PATH : ${lib.makeBinPath [fzf ripgrep]} \
--argv0 opencode
runHook postInstall
'';
postInstall = ''
# Add symlinks for platform-specific native modules
pkgs=(
$out/lib/opencode/node_modules/.bun/@opentui+core-*
$out/lib/opencode/node_modules/.bun/@opentui+solid-*
$out/lib/opencode/node_modules/.bun/@opentui+core@*
$out/lib/opencode/node_modules/.bun/@opentui+solid@*
)
for pkg in "''${pkgs[@]}"; do
if [ -d "$pkg" ]; then
pkgName=$(basename "$pkg" | sed 's/@opentui+\([^@]*\)@.*/\1/')
ln -sf ../.bun/$(basename "$pkg")/node_modules/@opentui/$pkgName \
$out/lib/opencode/node_modules/@opentui/$pkgName
fi
done
${lib.optionalString
((stdenvNoCC.buildPlatform.canExecute stdenvNoCC.hostPlatform)
&& (stdenvNoCC.hostPlatform.system != "x86_64-darwin")) ''
installShellCompletion --cmd opencode \
--bash <($out/bin/opencode completion)
''}
'';
passthru = {
jsonschema = "${placeholder "out"}/share/opencode/schema.json";
tests.version = testers.testVersion {
package = finalAttrs.finalPackage;
command = "HOME=$(mktemp -d) opencode --version";
inherit (finalAttrs) version;
};
updateScript =
nix-update-script {extraArgs = ["--subpackage" "node_modules"];};
};
meta = {
description = "AI coding agent built for the terminal";
longDescription = ''
OpenCode is a terminal-based agent that can build anything.
It combines a TypeScript/JavaScript core with a Go-based TUI
to provide an interactive AI coding experience.
'';
homepage = "https://github.com/anomalyco/opencode";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [delafthi];
sourceProvenance = with lib.sourceTypes; [fromSource];
platforms = ["aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin"];
mainProgram = "opencode";
};
})

View File

@@ -1,28 +0,0 @@
From 0e07ea8225f5667e39c6aa59eea726266f0afab0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
Date: Thu, 13 Nov 2025 10:16:31 +0100
Subject: [PATCH] Change Bun version check from error to warning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
---
packages/script/src/index.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/script/src/index.ts b/packages/script/src/index.ts
index 141d2b75..de06d0dc 100644
--- a/packages/script/src/index.ts
+++ b/packages/script/src/index.ts
@@ -10,7 +10,7 @@ if (!expectedBunVersion) {
}
if (process.versions.bun !== expectedBunVersion) {
- throw new Error(`This script requires bun@${expectedBunVersion}, but you are using bun@${process.versions.bun}`)
+ console.warn(`Warning: This script expects bun@${expectedBunVersion}, but you are using bun@${process.versions.bun}`)
}
const CHANNEL = process.env["OPENCODE_CHANNEL"] ?? (await $`git branch --show-current`.text().then((x) => x.trim()))
--
2.51.0