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

Add direnv #669

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add direnv #669

wants to merge 4 commits into from

Conversation

levydsa
Copy link
Contributor

@levydsa levydsa commented Jan 14, 2025

Add use flake configuration for direnv. For Nix users, being able to hop into a directory and loading the environment automatically is very convenient.

@levydsa levydsa changed the title Add direnv: .envrc Add direnv Jan 14, 2025
@thisismiller
Copy link
Contributor

Committing this sort of locks out anyone from doing anything else with direnv though (which layout python3 also rather convenient given the recently added python bindings)

@levydsa
Copy link
Contributor Author

levydsa commented Jan 14, 2025

Committing this sort of locks out anyone from doing anything else with direnv though (which layout python3 also rather convenient given the recently added python bindings)

@thisismiller, I addressed this in 453571e. Take a look :)

@penberg
Copy link
Collaborator

penberg commented Jan 14, 2025

I don't use Flake or nix so... does this look better now, @thisismiller?

@levydsa
Copy link
Contributor Author

levydsa commented Jan 14, 2025

@penberg, this can be safely merged. The configuration checks if nix is present. Example on another repo: https://github.com/ghostty-org/ghostty/blob/6ef757a8f85db7a124d370378850339a899c9e65/.envrc

@thisismiller
Copy link
Contributor

thisismiller commented Jan 14, 2025

Sorry for making unconstructive complaints. I'm already a direnv user, but not a nix user. So committing a .envrc file means I'd just have to carry around a conflict permanently, or figure out that one line of git magic to ignore conflicts from a specific file name.

I don't oppose committing a file with the direnv script for flake if that's helpful for folk, but I'd suggest maybe adding .envrc to .gitignore and offering the current script as .envrc_flake. We can then append to the README setup instructions a "if you're a direnv and flake user, then do echo source_env .envrc_flake > .envrc".

If most people are flake users already and I'm the odd one out, then appending a source_env_if_exists .envrc_custom to the bottom of the current script (and adding .envrc_custom to .gitignore) at least lets me keep the layout python3 I currently have without have a permanent conflict.

@levydsa
Copy link
Contributor Author

levydsa commented Jan 15, 2025

@thisismiller, don't be sorry, your input is very much valid. I said it was safe to merge because it wouldn't just break for users that don't use nix. Can we just add layout python3 to a .envrc on the repo itself? I have added it to a nested .envrc under bindings/python. Tell me if that works :)

@thisismiller
Copy link
Contributor

Unfortunately, the layout python3 also needs to be at the top level, because otherwise when you run cargo build at the root of the limbo checkout, cargo won't pick up the .envrc within bindings/python. My impression was that flake and layout python3 are just two different ways of achieving the same thing (with flake doing a superset), and so the two are just in direct conflict.

@haaawk
Copy link
Collaborator

haaawk commented Jan 15, 2025

Wouldn't it make sense to keep this out of the repo? It seems very specific to individual preferences. I don't think commiting tools configs to the repo is a good idea unless usage of that tools is mandatory to all contributors. How are direnv and nix more special than thousands other tools?

@levydsa
Copy link
Contributor Author

levydsa commented Jan 15, 2025

@haaawk, I understand that this looks very specific, but the direnv and nix flakes are very project specific. Having this tools available is just nice to have. We can accommodate the needs of other developers that use, in this case, layout python3.

Having layout python3 in the configuration doesn't affect the nix devshell at all. The project has a Pipfile and a bunch of python scripts for tests (I only saw that now), so it makes total sense to have the environment configured for that.

I've added it to the top level .envrc. @thisismiller, tell me if that works.


# Direnv
.direnv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is no longer needed now, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direnv generates this folder for me. Seems to be a cache of some sort.

@thisismiller
Copy link
Contributor

If use flake and layout python3 aren't conflicting for you, then yes, this makes it no longer conflicting for me. Thanks!

To haaawk's point, I'm still not sure that it's good to specify one canonical .envrc that should work for everyone, as someone might show up in the future complaining that they can't override some cargo env var for limbo or something similar, but we can also figure out what to do when we reach that point.

@levydsa
Copy link
Contributor Author

levydsa commented Jan 16, 2025

It works for me :) Thanks for showing that feature, I didn't knew about it.

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.

4 participants