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

NixOS and home-manager does not update session variables in Wayland + GNOME until reboot #755

Closed
kachick opened this issue Aug 19, 2024 · 15 comments · Fixed by #891
Closed
Labels
help wanted Extra attention is needed

Comments

@kachick
Copy link
Owner

kachick commented Aug 19, 2024

Often occurred, latest is f042b85

nix-community/home-manager#1011

After rebooting(relogin?) fixed, but it is annoy (Now my NixOS requires to be rebooted many times than Windows...)

@kachick kachick added the bug Something isn't working label Aug 19, 2024
@kachick kachick changed the title home-manager does not update session variables in terminals on NixOS and GNOME NixOS and home-manager does not update session variables in GNOME Oct 1, 2024
@kachick
Copy link
Owner Author

kachick commented Oct 2, 2024

💭 What is the different of variables and sessionVariables?

https://nixos.wiki/wiki/Environment_variables

@kachick kachick added help wanted Extra attention is needed and removed bug Something isn't working labels Oct 20, 2024
@kachick kachick changed the title NixOS and home-manager does not update session variables in GNOME NixOS and home-manager does not update session variables in Wayland + GNOME Oct 20, 2024
@kachick
Copy link
Owner Author

kachick commented Oct 20, 2024

@kachick
Copy link
Owner Author

kachick commented Oct 22, 2024

pkill and re-login does not fix

pkill -SIGQUIT gnome-shell
pkill -SIGQUIT gdm

nix-community/home-manager#3100

@kachick
Copy link
Owner Author

kachick commented Oct 22, 2024

systemctl restart display-manager

also does not resolve

kachick added a commit that referenced this issue Oct 22, 2024
* Implement `envs` command to make easier debugging GH-755 and developing GH-853

* Rewrite the command with ruby, the pipeline_w much helps for daily use. So closes GH-825 for now
@kachick
Copy link
Owner Author

kachick commented Oct 23, 2024

This is much frustrated when I was struggling with #886

@kachick kachick changed the title NixOS and home-manager does not update session variables in Wayland + GNOME NixOS and home-manager does not update session variables in Wayland + GNOME until reboot Oct 23, 2024
@kachick
Copy link
Owner Author

kachick commented Oct 27, 2024

https://wiki.archlinux.org/title/Environment_variables#Per_Wayland_session
https://wiki.archlinux.org/title/Systemd/User#Environment_variables

Units started by user instance of systemd do not inherit any of the [environment variables](https://wiki.archlinux.org/title/Environment_variables) set in places like .bashrc etc. There are several ways to set environment variables for them:

    For users with a $HOME directory, create a .conf file in the ~/.config/environment.d/ directory with lines of the form NAME=VAL. Affects only that user's user unit. See [environment.d(5)](https://man.archlinux.org/man/environment.d.5) for more information.
    Use the DefaultEnvironment option in /etc/systemd/user.conf file. Affects all user units.
    Add a drop-in configuration file in /etc/systemd/system/[email protected]/, see [#Service example](https://wiki.archlinux.org/title/Systemd/User#Service_example)
    Add a drop-in configuration file in /etc/systemd/system/[email protected]/ (affects all users), see [#Service example](https://wiki.archlinux.org/title/Systemd/User#Service_example)
    At any time, use systemctl --user set-environment or systemctl --user import-environment. Affects all user units started after setting the environment variables, but not the units that were already running.
    Using the dbus-update-activation-environment --systemd --all command provided by [dbus](https://wiki.archlinux.org/title/Dbus). Has the same effect as systemctl --user import-environment, but also affects the D-Bus session. You can add this to the end of your shell initialization file.
    For "global" environment variables for the user environment you can use the environment.d directories which are parsed by some generators. See [environment.d(5)](https://man.archlinux.org/man/environment.d.5) and [systemd.generator(7)](https://man.archlinux.org/man/systemd.generator.7) for more information.
    You can also write a [systemd.environment-generator(7)](https://man.archlinux.org/man/systemd.environment-generator.7) script which can produce environment variables that vary from user to user, this is probably the best way if you need per-user environments (this is the case for XDG_RUNTIME_DIR, DBUS_SESSION_BUS_ADDRESS, etc).

One variable you may want to set is PATH.

After configuration, the command systemctl --user show-environment can be used to verify that the values are correct. You may need to run systemctl --user daemon-reload for changes to take effect immediately.

Updating ~/.config/environment.d/ with home.systemd.user.sessionVariables does not fix it

> la ~/.config/environment.d
0777 - 10-27 19:46 10-home-manager.conf -> /nix/store/pj4adacv53hzjdriai3120il8iy1sppv-home-manager-files/.config/environment.d/10-home-manager.conf

@kachick
Copy link
Owner Author

kachick commented Oct 27, 2024

@kachick
Copy link
Owner Author

kachick commented Oct 27, 2024

@kachick
Copy link
Owner Author

kachick commented Oct 27, 2024

@kachick
Copy link
Owner Author

kachick commented Oct 27, 2024

> bat /home/kachick/.nix-profile/etc/profile.d/hm-session-vars.sh
# Only source this once.
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1
 
export EDITOR="/nix/store/h0cn28h7mvkj1vwbdj4zkzkailkwr1i0-helix-24.03/bin/hx"

> echo $__HM_SESS_VARS_SOURCED
1

🤔

@kachick
Copy link
Owner Author

kachick commented Oct 27, 2024

Might be related to #680?

@kachick
Copy link
Owner Author

kachick commented Oct 27, 2024

https://unix.stackexchange.com/questions/2745/how-to-run-a-script-during-gnome-log-out

> lat /etc/gdm             
0755 - 10-27 20:21 /etc/gdm
0755 - 10-27 20:21 ├── PostLogin
0777 - 10-27 20:21 │  └── Default -> /etc/static/gdm/PostLogin/Default
0777 - 10-27 20:21 ├── Xsession -> /etc/static/gdm/Xsession
0777 - 10-27 20:21 └── custom.conf -> /etc/static/gdm/custom.conf

kachick added a commit that referenced this issue Oct 27, 2024
This does not help GH-755 for now.
Mostly for UI looks
kachick added a commit that referenced this issue Oct 27, 2024
@kachick
Copy link
Owner Author

kachick commented Oct 27, 2024

@kachick
Copy link
Owner Author

kachick commented Oct 27, 2024

❄️ ~ zsh 1
> cdnix gnome-session    

❄️ /nix/store/9zkcrgjd42wv2ir2bnkfwkg8ms33nbbd-gnome-session-46.0🔒 zsh 
> bat bin/gnome-session
#!/nix/store/516kai7nl5dxr792c0nzq0jp8m4zvxpi-bash-5.2p32/bin/sh
 
if [ "x$XDG_SESSION_TYPE" = "xwayland" ] &&
   [ "x$XDG_SESSION_CLASS" != "xgreeter" ] &&
   [  -n "$SHELL" ] &&
   grep -q "$SHELL" /etc/shells &&
   ! (echo "$SHELL" | grep -q "false") &&
   ! (echo "$SHELL" | grep -q "nologin"); then
  if [ "$1" != '-l' ]; then
    # Make sure the shell actually sets up the environment.
    unset __NIXOS_SET_ENVIRONMENT_DONE
    exec /nix/store/516kai7nl5dxr792c0nzq0jp8m4zvxpi-bash-5.2p32/bin/bash -c "exec -l '$SH
ELL' -c '$0 -l $*'"
  else
    shift
  fi
fi
 
SETTING=$(G_MESSAGES_DEBUG='' /nix/store/v6rxay5qhjr4s8dzcb3sr9n0m7kms07g-glib-2.80.2-bin/
bin/gsettings get org.gnome.system.locale region)
REGION=${SETTING#\'}
REGION=${REGION%\'}
 
if [ -n "$REGION" ]; then
  unset LC_TIME LC_NUMERIC LC_MONETARY LC_MEASUREMENT LC_PAPER
 
  if [ "$LANG" != "$REGION" ] ; then
    # LC_CTYPE
    export LC_NUMERIC=$REGION
    export LC_TIME=$REGION
    # LC_COLLATE
    export LC_MONETARY=$REGION
    # LC_MESSAGES
    export LC_PAPER=$REGION
    # LC_NAME
    export LC_ADDRESS=$REGION
    export LC_TELEPHONE=$REGION
    export LC_MEASUREMENT=$REGION
    # LC_IDENTIFICATION
  fi
fi
 
exec /nix/store/9zkcrgjd42wv2ir2bnkfwkg8ms33nbbd-gnome-session-46.0/libexec/gnome-session-
binary "$@"

@kachick
Copy link
Owner Author

kachick commented Oct 27, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant