nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.82k stars 1.78k forks source link

bug: Session variables are not set in terminal window when logging into Wayland session, but are enabled with Xorg #3100

Open schuelermine opened 2 years ago

schuelermine commented 2 years ago

Is there an existing issue for this?

Issue description

When setting a session variable such as $EDITOR via home.sessionVariables, the variables are loaded in Xorg, but not in Wayland.

I am choosing the session via GDM.
My terminal is kitty.
My shell is nushell.

My home-manager configuration: https://github.com/schuelermine/home-manager-configuration
I have since switched to systemd.user.sessionVariables. The last commit to use home.sessionVariables is 557de379dd0eb144cae5833efc2ad22d43b875bc.

My system configuration: https://github.com/schuelermine/nixos-configuration

Maintainer CC

No response

System information

- system: `"x86_64-linux"`
 - host os: `Linux 5.18.10, NixOS, 22.11 (Raccoon), 22.11.20220712.68c63e6`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.9.1`
 - channels(root): `"nixos, nixpkgs"`
 - channels(anselmschueler): `""`
 - nixpkgs: `/nix/store/ia11pz7v8wag5gh54bbnl5c87qc9cjm7-source`
jflanglois commented 2 years ago

I've been debugging this a bit and the culprit for my case (no access to coreutils in fishline plugin) is https://github.com/nix-community/home-manager/pull/3031. I'm not sure what the right solution is to this. @oxalica thoughts?

edit: maybe I'm wrong... I use greetd and Sway, so this may not be the cause for you.

oxalica commented 2 years ago

I've been debugging this a bit and the culprit for my case (no access to coreutils in fishline plugin) is https://github.com/nix-community/home-manager/pull/3031

Seems unrelated to this one. But generally systemd environment is unrelated to session environment. The former is for isolated systemd services (no env vars, by default), and the latter is for user interaction (PATH, EDITOR, LESS and etc).

@schuelermine Could you try switching to bash as login shell? My friends also have some env var issues with fish as login shell.

schuelermine commented 2 years ago

I tried to recreate the problem but I couldn’t.

archer-65 commented 2 years ago

Same problem with SDDM and Sway, any ideas?

stale[bot] commented 1 year ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

nevivurn commented 1 year ago

I think I'm experiencing the same issue.

I am using sway and foot (in server mode), and start sway with [[ "$(tty)" == /dev/tty1 ]] && sway in ~/.profile. ssh-agent and such stopped working in terminal sessions after switching to 22.11.

The problem is fixed for a particular terminal session when I source ~/.profile which eventually sources /etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh.

Prior to #3031, sway was importing all of those variables to systemd and so these variables were available to each terminal session.

I think this could be fixed by sourcing hm-session-vars.sh from .bashrc or something, but is that the proper way to fix this?

I don't know much about how systemd env vars affect each session, but I tested running systemctl --user import-environment something, restarting systemctl --user restart foot.service, and the something variable was set in the terminal session.

ryan4yin commented 1 year ago

Same problem here, When logging into Wayland, I can read all environment variables in bash(such as EDITOR SSH_AUTH_SOCK), but nothing in nushell.


Since my bash shell works fine, currently I fixed this problem by running nushell via bash: https://github.com/ryan4yin/nix-config/pull/27

SamueleFacenda commented 1 year ago

I have the same problem with wayland (gnome) and zsh (with xorg everything works fine). I made some research, /etc/profiles/per-user/samu/etc/profile.d/hm-session-vars.sh is sourced in .zshenv, I checked and .zshenv is executed every time, and so is hm-session-vars.sh. But the variables aren't set, I think that the if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi at the beginning of hm-session-vars.sh is triggered, but why? $__HM_SESS_VARS_SOURCED should be empty in a new session (and it is with xorg), but with wayland something is different, I don't know why. Sourcing hm-session-vars.sh in .zshrc or something is not a solution anyway (for me). Edit: I have to reboot the system in order to update them.

farnoy commented 1 year ago

I have a similar problem with nested shells when using vscode remote ssh. My understanding is that it spawns its server process through SSH using bash or some other shell, invokes the global /etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh which exports __HM_SESS_VARS_SOURCED=1. Then, when I use the integrated terminal, it spawns a subprocess with fish as my shell of choice.

Fish then runs part of the initialisation, but Home Manager's init scripts are checking __HM_SESS_VARS_SOURCED first , while /etc/set-environment only sets, but does not check for __NIXOS_SET_ENVIRONMENT_DONE=1. In effect, those coarse variables defined through config.environment.variables, like the mkDefault EDITOR=nano are overwriting my home-manager specific ones.

I think that either HM should align with NixOS and remove the branch, or we should have a similar branch in /etc/set-environment so it won't set things twice in nested shells.

profiluefter commented 1 year ago

Hi, I have had the same problem using SDDM for a long time now and have followed this issue. Yesterday I found this issue which explained that there's something different in SDDM 0.20.0 (currently NixOS unstable) than 0.19.0 (NixOS 23.05).

After creating an overlay which uses the unstable package in my configuration it now correctly loads the env variables! I'm not quite sure what exactly is happening as for my eyes it should also work with the implementation from 0.19.0 but I'm happy that I've found a fix/workaround for the time being.

hpfr commented 8 months ago

This seems to be a duplicate of https://github.com/nix-community/home-manager/issues/2659