nushell: load session environment at runtime - #9666
Open
LisaScheers wants to merge 1 commit into
Open
Conversation
LisaScheers
force-pushed
the
agent/nushell-session-environment
branch
from
July 16, 2026 04:17
79ac1f5 to
fa1d942
Compare
Source the OS and Home Manager POSIX environment scripts when Nushell starts so runtime HOME and USER expansions and profile paths match managed POSIX shells.
LisaScheers
force-pushed
the
agent/nushell-session-environment
branch
from
July 16, 2026 04:18
fa1d942 to
460b87c
Compare
LisaScheers
marked this pull request as ready for review
July 16, 2026 04:21
Contributor
|
Note that this PR still doesn't you to seamlessly set nushell as the login shell on macOS if you want the config to be stored in XDG directories. If |
Author
|
the real solution is to let the xdg module write a plist with something like <!-- ~/Library/LaunchAgents/setenv.XDG_CONFIG_HOME.plist -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>setenv.XDG_CONFIG_HOME</string>
<key>ProgramArguments</key>
<array>
<string>/bin/launchctl</string>
<string>setenv</string>
<string>XDG_CONFIG_HOME</string>
<string>{USER_HOME}/.config</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>to this would set it for all applications |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
env.nuloader when a system or Home Manager sessionenvironment needs to be applied.
setEnvironmentscript when Home Manager is used as a NixOS or nix-darwin module, followed byhm-session-vars.sh.PATHas alist<string>.envFile/extraEnv, so inherited or user-specific values keep their expected precedence.env.nuownership and migration path in the 26.11 releasenotes.
Why
Nushell does not source the POSIX environment scripts used by Bash and Zsh. As a result, a directly launched Nushell login shell can miss the Nix profile
PATH, Home Manager session variables, and expansions involving runtime values such as$HOMEand$USER.Evaluating these scripts at build time captures sandbox values instead of the user's login environment. This implementation evaluates them at shell startup and transfers the resulting environment through a NUL-delimited representation, which also handles values containing newlines.
This builds on the investigation and experiments in #6941 while avoiding its sandbox-environment limitation.
User impact
Nushell can be launched directly instead of through Zsh or Bash while receiving the system and Home Manager environment.
home.sessionVariables,home.sessionPath, POSIX default/alternate expansions, and NixOS/nix-darwin profile paths are applied consistently.Fixes #4313
Fixes #4918
Fixes #6507
Addresses #6568
Fixes #6901
Validation
$HOME/$USERexpansion, POSIX default/alternate expansion,home.sessionPath, list-formPATH, and userenv.nuprecedence.nix build .#test-all.aarch64-darwin.x86_64-linux.nix build .#docs-html.git diff --check.