services: Fix missing environment variables for user services

We add an additional 'core' user service (i.e. one that gets loaded
before all others by turnstile) which populates the TURNSTILE_ENV_DIR
with all manner of custom set env vars that are important for other
applications.

Most importantly, this sets up the XDG directory compliance for
applications either managed by turnstile or applications started through
turnstile on my system. So, for example `pass` knows to search for its
database in `XDG_DATA_HOME` and river knows to search for binaries in a
PATH which has been prefixed with my custom user binary location.
This commit is contained in:
Marty Oehme 2025-02-26 15:37:28 +01:00
parent 5f6627e7e7
commit 2e9701ea26
Signed by: Marty
GPG key ID: 4E535BC19C61886E
6 changed files with 36 additions and 12 deletions

29
services/sv/loadenv/run Executable file
View file

@ -0,0 +1,29 @@
#!/bin/sh
# Loadenv service ensures turstile environment gets populated with all
# profile-loaded environment variables.
#
# To use this service with other turnstile user services, ensure it gets
# started before anything else is started by putting it into `turnstile-ready`
# service conf as a core service.
#
# Will also load the profile file from a custom XDG-compliant
# ~/.config/sh/profile directory before falling back to the home directory
# ~/.profile file.
# This location can be manually overriden by putting the following into the
# service conf file:
# XDG_PROFILE=/my/location/somewhere/profile
[ -r ./conf ] && . ./conf
if [ -e "$HOME/.config/sh/profile" ]; then
XDG_PROFILE="${XDG_PROFILE:-HOME/.config/sh/profile}"
fi
ENV=${XDG_PROFILE:-$HOME/.profile} sh -i -c env | while IFS= read -r line; do
value=${line#*=}
name=${line%%=*}
echo "$value" > "$TURNSTILE_ENV_DIR/$name"
done
exec 2>&1
exec pause