nix-community / nix-direnv

A fast, persistent use_nix/use_flake implementation for direnv [maintainer=@Mic92 / @bbenne10]
MIT License
1.78k stars 101 forks source link

Issue when .envrc points to a flake in a git repository #480

Closed realbogart closed 6 months ago

realbogart commented 6 months ago

Hi,

Today I ran into an issue where I have the following in my .envrc file: use flake git+ssh://git@gitlab.my-selfhosted-gitlab/test.git

It works well but gets stuck on one commit. If I make a change to my test.git repository and push it, the new environment is never picked up. I have tried manually deleting the .direnv directory. Any ideas on how to resolve this?

Thank you!

realbogart commented 6 months ago

I managed to make it update by changing .envrc to: use flake git+ssh://git@gitlab.build.paradox-interactive.com/gsg/tech/conan/conan-nix.git --refresh

I'm not sure if this is the correct solution though.

bbenne10 commented 6 months ago

"gets stuck on one commit" isn't exactly clear. What does that mean exactly? Is the URL in your reply the one we can use to reproduce this problem (without --refresh)? Can I clone this url with https instead of ssh?

realbogart commented 6 months ago

Is the URL in your reply the one we can use to reproduce this problem (without --refresh)? Can I clone this url with https instead of ssh?

No, this is a private repository not accessible on the internet. Sorry, I should have created a way to reproduce the bug, or at least have made it clear.

"gets stuck on one commit" isn't exactly clear. What does that mean exactly?

That if I push a new commit to the repository (test.git), then it never gets picked up by direnv. Every time I enter the directory the previous commit of test.git is used.

After reading the documentation on how direnv works under the hood (https://github.com/nix-community/nix-direnv?tab=readme-ov-file#advanced-usage), I managed to force it to upgrade by adding --refresh. This is good enough for me and I'm ready to close the issue with that unless you think this is something that should work without it?

Thank you for your help.

bbenne10 commented 6 months ago

Oh. Yes - this is expected behavior. The git hash is resolved when the cache is created. (There might be more nix caching going on behind the scenes too, actually. I'm not entirely sure and have not gone poking around).

I think that --refresh is probably the best way to handle this with nix-direnv.

realbogart commented 6 months ago

Great, thank you!