tt icon indicating copy to clipboard operation
tt copied to clipboard

Export environment from service

Open danyspin97 opened this issue 5 years ago • 0 comments

Some daemons export configuration variables into the environment. I think it could be useful to provide support for this use-case into the configuration. An example could be SWAYSOCK variable exported by sway that is needed by all wayland related daemons, like Waybar and mako.

I propose to add:

  • an export array in the options section to list all the environment to read once the service is started
  • an import array in the options section to list all the service to import the environment from

Example:

sway.user:

[main]
name = sway
description = ...
type = longrun

[run]
build = path
execute = sway

[options]
export =[ SWAYSOCK ]

Waybar.user:

[main]
name = Waybar
description = ...
type = longrun

[run]
build = path
execute = waybar

[options]
import =[ sway ]

/proc/$pid/environ can be used to read the environment as shown here. Knowing the $pid of a service is at the base of the supervision used so it can be assumed that it is correct.

A couple of issues:

  • Some services could want to export some dynamic environment variables to entire service tree of the user. E.g. a service could export all XDG environment variables. (for the static variable a different method should be added)
  • Is reading from /proc/$pid/environ portable?

danyspin97 avatar Nov 06 '20 10:11 danyspin97