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

Include some more shell-specific vars, remove nix shell hook #635

Merged
merged 3 commits into from
Feb 15, 2023

Conversation

ipince
Copy link
Contributor

@ipince ipince commented Feb 14, 2023

Summary

Add some more variables that are required for shell: DEVBOX_ vars, a couple hard-coded nix vars, and a few more vars to leak.

Also removes the shell.nix hook, which we no longer need if we're using unified env.

How was it tested?

go tests

@ipince ipince requested a review from savil February 14, 2023 18:01
env[name] = os.Getenv(name)
// Copy over (and overwrite) vars that we explicitly "leak", as well as DEVBOX_ vars.
for _, kv := range os.Environ() {
parts := strings.SplitN(kv, "=", 2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

key, val, found := strings.Cut(kv, "=")
if !found {
    return errors.Errorsf("expected = in kv: %s", kv)
}

}
}

// These variables are only needed for shell, but we include them here in the computed env
// for both shell and run in order to be as identical as possible.
env["NIX_PKGS_ALLOW_UNFREE"] = "1" // Only for shell because we don't expect nix calls within run
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think its good to include, because someone's script may do devbox add for them.

// TODO: add shell-specific vars, including:
// - NIXPKGS_ALLOW_UNFREE=1 (not needed in run because we don't expect nix calls there)
// - __ETC_PROFILE_NIX_SOURCED=1 (not needed in run because we don't expect rc files to try to load nix profiles)
// - HISTFILE (not needed in run because it's non-interactive)
Copy link
Collaborator

Choose a reason for hiding this comment

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

would it be good to maintain somewhere a list of env vars like HISTFILE that are deliberately omitted from devbox run but included in devbox shell?

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe in LeakedVarsForShell with a value of false ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I think looking at shellrc will be good enough for now (there's no other place in which the env can be changed)

@ipince ipince force-pushed the rodrigo/shell-vars branch from 71481b5 to a1de3c8 Compare February 15, 2023 21:06
@ipince ipince merged commit 5c593ec into main Feb 15, 2023
@ipince ipince deleted the rodrigo/shell-vars branch February 15, 2023 21:16
@savil savil mentioned this pull request Feb 22, 2023
savil added a commit that referenced this pull request Feb 23, 2023
## Summary

#635 hid the shell hook from
`shell.nix` behind the unified-env flag (where shell hook is active when
flag is OFF).
So, this PR removes it from `flake.nix`, since flakes depend on
unified-env being turned on.



## How was it tested?

opened `devbox shell` in `examples/testdata/go/go-1.19` project
savil added a commit that referenced this pull request Jun 14, 2024
## Summary

This was introduced in #635 (cc @ipince). I don't think its needed
anymore.
It seems to be used in the
`/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh` script, at
the very top to prevent re-execution:
```
  1 # Only execute this file once per shell.
  2 if [ -n "${__ETC_PROFILE_NIX_SOURCED:-}" ]; then return; fi
  3 __ETC_PROFILE_NIX_SOURCED=1
  4
```
Perhaps it has other use-cases as well? RFC.


From my casual usage of a Devbox binary built with this change, it all
seems to still work fine.



## How was it tested?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants