Skip to content

Commit 3bf3e73

Browse files
committed
fix(opencode): symlink-to-copy activation, npm guard, libstdc++ watcher fix
- Convert home.file symlinks to real copies via makeOpencodeConfigMutable activation script with cmp-s guards to avoid unnecessary overwrites - Manage skills/ and commands/ as real directories (not HM symlinks) since HM cannot overwrite existing dirs with force=true - Add npm install guard: skip if node_modules exists and package.json unchanged - Add SQLite workaround: symlink opencode.db -> opencode-stable.db - Fix @parcel/watcher native binding on NixOS: wrap opencode binary with LD_LIBRARY_PATH pointing to stdenv.cc.cc.lib (libstdc++.so.6) Upstream: anomalyco/opencode#18447
1 parent 26091fd commit 3bf3e73

2 files changed

Lines changed: 54 additions & 25 deletions

File tree

‎modules/base/overlays.nix‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ in
5555
};
5656
};
5757

58+
# Fix @parcel/watcher native binding: libstdc++.so.6 not found on NixOS
59+
# See: https://github.com/sst/opencode/issues/18447
60+
# nixpkgs fix: https://github.com/NixOS/nixpkgs/commit/f2dd0a1
61+
opencode = prev.opencode.overrideAttrs (oldAttrs: {
62+
nativeBuildInputs = (oldAttrs.nativeBuildInputs or [ ]) ++ [ final.makeWrapper ];
63+
postFixup =
64+
(oldAttrs.postFixup or "")
65+
+ ''
66+
wrapProgram $out/bin/opencode \
67+
--set LD_LIBRARY_PATH "${final.lib.makeLibraryPath [ final.stdenv.cc.cc.lib ]}"
68+
'';
69+
});
70+
5871
libmateweather = prev.libmateweather.overrideAttrs (oldAttrs: {
5972
# Fix pointer offset bug in METAR parsing
6073
postPatch = (oldAttrs.postPatch or "") + ''

‎modules/home/opencode.nix‎

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ let
5757
mcp = enabledMcps;
5858
permission = cfg.permissions;
5959
plugin = [ "opencode-model-fallback-chain" ];
60-
log = {
61-
level = "WARN";
62-
};
6360
experimental = {
6461
modelFallbackChain = {
6562
timeoutMs = 60000;
@@ -89,9 +86,8 @@ let
8986
${builtins.readFile ./opencode/SYSTEM_RULES.md}
9087
'';
9188
".config/${runtimeCfg.dir}/AGENTS.md".source = "${pkgs.gentle-ai-assets}/share/gentle-ai/AGENTS.md";
92-
".config/${runtimeCfg.dir}/skills".source = "${pkgs.gentle-ai-assets}/share/gentle-ai/skills";
93-
".config/${runtimeCfg.dir}/commands".source =
94-
"${pkgs.gentle-ai-assets}/share/gentle-ai/opencode/commands";
89+
# skills/ and commands/ are managed entirely by makeOpencodeConfigMutable activation
90+
# (not via home.file) because HM cannot overwrite existing real directories with symlinks
9591
".config/${runtimeCfg.dir}/package.json" = {
9692
force = true;
9793
text = builtins.toJSON {
@@ -140,29 +136,38 @@ let
140136
${pkgs.coreutils}/bin/cp --remove-destination "$src" "$target"
141137
fi
142138
fi
139+
# Ensure files are writable (nix store sources are read-only)
140+
if [ -f "$target" ] && [ ! -w "$target" ]; then
141+
chmod 644 "$target"
142+
fi
143143
done
144144
145-
# Directory symlinks -> real directories (skills/, commands/)
146-
for dir in skills commands; do
147-
target="$runtime_dir/$dir"
145+
# Directory management for skills/ and commands/
146+
# Handled here (not via home.file) because HM cannot overwrite real dirs with symlinks.
147+
# Copies files from nix store with per-file cmp guard + orphan removal.
148+
for dir_pair in "skills:${pkgs.gentle-ai-assets}/share/gentle-ai/skills" "commands:${pkgs.gentle-ai-assets}/share/gentle-ai/opencode/commands"; do
149+
dir_name="''${dir_pair%%:*}"
150+
src="''${dir_pair#*:}"
151+
target="$runtime_dir/$dir_name"
152+
# Remove symlink if HM managed to create one
148153
if [ -L "$target" ]; then
149-
src="$(${pkgs.coreutils}/bin/readlink -f "$target")"
150154
${pkgs.coreutils}/bin/rm -f "$target"
151-
mkdir -p "$target"
152-
# Copy changed files
153-
(cd "$src" && ${pkgs.findutils}/bin/find . -type f) | while read -r rel; do
154-
if [ ! -f "$target/$rel" ] || ! ${pkgs.coreutils}/bin/cmp -s "$src/$rel" "$target/$rel"; then
155-
mkdir -p "$(dirname "$target/$rel")"
156-
${pkgs.coreutils}/bin/cp -f "$src/$rel" "$target/$rel"
157-
fi
158-
done
159-
# Remove orphaned files
160-
(cd "$target" && ${pkgs.findutils}/bin/find . -type f) | while read -r rel; do
161-
if [ ! -f "$src/$rel" ]; then
162-
rm -f "$target/$rel"
163-
fi
164-
done
165155
fi
156+
mkdir -p "$target"
157+
# Copy changed files
158+
(cd "$src" && ${pkgs.findutils}/bin/find . -type f) | while read -r rel; do
159+
if [ ! -f "$target/$rel" ] || ! ${pkgs.coreutils}/bin/cmp -s "$src/$rel" "$target/$rel"; then
160+
mkdir -p "$(dirname "$target/$rel")"
161+
${pkgs.coreutils}/bin/cp -f "$src/$rel" "$target/$rel"
162+
chmod 644 "$target/$rel"
163+
fi
164+
done
165+
# Remove orphaned files
166+
(cd "$target" && ${pkgs.findutils}/bin/find . -type f) | while read -r rel; do
167+
if [ ! -f "$src/$rel" ]; then
168+
rm -f "$target/$rel"
169+
fi
170+
done
166171
done
167172
'';
168173

@@ -188,13 +193,15 @@ let
188193
src="${pkgs.engram-assets}/share/engram/opencode/plugins/engram.ts"
189194
if [ ! -f "$target" ] || ! ${pkgs.coreutils}/bin/cmp -s "$src" "$target"; then
190195
${pkgs.coreutils}/bin/cp -f "$src" "$target"
196+
chmod 644 "$target"
191197
fi
192198
''}
193199
${lib.optionalString cfg.plugins.backgroundAgents.enable ''
194200
target="$runtime_dir/plugins/background-agents.ts"
195201
src="${pkgs.gentle-ai-assets}/share/gentle-ai/opencode/plugins/background-agents.ts"
196202
if [ ! -f "$target" ] || ! ${pkgs.coreutils}/bin/cmp -s "$src" "$target"; then
197203
${pkgs.coreutils}/bin/cp -f "$src" "$target"
204+
chmod 644 "$target"
198205
fi
199206
''}
200207
@@ -230,9 +237,18 @@ let
230237
target="$runtime_dir/node_modules/opencode-sdd-engram-manage"
231238
if [ ! -d "$target" ]; then
232239
${pkgs.nodejs}/bin/npm install --prefix "$runtime_dir" --no-save \
233-
[email protected] >/dev/null 2>&1 || true
240+
[email protected] >/dev/null 2>&1 || true
234241
fi
235242
''}
243+
244+
# Workaround for opencode bug: migration gate checks for opencode.db
245+
# but non-latest channels (stable) use opencode-stable.db, causing
246+
# migration to re-run on every launch. Symlink stable -> default name.
247+
# See: https://github.com/anomalyco/opencode/issues/16885
248+
data_dir="${config.home.homeDirectory}/.local/share/opencode"
249+
if [ -f "$data_dir/opencode-stable.db" ] && [ ! -e "$data_dir/opencode.db" ]; then
250+
ln -s "$data_dir/opencode-stable.db" "$data_dir/opencode.db"
251+
fi
236252
'';
237253
};
238254
in

0 commit comments

Comments
 (0)