directories-rs icon indicating copy to clipboard operation
directories-rs copied to clipboard

feature request: recognise systemd environment variable for systemd services

Open symphorien opened this issue 2 years ago • 2 comments

I would like to write an app which can be run both

  • in the terminal as a normal user, writing its cache to XDG_CACHE_HOME
  • as a systemd service as a system user, and then write its cache to /var/cache/ in a directory prepared by systemd with CacheDirectory=<progname>.

In the second case, systemd sets the CACHE_DIRECTORY env var, and directories-rs could recognize that.

This also applies for other directories than cache: from man systemd.exec:

           Table 2. Automatic directory creation and environment variables
           ┌────────────────────────┬────────────────┬───────────────────────┬──────────────────────────┐
           │Directory               │ Below path for │ Below path for user   │ Environment              │
           │                        │ system units   │ units                 │ variable set             │
           ├────────────────────────┼────────────────┼───────────────────────┼──────────────────────────┤
           │RuntimeDirectory=       │ /run/          │ $XDG_RUNTIME_DIR      │ $RUNTIME_DIRECTORY       │
           ├────────────────────────┼────────────────┼───────────────────────┼──────────────────────────┤
           │StateDirectory=         │ /var/lib/      │ $XDG_CONFIG_HOME      │ $STATE_DIRECTORY         │
           ├────────────────────────┼────────────────┼───────────────────────┼──────────────────────────┤
           │CacheDirectory=         │ /var/cache/    │ $XDG_CACHE_HOME       │ $CACHE_DIRECTORY         │
           ├────────────────────────┼────────────────┼───────────────────────┼──────────────────────────┤
           │LogsDirectory=          │ /var/log/      │ $XDG_CONFIG_HOME/log/ │ $LOGS_DIRECTORY          │
           ├────────────────────────┼────────────────┼───────────────────────┼──────────────────────────┤
           │ConfigurationDirectory= │ /etc/          │ $XDG_CONFIG_HOME      │ $CONFIGURATION_DIRECTORY │
           └────────────────────────┴────────────────┴───────────────────────┴──────────────────────────┘

symphorien avatar Jan 22 '23 13:01 symphorien

I've created the systemd-directories crate that does just this.

asasine avatar Feb 17 '24 20:02 asasine

These are all related: #87 #82 #58

andrewbaxter avatar Jul 19 '24 12:07 andrewbaxter