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

Direnv support #322650

Merged
merged 1 commit into from
Jul 8, 2024
Merged

Direnv support #322650

merged 1 commit into from
Jul 8, 2024

Conversation

infinisil
Copy link
Member

@infinisil infinisil commented Jun 26, 2024

Description of changes

Split off from #322512, since there's a bunch of discussion just about direnv.

This creates a .envrc, so that if you have https://direnv.net/ installed, the shell.nix is loaded automatically.

Ping @Frontear @mweinelt @peterhoeg

Things done


Add a 👍 reaction to pull requests you find important.

@infinisil infinisil changed the title Direnv Direnv support Jun 26, 2024
@infinisil
Copy link
Member Author

infinisil commented Jun 26, 2024

Originally posted by @Frontear in #322512 (comment):

Not a fan of a .envrc being added by default. My reason is fairly simple, I like to put my GITHUB_TOKEN for nixpkgs-review --post-result, and I have a global ignore to prevent my nixpkgs fork from seeing it, so that whenever I git add -A any changes, they ignore the .envrc.

Having it default included means its tracked, which means per-user secrets have a chance to end up accidentally in a commit. Sure this is a user error and isn't necessarily nixpkgs responsibility, but I honestly think I'd prefer it being left out and left to the user to create and maintain.


Originally posted by @infinisil in #322512 (comment):

@Frontear It's very standard to commit the .envrc file, I don't think it's worth everybody having to add it manually for such edge cases. Here are some workarounds you can use:

  • Unset GITHUB_TOKEN and install the GitHub CLI (pkgs.github-cli) instead, which nixpkgs-review can use to get the token
  • Set the token in ~/.config/direnv/direnvrc instead, which gets loaded before .envrc
  • Use git update-index --assume-unchanged .envrc for Git to never try adding it

Originally posted by @Frontear in #322512 (comment):

I've always believed envrc shouldnt be commited due to it holding environment secrets, unless im conflating the role of .env with .envrc. In any case thats fair that everyone needing to manually make one is tedious.


Originally posted by @peterhoeg in #322512 (comment):

I'm using this pattern all over in .envrc:

for f in .env .env.local .env.secrets; do
  dotenv_if_exists $f
done

And those files are then obviously gitignored.

@Frontear
Copy link
Member

Frontear commented Jun 26, 2024

Wasn't a fan at first but I support the notion of convenience for the nixpkgs community at large. Losing my ability to set secrets in one way (there are alternatives) is a small price to pay for overall convenience.

Of course there can be an argument of opt-in semantics and automatic consent but I was never much of an extreme vocalist for such, nor do I personally care too much, so that argument isn't mine to make.

👍 for implementation!

@@ -0,0 +1 @@
use nix
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
use nix
use nix
watch_file .envrc.private
if [[ -f .envrc.private ]]; then
source_env .envrc.private
fi

Copy link
Member

@Mic92 Mic92 Jun 27, 2024

Choose a reason for hiding this comment

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

And in .envrc.private people than can do things like:

export GITHUB_TOKEN=$(rbw get gitlab.com-token)

or whatever they like to also add to their nixpkgs development workflow.

We would than add .envrc.private to .gitignore.

Copy link
Member

Choose a reason for hiding this comment

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

This seems a bit more flexible than restricting the choice to dotenv, where one could only add hardcode static secrets.

Copy link
Member Author

@infinisil infinisil Jun 27, 2024

Choose a reason for hiding this comment

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

The main problem with this seems to be that it doesn't require the user to confirm it if the .envrc.private file changed, see direnv/direnv#348. Especially in Nixpkgs this considerably increases the attack surface, since we run so many update scripts, which could populate .envrc.private file.

Copy link
Member

Choose a reason for hiding this comment

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

How is this different from changing shell.nix to add a shellHook or changing any code in nixpkgs?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess at least the shell.nix is being code owned by the security team, so if somebody does something sketchy they'd be notified. Can't do the same here. Ping @NixOS/security for input

Copy link
Member

@Mic92 Mic92 Jun 27, 2024

Choose a reason for hiding this comment

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

Why not add .envrc.private than as well to the code owner list?

Copy link
Member

Choose a reason for hiding this comment

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

Anyway. Not the hill, I want to die on.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why not add .envrc.private than as well to the code owner list?

Unless I'm missing something, code owners only work when you commit the file to GitHub, which defeats the point of it :P

Anyways, I don't want to say No to this, just that I'm personally not sure about the security impact of it. So I'd say let's go with a more minimal solution without .private for now, which we can then still change in a backwards-compatible way later if necessary.

@infinisil infinisil marked this pull request as ready for review June 29, 2024 22:08
@infinisil infinisil merged commit c941400 into NixOS:master Jul 8, 2024
24 checks passed
@infinisil infinisil deleted the direnv branch July 8, 2024 17:25
@toastal toastal mentioned this pull request Jul 9, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants