Does editing 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.
How to guarantee a fresh environment
- Edit
replit.nix and commit the change.
- Open the Replit sidebar (the gear icon on the left).
- Click Rebuild environment. This forces the Nix store to discard the cached derivation for the current repl and rebuild the entire environment from the updated expression.
- Wait for the status bar to show
building… and finally success. The console will display the build log.
- Verify the new version by running a command that reports the package’s version, e.g.
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.
What if the new version still appears stale?
- Check the console for any build errors. If the rebuild was interrupted, the old derivation may still be in use.
- Confirm that the build log contains the expected package name and hash in the path, e.g.
/nix/store/abcd1234-python3-requests-2.28.1.
- Ensure you are not using a custom overlay that might cache a different derivation.
Undocumented cache clearing
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.
Quick sanity check
After a rebuild, run:
nix-env -qaP <package>
to see the derivation hash and verify that it matches the new version you specified.
Missing diagnostic detail
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.