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

session's $PATH does not include nix-profile or cfg.sessionPath anymore #1999

Closed
xvello opened this issue May 11, 2021 · 12 comments
Closed

session's $PATH does not include nix-profile or cfg.sessionPath anymore #1999

xvello opened this issue May 11, 2021 · 12 comments
Assignees

Comments

@xvello
Copy link

xvello commented May 11, 2021

Issue description

After upgrading home-manager today, the xsession $PATH does not include the right folders anymore. I am running KDE Neon (with a Ubuntu 20.04 system base).

Although interactive shells have the right path, plasmashell and krunner cannot start applications installed via home-manager, as their $PATH is incorrect.

Logs from ~/.xsession-errors:

Before (correct, includes ~/.nix-profile/bin and my custom ~/.config/nixpkgs/bin from cfg.sessionPath):

dbus-update-activation-environment: setting PATH=/home/xavier/.nix-profile/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/xavier/.config/nixpkgs/bin

After (incorrect):

dbus-update-activation-environment: setting PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Possible cause

I suspect a regression has been introduced by #1797, as my hm-session-vars.sh got this new line at the end:

export $(/nix/store/bmvjq883zj2vxgynl8p47za39lrg0ypi-systemd-247.6/lib/systemd/user-environment-generators/30-systemd-environment-d-generator)

Running this script on my system resets $PATH to the hardcoded initial list matching my distribution's /etc/environment file:

$ /nix/store/bmvjq883zj2vxgynl8p47za39lrg0ypi-systemd-247.6/lib/systemd/user-environment-generators/30-systemd-environment-d-generator
LOCALE_ARCHIVE_2_27=/nix/store/7dz31dq4n1r0wqq3r28r7975cql68n8w-glibc-locales-2.32-40/lib/locale/locale-archive
NIX_PATH=/home/xavier/.nix-defexpr/channels:/home/xavier/.nix-defexpr/channels:/home/xavier/.nix-defexpr/channels
QT_ACCESSIBILITY=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

Maintainer CC

@tadfisher author of #1797
@berbiche who reviewed and merged

Is it intentional to call 30-systemd-environment-d-generator at the very end, or would it make sense to call it earlier, so that cfg.sessionVariables and cfg.sessionPath can still override it?

As sourcing the nix PATH is also done in sessionVariablesExtra, ordering them correctly might prove tricky.

Technical details

$ nix-shell -p nix-info --run "nix-info -m"
these paths will be fetched (0.00 MiB download, 0.00 MiB unpacked):
  /nix/store/rcw3a87m7jycgr6hfbg6zrnr3fj6wg20-nix-info
copying path '/nix/store/rcw3a87m7jycgr6hfbg6zrnr3fj6wg20-nix-info' from 'https://cache.nixos.org'...
 - system: `"x86_64-linux"`
 - host os: `Linux 5.8.0-50-generic, KDE neon, 5.21`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.10`
 - channels(xavier): `"home-manager, nixpkgs-21.05pre288317.357e6b3560f"`
 - nixpkgs: `/home/xavier/.nix-defexpr/channels/nixpkgs`
@sumnerevans sumnerevans assigned berbiche and unassigned berbiche May 11, 2021
@tadfisher
Copy link
Contributor

Maybe systemctl import-environment could be called before that line? I'll test it out.

@rycee
Copy link
Member

rycee commented May 11, 2021

I don't understand the purpose of the

export $(/nix/store/…-systemd-247.6/lib/systemd/user-environment-generators/30-systemd-environment-d-generator)

line. Why is it necessary?

Edit: Looking at it a bit more I don't think calling 30-systemd-environment-d-generator to set up the user login shell is a good idea. It seems like it can overwrite expected variables and introduce unexpected variables. Wouldn't it be easier to simply assign to home.sessionVariables?

@tadfisher
Copy link
Contributor

tadfisher commented May 11, 2021

@rycee This was added specifically as a universal mechanism to configure XDG system directory variables (XDG_DATA_DIR, XDG_CONFIG_DIR) while having them available in both the systemd user session and login shells. The background of this is this issue requesting support for Gnome Shell extension configuration. This works fine as-is on NixOS, because nothing is setting PATH in environment.d, but it looks like Ubuntu does. Personally I would prefer to use the system's mechanism of setting PATH for user sessions, which is environment.d for Ubuntu, but this configuration is non-obvious, so I would be fine with reverting #1797 in favor of a more targeted solution.

@xvello Can you check these directories on your system for a config file that sets PATH? (Nevermind, I see that Ubuntu defines /etc/environment.)

You should be able to override it with systemd.user.sessionVariables.PATH.

@ony
Copy link

ony commented May 12, 2021

I would expect that systemd-environment-d-generator mostly used to populate environment from scratch like user service environment where newly started process have no environment to inherit it from. Hence, I expect plain assignments being used often.

I also expect that if intention of environment.d was to set also variables for user shell, then it will be run alongside with other environment generators during login procedure via something like pam_systemd. And if it is not happening, then maybe split between user session and user services is intended. I think decision about changing that might require more thoughts and not necessary should block exposing some XDG variables to services 😉 .

P.S. systemctl import-environment will not work since generator is called rather than systemctl show-environment to obtain values. And yes, user started services will be sensitive to that import (which might be unwanted) while shell session set up will not.

@terlar
Copy link
Contributor

terlar commented May 13, 2021

I agree that if we do decide to revert, let’s keep the XDG variables parts and only get rid of the 30-systemd-environment-d-generator part.

@berbiche
Copy link
Member

@tadfisher instead of reverting everything, would it be enough to revert only what @terlar suggested?

@rycee
Copy link
Member

rycee commented May 14, 2021

Yes, please do that. In principle perhaps systemd-environment-d-generator is OK to use in the user session but I think it needs to be done after careful consideration.

@xvello
Copy link
Author

xvello commented May 16, 2021

@tadfisher do have the bandwidth to re-scope #2001 to just the 30-systemd-environment-d-generator part, or do you want me to open a PR to do so?

My current workaround on ubuntu is to comment out the PATH export from /etc/environment, but it's very hacky.

@tadfisher
Copy link
Contributor

I've udpated #2001 to revert the usage of 30-systemd-environment-d-generator. xdg.systemDirs now also exports its variables via home.sessionVariables to achieve the same effect.

@berbiche
Copy link
Member

#2001 was merged. Is there anything else that needs to be done?

@xvello
Copy link
Author

xvello commented May 18, 2021

Works good now, my PATH has all expected elements in the right order. Thanks!

@d12frosted
Copy link

d12frosted commented May 19, 2021

When using fish as user shell my PATH is still in the incorrect order:

$ echo $PATH
/usr/local/bin /usr/bin /bin /usr/sbin /sbin /opt/X11/bin /Library/Apple/usr/bin /usr/local/MacGPG2/bin /Library/TeX/texbin /Users/d12frosted/.nix-profile/bin /run/current-system/sw/bin /nix/var/nix/profiles/default/bin

Notice that /usr/bin comes before .nix-profile/bin, which shadows coreutils.

When I change my shell to bash everything seems fine (except for duplicating entries):

$ echo $PATH
/Users/d12frosted/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/MacGPG2/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/d12frosted/.nix-profile/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin

I am installing home-manager via flake and my current commit is 6a471f1, which is the first child of 01ec2aa.

Any suggestions?

P. S. Since my PATH contains several strange entries (I am switching from homebrew to nix) it might be that it's just my local issue with old fish configs, though I completely wiped ~/.config/fish in favour of home-manager generated one.

Update: turns out to be LnL7/nix-darwin#122

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

No branches or pull requests

7 participants