apognu / tuigreet

Graphical console greeter for greetd
GNU General Public License v3.0
992 stars 45 forks source link

Run command depending on user #42

Closed rambip closed 3 years ago

rambip commented 3 years ago

I would like to start a graphical session (gnome, sway, xmonad, and so on) depending on the user. I tried to do

--cmd 'sh -c \$START_SESSION_SCRIPT'

But that didn't work.

Since there is no standard way to start a graphical session (except startx but this was created for X), I don't know how to do that.

I know this is not a good issue, but help would be really apreciated.

apognu commented 3 years ago

What you are trying to do (doing shell expansion within the cmd attribute) is not supported, either by tuigreet (for now) or, as far as I know, greetd. Commands are executed as is, without a shell present.

Without any modification in tuigreet, what I would do is execute a global script, /usr/local/bin/start-session for example, that will check the current user and start the appropriate session accordindly (the script will be executed as the just-authenticated user).

Something akin to this:

#!/bin/sh

case "$(whoami)" in
  'apognu')
    sway
    ;;

  'bob')
    uname
    ;;
esac
rambip commented 3 years ago

Thanks, this is really helpfull ! And with nixos I will be able to create the script in my global config, this could be a really nice solution !

Just for curiosity sake, would that work if the content of my file is as follows:

!/bin/sh

source $HOME/.profile
exec $START_SESSION_COMMAND
# START_SESSION_COMMAND is defined in the user config
apognu commented 3 years ago

Absolutely, the session is executed by your user, so $HOME will be defined and you can start a session exactly like that.

What $START_SESSION_COMMAND should do will depend on the program you need to run, obviously, but I'm sure you already have that lying around.

apognu commented 3 years ago

@rambip Did that answer your question?

rambip commented 3 years ago

Yeah thanks a lot ! I just need to dig a bit to know when exactly the user environment variables are set on nixos, and it will be good.