Stale package versions persist after editing replit.nix in Replit
0 reputation · 22 Sept 2021, 02:01 UTC
0 reputation · 22 Sept 2021, 02:01 UTC
The goal is to understand when a modification to the replit.nix file triggers a fresh Nix store build versus reusing a cached environment.
After editing replit.nix to change a package version, a simple restart of the repl does not always result in the updated version being active; the Nix store may retain previous builds, leading to mixed or outdated packages.
Because the documentation does not specify the exact conditions that invalidate the Nix cache, it is unclear whether a restart, a manual rebuild, or another action is required to guarantee reproducibility.
replit.nix automatically invalidate the Nix store?replit.nix automatically invalidate the Nix store?Replit’s build system watches replit.nix for changes. When you save a modification, the platform schedules a rebuild of the environment for that repl. The rebuild is not instantaneous; it runs the next time you press Run or Restart. If the rebuild completes successfully, the old derivations are replaced and the new package versions are used.
replit.nix and commit the change.
building… and finally success. The console will display the build log.
python -m pip show requests or node -v, depending on the package.
If you prefer the command line, you can trigger garbage collection to clean unused derivations:
nix-store --gc
but this only removes unused items; it does not replace the current environment.
/nix/store/abcd1234-python3-requests-2.28.1.
Deleting the hidden .replit-nix-cache directory is an unsupported workaround and may break future builds. Stick to the UI Rebuild environment button for predictable results.
After a rebuild, run:
nix-env -qaP <package>
to see the derivation hash and verify that it matches the new version you specified.
Did the rebuild log show a success message, or were there any errors? Knowing this will determine whether the stale package is due to an incomplete rebuild or a different issue.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 22 Sept 2021, 09:22 UTC
When modifying replit.nix, it is important to distinguish between the Nix store content and the active environment link. Because Nix uses content-addressable storage, any change to a package version results in a new hash in the /nix/store/ directory. If you have updated the version in replit.nix but see the old version after a restart, the environment is likely still pointing to the previous derivation.
To confirm if a rebuild has actually occurred, you can run the following in the shell:
which [package-name] & xargs ls -
If the returned path remains identical to your edit, the environment hasn't re-evaluated the Nix expression. In such cases, manually triggering a rebuild via the UI or clearing the environment-specific cache directory is necessary to force the system to symlink the active environment to the new store path.