NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.38k stars 14.34k forks source link

Load user's login shell environment for graphical sessions #187191

Open kira-bruneau opened 2 years ago

kira-bruneau commented 2 years ago

Describe the bug

Currently the xsession wrapper is hard-coded to emulate the login shell for sh.

This should be generalized to load the environment for whatever shell the user configured. Similarly to SDDM's default Xsession wrapper script: https://github.com/sddm/sddm/blob/v0.19.0/data/scripts/Xsession#L8-L51

Decoupling bash-specific sourcing from the xsession wrapper could also make it possible to disable bash again: https://github.com/NixOS/nixpkgs/commit/90dac235bb409e5795aa460b34388c455178035c.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Set user's shell to bash users.users.<name>.shell = bash
  2. Add ~/.bash_profile file with exports
  3. ~/.bash_profile will be sourced in a tty login shell, but not a graphical session.

Expected behavior

A graphical session should have the same environment as a tty login for the user's configured shell.

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.19.0, NixOS, 22.11 (Raccoon), 22.11.20220813.65c15b0`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.10.3`
 - nixpkgs: `/nix/store/28fq18g5rbzn29di36pcnaz4qpwdf1r3-source`

@LoveIsGrief

ghost commented 2 years ago

This was actually the next thing I wanted to tackle. I'll make a PR but I have to check if the SHELL variable is set and available if the script is run with sh on NixOS

mhwombat commented 1 year ago

I'm pretty sure something has changed in how NixOS creates users, and I suspect it's related to this issue. In the past, a user.users setting in configuration.nix would result in the user's home directory being created and populated with .bash_profile (among other files) that invokes .bashrc. That was the case about a year or so ago, when I last built my system from scratch. I have never written a .bash_profile on any machine/distro I've used, it (and/or .profile) was always already there.

But I rebuilt my system from scratch again this week, and was very confused when I logged into one of the virtual terminals (e.g. Ctrl+Alt+F1) and none of my aliases were recognised. Eventually I discovered that this file wasn't automatically created.

nixos-discourse commented 1 year ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/bash-not-sourcing-bashrc/22859/9