how can we add devbox global path to nushell?
What problem are you trying to solve?
how does eval "$(devbox global shellenv)" translate for nushell?
What solution would you like?
an example on how to configure devbox global in nushell
Alternatives you've considered
No response
I'm not sure there's a really easy way to translate the script, since nushell expects variables in a different format than what devbox global shellenv exports.
You might want to look into the nu plugin bash_env, which can evaluate a bash environment and then load it into your nushell? The plugin is described here: https://github.com/tesujimath/nu_plugin_bash_env
got it, thanks!
@vtmocanu Hi, were you able to solve this?
I'm also frustrated by this
Hi, I was able to temporarily solve this by putting this snippet into config nu:
Credit for the capture-foreign-env function: https://github.com/NixOS/nix/issues/9813#issuecomment-3240448107
# Returns a record of changed env variables after running a non-nushell script's contents (passed via stdin), e.g. a bash script you want to "source"
def capture-foreign-env [
--shell (-s): string = /bin/sh
# The shell to run the script in
# (has to support '-c' argument and POSIX 'env', 'echo', 'eval' commands)
--arguments (-a): list<string> = []
# Additional command line arguments to pass to the foreign shell
] {
let script_contents = $in;
let env_out = with-env { SCRIPT_TO_SOURCE: $script_contents } {
^$shell ...$arguments -c `
env
echo '<ENV_CAPTURE_EVAL_FENCE>'
eval "$SCRIPT_TO_SOURCE"
echo '<ENV_CAPTURE_EVAL_FENCE>'
env -0 -u _ -u _AST_FEATURES -u SHLVL` # Filter out known changing variables
}
| split row '<ENV_CAPTURE_EVAL_FENCE>'
| {
before: ($in | first | str trim | lines)
after: ($in | last | str trim | split row (char --integer 0))
}
# Unfortunate Assumption:
# No changed env var contains newlines (not cleanly parseable)
$env_out.after
| where { |line| $line not-in $env_out.before } # Only get changed lines
| parse "{key}={value}"
| transpose --header-row --as-record
| if $in == [] { {} } else { $in }
| if ("PATH" in $in) { update PATH { $in | split row :} } else { $in }
}
load-env (open /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh | capture-foreign-env err> /dev/null)
alias refresh-global = load-env (devbox global shellenv --preserve-path-stack -r | capture-foreign-env err> /dev/null)
refresh-global