How to set up desktop environment per user

I want to add a guest user to my desktop, but want to set up my guest account to use plasma ( I use i3 and my guest is used to a full desktop environment ).

Is there a way I can set this up to be the default on their user account, but keep my default to be just i3?

Relevant X11 section:

  # X11             
  services.xserver = {                               
    enable = true;                    
    layout = "us";    
                                             
    displayManager.sddm.enable = true;            
    desktopManager.default = "none";    
                                                                      
    windowManager.default = "i3";                                     
    windowManager.i3.enable = true;                                   
  };                                                                  
  • Ideally I’d like this to be agnostic of the displayManager, since I want to move away from sddm?
3 Likes

Hi @epigramengineer

I had somehow the same problem :slight_smile: (gnome vs i3)

This is what works for me:

  1. Use home-manager
  2. Inside home-manager user-specific config, define xsession entry where you can pass windowManager.commad:

This will create .xsession in your home dir with appropriate xsession startup command (either i3 or whatever else).

Important: do not enable your desktopManager globally via services.xserver.desktopManager.gnome.enable = true.

In my case it works.

1 Like

I tried this technique with gdm with both gnome and plasma enabled, but it had no effect.

i was able to overide the system default (which was plasma instead of gnome) with:

services.displayManager.defaultSession = "gnome-xorg";

but i didn’t manage to find a way to overide that for a specific user.

what it did do was to set the system default for the little gear menu on the login screen.

in my case it was one of: [ “gnome” “gnome-xorg” “plasma” “plasmawayland” ]
if you have other DMs installed you can get this list with
nix eval .#nixosConfigurations.$NIXOS_INTERNAL_HOSTNAME.config.services.xserver.displayManager.sessionData.sessionNames

I found this answer on superuser:

.dmrc file is no longer used.

To specify a default session for a user,
update the user’s account service in the /var/lib/AccountsService/users/username

trying to set this up with a semi-declarative editable dotfile

system.activationScripts.defaultSessionPerUserHack.text = ''
    if [[ ! -h "/home/$username/.config/.AccountsService" ]]; then
      ln -s "/home/$username/.config/.AccountsService" "/var/lib/AccountsService/users/$username"
    fi
  '';

restarting now after rebuild switch… lets see if it works

so the rebuild switch worked and the symlink was there, and i also tried to cp the file but it seems to get overriden by wherever this is set: services.displayManager.defaultSession

interesting to note, it seems to be patching the file and only XSession is changed:

[User]
Session=plasma
SessionType=x11
XSession=gnome-xorg
Icon=/home/$user/.face
SystemAccount=false

both were set to plasma in my user file and the menu showed gnome-xorg which was overridden during the boot process somewhen

found an interesting comment in gdm:
# Set default session in session chooser to a specified values – basically ignore session history.

gdm calls a python script which must be overwriting or patching the file
/var/lib/AccountsService/users/username

I found a (almost) decent way to do this:

  # copy AccountsService Settings
  system.activationScripts.defaultSessionPerUserHack.text = ''
    cp "${./accountsService.ini}" "/var/lib/AccountsService/users/${username}"
  '';

  services.displayManager = {
    preStart = lib.mkForce "";
  };

the override of preStart feels rather ugly, but otherwise the service will patch the users file in
/var/lib/AccountsService/users/
and trump the chosen value with what is set via
services.displayManager.defaultSession

@jtojnar (github handle from 5 year old commit) seemed to consciously want to override other ways of setting up these user prefs.

Maybe a home-manager config could be possible one fine day.

anyone know a more elegant way to do this?

There is no per-user setting in GDM. There is not even a global one – GDM uses the last session used by the user as recorded by AccountsService, so we run a script that tells AccountsService to change the last session when defaultSession is set.

It should be possible to add per-user options and update the set-session.py script to support that. Pull requests welcome.

Then do not set services.displayManager.defaultSession.

/var/lib/AccountsService is out of scope of home-manager. You can use systemd.tmpfiles.rules NixOS option to create files anywhere on the system.