Environment Variables and brew services
#6196
Unanswered
robsdudeson
asked this question in
Everyday usage
Replies: 1 comment 1 reply
-
I struggle with a similar scenario: I want to configure env vars or command line options for |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Output of
brew config
Output of
brew doctor
Description of issue
Question
I'm curious if others would find it reasonable or useful to have an optional way for
brew services
to specify environment variables that all tools run bybrew services
would pick up and use when running.Proposal
Use a new env var
HOMEBREW_SERVICES_ENV_FILE
with a default ofHOMEBREW_USER_CONFIG_HOME/.env
This
.env
file would contain a list of environment variables that the user would want exported to services run via homebrew.Each environment variable could have a static value set similar to bash syntax (i.e.
VAR='some value'
) or just declared as the variable symbol and resolved to the running shell's value. (i.e.VAR
)These environment variables would then either need to be appended to the
.plist
definitions of each service or set vialaunchctl setenv
prior to running/starting homebrew services.Context
I'm a heavy user of the XDG Spec for home directory organization and specify the respective
XDG_*
environment vars on my Mac so tools that support it will respect them.I found that the colima service created
~/.colima
when running viabrew services
despite my setting of the appropriateXDG_CONFIG_HOME
. This was surprising to me because launching the tool via a terminal created a directory at the expected location (~/.config/colima
).Root Cause
This prompted a deep dive into what was going on. I determined the root cause of this to be that
launchd
does not run a login shell and therefore does not know about my custom definitions in.bash_profile
,.zprofile
, etc.I found that
launchd
provides a couple of ways to deal with this...EnvironmentVariables
dictionary in the service.plist
filelaunchctl setenv
prior to running the service.Pitfalls
Both of these have pitfalls with respect to homebrew managed services.
Option 1 has the issue that when issuing
brew services restart <service>
the.plist
file is regenerated to the maintainer's version, wiping out any customizations I made.Option 2 has the issue that
launchctl setenv
must be re-run after a reboot and there is no simple way, within the context oflaunchd
/launchctl
, to ensure that they are set before running other services.Beta Was this translation helpful? Give feedback.
All reactions