alebastr / sway-systemd

Systemd integration for Sway session
MIT License
141 stars 12 forks source link

Use systemd-style Environment files to pass variables via session.sh and assign-cgroups.py #27

Open snakeroot opened 10 months ago

snakeroot commented 10 months ago

Another run at #6 .

Would you consider modifying session.sh so that it looks for an "Environment" file in a pre-defined location, and, if the file exists, sources the variables in that file and then adds them to the $VARIABLES list alongside the default variables hardcoded in the script and those passed in via -E?

This has the advantage of leveraging a broadly-used format (i.e, you can crib from people using .profile or /etc/environment.d). It also should mean that the file won't get overwritten when sway-systemd is upgraded (unlike changes to -E in 10-systemd-session.conf).

I stuck this language into my session.sh and, while it's not pretty it does seem to work:

set_var(){
        . ${1}
        while read -r line; do
                if [[ $(echo $line | grep -v ^#) ]]; then
                        line=${line%=*}
                        export ${line}
                        VARIABLES="${VARIABLES} ${line}"
                fi
        done < ${1}
}

if [[ -e ~/.config/sway-systemd/env ]]; then
        set_var ~/.config/sway-systemd/env
fi

Similarly, would it be possible to do something similar for the transient scope units created by assign-cgroups.py? It seems one could parse an Environment file and submit the name/value pairs via the systemd d-bus API's SetEnvironment() method. Since a lot of the commonly-used environment variables are used to persuade GUI programs to use wayland, this might prove useful.

alebastr commented 10 months ago

The static assignment needed for LANG/MOZ_ENABLE_WAYLAND/QT_QPA_PLATFORM/etc... seems to be already solved with environment.d(5), right? What do you want to achieve by parsing environment.d files with another tool and sending the variables to systemd?

There's a finite amount of per-session variables set by a display manager or by a compositor, that need to be injected to systemd dynamically. Most of those are already in the session script, with exception of XCURSOR_* ones that I simply forgot to add.