dirs-dev / directories-rs

a mid-level library that provides config/cache/data paths, following the respective conventions on Linux, macOS and Windows
https://dirs.dev
Apache License 2.0
748 stars 33 forks source link

feature request: recognise systemd environment variable for systemd services #78

Open symphorien opened 1 year ago

symphorien commented 1 year ago

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

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 │
           └────────────────────────┴────────────────┴───────────────────────┴──────────────────────────┘
asasine commented 6 months ago

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

andrewbaxter commented 1 month ago

These are all related: #87 #82 #58