Skip to content

Commit d8806e8

Browse files
committed
fix(opencode): repin the node_modules FOD per our nixpkgs bun
opencode's node_modules FOD is hash-pinned in upstream's hashes.json against the bun of their CI's nixpkgs. We follow our nixpkgs, where a newer bun lays out node_modules differently, so the pin fails deterministically (spec FY/I7zxm vs got Ppc2Kgb9). Re-pin per system with the hash our bun produces via the existing pins/ machinery (Renovate-tracked): opencode-node-modules.json read by pins/default.nix, same pattern as pi/omp/primeAgent. When our nixpkgs ships the same bun upstream's CI calibrates with, the override short-circuits and upstream's hashes.json wins; a null hash entry keeps the upstream behavior. Tracked upstream as anomalyco/opencode#49063 (proposes a bun-agnostic lockfile-aware FOD); drops when upstream lands the fix.
1 parent ff869e0 commit d8806e8

3 files changed

Lines changed: 75 additions & 18 deletions

File tree

‎home-manager/modules/development/opencode.nix‎

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,73 @@
55
inputs,
66
...
77
}:
8+
89
let
910
cfg = config.modules.development.opencode;
1011
system = pkgs.stdenv.hostPlatform.system;
1112

13+
pins =
14+
(import ../development/pins {
15+
inherit lib;
16+
inherit (pkgs) fetchurl fetchzip;
17+
}).opencodeNodeModules;
18+
19+
# opencode's node_modules FOD is hash-pinned in upstream's hashes.json
20+
# against their CI's bun, but we follow our nixpkgs and build with ours.
21+
# The local pin records the hash our bun actually produces (see
22+
# pins/opencode-node-modules.json). When our nixpkgs ships upstream's
23+
# expected bun, the pin is bypassed and upstream's hashes.json wins.
24+
# Tracked upstream as anomalyco/opencode#49063 proposing a bun-agnostic
25+
# lockfile-aware FOD.
26+
node_modulesOverride =
27+
if pins.bun == pkgs.bun.version then
28+
{ }
29+
else if pins.hashes.${system} or null != null then
30+
{
31+
node_modules = inputs.opencode.packages.${system}.default.node_modules.override {
32+
hash = pins.hashes.${system};
33+
};
34+
}
35+
else
36+
null;
37+
1238
baseOpencodePackage = inputs.opencode.packages.${system}.default or null;
1339

1440
opencodePackage =
15-
if baseOpencodePackage != null then
16-
baseOpencodePackage.overrideAttrs (previousAttrs: {
17-
# Workaround: native Node modules need libstdc++ at runtime on Linux.
18-
# Remove when upstream wraps the executable with its compiler runtime.
19-
postFixup =
20-
(previousAttrs.postFixup or "")
21-
+ lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
22-
wrapProgram "$out/bin/opencode" \
23-
--prefix LD_LIBRARY_PATH : ${pkgs.stdenv.cc.cc.lib}/lib
24-
'';
25-
})
41+
if baseOpencodePackage == null then
42+
null
43+
else if node_modulesOverride == null then
44+
null
2645
else
27-
null;
46+
baseOpencodePackage.override node_modulesOverride;
2847

2948
mkDesktopPackage =
3049
let
3150
desktop = inputs.opencode.packages.${system}.opencode-desktop or null;
3251
in
3352
if desktop != null then
34-
desktop.override {
35-
opencode = opencodePackage;
36-
# opencode builds with bare nixpkgs.legacyPackages: re-instance the
37-
# EOL electron_41 pin here so permittedInsecurePackages applies.
38-
electron_41 = pkgs.electron_41;
39-
}
53+
if opencodePackage == null then
54+
null
55+
else
56+
let
57+
opencode =
58+
opencodePackage.overrideAttrs (previousAttrs: {
59+
# Workaround: native Node modules need libstdc++ at runtime on Linux.
60+
# Remove when upstream wraps the executable with its compiler runtime.
61+
postFixup =
62+
(previousAttrs.postFixup or "")
63+
+ lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
64+
wrapProgram "$out/bin/opencode" \
65+
--prefix LD_LIBRARY_PATH : ${pkgs.stdenv.cc.cc.lib}/lib
66+
'';
67+
});
68+
in
69+
desktop.override {
70+
inherit opencode;
71+
# opencode builds with bare nixpkgs.legacyPackages: re-instance the
72+
# EOL electron_41 pin here so permittedInsecurePackages applies.
73+
electron_41 = pkgs.electron_41;
74+
}
4075
else
4176
null;
4277

‎home-manager/modules/development/pins/default.nix‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ let
1111
piData = readPin ./pi.json;
1212
ompData = readPin ./omp.json;
1313
primeAgentData = readPin ./prime-agent.json;
14+
opencodeData = readPin ./opencode-node-modules.json;
1415

1516
expectedOmpKeys = [
1617
"darwin-arm64"
@@ -27,7 +28,14 @@ let
2728
"mcp"
2829
"mcp-types"
2930
];
31+
expectedOpencodeHashKeys = [
32+
"aarch64-darwin"
33+
"aarch64-linux"
34+
"x86_64-darwin"
35+
"x86_64-linux"
36+
];
3037
in
38+
assert builtins.attrNames opencodeData.hashes == expectedOpencodeHashKeys;
3139
assert builtins.attrNames ompData.hashes == expectedOmpKeys;
3240
assert builtins.attrNames primeAgentData.npm == expectedPrimeNpmKeys;
3341
assert builtins.attrNames primeAgentData.python == expectedPrimePythonKeys;
@@ -55,6 +63,11 @@ assert
5563
) ompData.hashes;
5664
};
5765

66+
opencodeNodeModules = {
67+
inherit (opencodeData) bun;
68+
hashes = opencodeData.hashes;
69+
};
70+
5871
primeAgent = {
5972
inherit (primeAgentData) version rlmExtraPackages snapshotRequirement;
6073
src = fetchzip {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"bun": "1.4.2",
3+
"hashes": {
4+
"aarch64-darwin": null,
5+
"aarch64-linux": null,
6+
"x86_64-darwin": null,
7+
"x86_64-linux": "sha256-Ppc2Kgb9D9xdkrNMyQgPS6rn/zU5zMqMKvAmrFCj1zQ="
8+
}
9+
}

0 commit comments

Comments
 (0)