Skip to content

sync-models user service fails from Nix store layout: resolves opencode config to /nix/.opencode/opencode.jsonc #591

Closed

Description

@dezren39

Symptom

The sync-models systemd user service on amd (Framework laptop) fails on every run. Latest journal evidence (2026-10-22 00:44:49 CDT, journalctl --user -u sync-models):

[sync-models] Discovered 22 models from Antigravity Language Server
[sync-models] Discovering Codex models...
[sync-models] Discovered 9 models from Codex cache
[sync-models] Error: /nix/.opencode/opencode.jsonc does not exist!
sync-models.service: Main process exited, code=exited, status=1/FAILURE

Discovery works fine — the failure is purely in resolving the config file the script syncs models into.

Root cause

bin/sync-models.mjs resolves the config relative to its own location:

const ROOT_DIR = path.resolve(import.meta.dirname, '..');
const OPENCODE_CONFIG_PATH = path.join(ROOT_DIR, '.opencode/opencode.jsonc');

That assumption holds in a repo checkout (<repo>/bin → <repo>/.opencode/opencode.jsonc). But the home-manager unit (home/common/default.nix, systemd.user.services.sync-models) runs the file from the Nix store: node ${../../bin/sync-models.mjs} interpolates to a lone store file (/nix/store/<hash>-sync-models.mjs), so import.meta.dirname is /nix/store, ROOT_DIR becomes /nix, and the script looks for /nix/.opencode/opencode.jsonc — which never exists.

(POLICY_PATH has the same store-layout problem, but its loader already tolerates a missing file and falls back to empty defaults, so it degrades silently instead of failing.)

Fix

Resolve the config path in this order:

  1. $OPENCODE_CONFIG_PATH env override, if set.
  2. The repo-local .opencode/opencode.jsonc when it exists (in-checkout runs keep today's behavior).
  3. The deployed user config ~/.config/opencode/opencode.jsonc — the file the service actually maintains, and the same file the opencode-config-normalize path unit already watches.

Acceptance

  • Installed (store-layout) run no longer dies at the config-exists check; it targets ~/.config/opencode/opencode.jsonc.
  • In-repo run behavior unchanged.
  • Verified by a dry-run from a store-like layout (script copied alone into a bare directory) passing the config resolution step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions