Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shellHook caching inconsistency with and without flakes #90

Closed
ryneeverett opened this issue Jun 3, 2021 · 5 comments · Fixed by #91
Closed

shellHook caching inconsistency with and without flakes #90

ryneeverett opened this issue Jun 3, 2021 · 5 comments · Fixed by #91

Comments

@ryneeverett
Copy link
Contributor

In cached shells, the shellHook does not execute with use nix but does with use flake.

It would be easy to achieve consistency by piping the nix print-dev-env output through sed to remove the final eval "$shellHook", but I'm not sure this is the right direction. It seems that nix develop runs the shellHook even when cached so perhaps it's better not to fight the pattern flakes is currently implementing.

I'm not sure if this is a bug or just a (documentation-worthy?) distinction but it does complicate the creation of environments compatible with or without flakes. For example, I was planning to use an .envrc like:

nix flake --help > /dev/null \
  && use flake \
  || use nix

but heavy shellHooks will need to be rewritten to check whether their expensive processes have been run already.

@Mic92
Copy link
Member

Mic92 commented Jun 3, 2021

Do you have in your project both a flake.nix and a shell.nix?

@ryneeverett
Copy link
Contributor Author

Yes, devShell is set to the imported shell.nix. I should have time to upload a demo project this weekend if that would be helpful.

@ryneeverett
Copy link
Contributor Author

@Mic92
Copy link
Member

Mic92 commented Jun 7, 2021

Ok. I would accept patches to fix this. Ideally with a test.

@ryneeverett
Copy link
Contributor Author

I just pushed another README section to the demo demonstrating that while nix develop caches the nix evalutation, the shellHook still gets run on cached invocations.

However having taken a second look this inconsistency doesn't bother me. Caching is more of a feature of the new nix cli than the develop subcommand specifically and nix develop seems more like an improved nix-shell than a competitor with third party development environment caching tools like nix-direnv and lorri.

ryneeverett added a commit to ryneeverett/nix-direnv that referenced this issue Jun 8, 2021
This makes the behavior of `use flake` consistent with that of `use
nix`.

Resolve nix-community#90.
ryneeverett added a commit to ryneeverett/nix-direnv that referenced this issue Jun 9, 2021
This makes the behavior of `use flake` consistent with that of `use
nix`.

Resolve nix-community#90.
@Mic92 Mic92 closed this as completed in #91 Jun 11, 2021
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 a pull request may close this issue.

2 participants