Skip to content

fix: invalidate shell eval cache when devenv config changes#2643

Merged
domenkozar merged 3 commits into
cachix:mainfrom
hencjo:invalidate-shell-cache-when-devenv-config-changes
Mar 20, 2026
Merged

fix: invalidate shell eval cache when devenv config changes#2643
domenkozar merged 3 commits into
cachix:mainfrom
hencjo:invalidate-shell-cache-when-devenv-config-changes

Conversation

@hencjo

@hencjo hencjo commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

DISCLAIMER: Both bug triage, fix and most of this summary is AI Generated (Codex 5.4).

Human bug report

My changes in devenv.nix did not reflect in the build environment.
This happened both in direnv activation. and devenv shell`.

Changes to these attributes in devenv.nix didn't have effect on my shell:

  • languages (like adding gradle; and it not ending up on PATH).
  • ENVs not apperaing in shell.
  • scripts not appearing on path.
  • packages not being available.

This PR fixes this, but I have no idea if it's a desired approach. Please complete it with taste :D.

Everything that follows is AI-generated

This was caused by stale shell evaluation cache entries being reused after project configuration changed.

The key symptom was that different commands disagreed about the current configuration:

  • devenv info showed the updated packages and environment
  • devenv print-dev-env could still return an older cached shell environment

Because devenv shell and direnv activation both consume the shell environment output, they inherited the stale result as well. That made the issue look like a broad languages problem, but the language modules were not the root cause. The same failure mode affected top-level packages, env, and generated scripts.

The underlying issue was incomplete cache invalidation for shell environment evaluation. Changes to core project configuration files such as devenv.nix could leave an existing shell cache entry looking valid when it was no longer correct.

Fix approach

This PR fixes the problem by explicitly tracking core project configuration files as shell eval-cache inputs.

The shell cache now watches the project files that directly define the environment, including devenv.nix, devenv.yaml, devenv.lock, and local override files when they exist.

This keeps the change focused on cache correctness instead of adding special handling for individual features like languages, env, or scripts.

Why this approach

The failure was not specific to any one module. It was a generic shell-environment caching bug. Fixing cache input tracking addresses the common cause and keeps devenv info, devenv print-dev-env, devenv shell, and direnv activation consistent with each other.

Verification

The change is covered by focused tests for:

  • the shared shell cache key versioning
  • explicit tracking of core project config files

This is intended to be a low-maintenance fix: it hardens the cache boundary directly, rather than adding feature-specific behavior or a large end-to-end regression test.

Comment thread devenv-core/src/nix_backend.rs Outdated
@domenkozar

Copy link
Copy Markdown
Member

Looks good, could you also add an entry to CHANGELOG.md?

@hencjo

hencjo commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

Thank you. Will do!

hencjo added 3 commits March 20, 2026 12:23
Track core project config files explicitly in the FFI eval cache and bump
the shared shell cache key version so stale shell cache rows are not reused.

This fixes cases where `devenv info` reflected updated config but
`devenv print-dev-env`, `devenv shell`, and direnv activation kept serving
an older cached shell environment.
@hencjo hencjo force-pushed the invalidate-shell-cache-when-devenv-config-changes branch from bffb1db to 8923b5c Compare March 20, 2026 11:24
@domenkozar domenkozar merged commit c0aa1f8 into cachix:main Mar 20, 2026
@hencjo hencjo deleted the invalidate-shell-cache-when-devenv-config-changes branch March 20, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants