#37200·nx

Allow overriding the local cache db name (e.g. NX_DB_NAME) so a restored .nx/workspace-data is usable on another machine

Author: omril1Created Sep 26, 2026Updated Sep 26, 2026

Current behavior

connect_to_nx_db (packages/nx/src/native/db/mod.rs) names the local cache index <db_name>-v<DB_VERSION>.db with db_name.unwrap_or_else(get_machine_id). The db_name parameter exists since #26891 but nothing sets it: getDbConnection({ dbName }) in packages/nx/src/utils/db-connection.ts has no caller passing one, and there is no environment override (checked on 22.7.9 and on master).

On Linux the id comes from machine-uid (/var/lib/dbus/machine-id, then /etc/machine-id); on macOS from the host UUID. So the file name is a property of the machine, not of the workspace.

Why this matters

Since the index moved into the sqlite db, persisting .nx/cache alone on CI yields zero hits; persisting .nx/cache together with .nx/workspace-data/*.db works — but only while the restoring runner has the same machine id as the one that saved. Ephemeral runners built from the same image happen to share one, so this works until the image changes, and then every restore is silently cold: the restored db is ignored and Nx reports "Nx found unrecognized artifacts in the cache directory". #35403 looks like this failure mode.

Reproduced on 22.7.9: restoring .nx/cache + .nx/workspace-data/<id>-v2.db from another runner gave 4/4 cache hits when the ids matched; with a mismatched name the db is not picked up.

Expected behavior

A way to pin the db file name, so a saved .nx/workspace-data is usable on any machine that restores it:

  • an environment variable, e.g. NX_DB_NAME=ci, read in db-connection.ts and passed as dbName, or
  • a nx.json option.

Either would let CI restore the local cache deterministically without touching /etc/machine-id or renaming the db file after restore (the workarounds available today).

Nx version

22.7.9 (naming unchanged on master as of 2026-09-26).

Happy to send a PR for the env-var variant: read process.env.NX_DB_NAME in getDbConnection/getDbConnectionForWorkspace and pass it through to connectToNxDb.