-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configuring Homebrew with .env
files
#15787
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -68,12 +68,61 @@ then | |||||||||||||
then | ||||||||||||||
HOMEBREW_PREFIX="/usr/local" | ||||||||||||||
fi | ||||||||||||||
unset USR_LOCAL_BREW_FILE_DIRECTORY USR_LOCAL_HOMEBREW_REPOSITORY | ||||||||||||||
fi | ||||||||||||||
|
||||||||||||||
unset BREW_FILE_DIRECTORY | ||||||||||||||
|
||||||||||||||
# If the location of HOMEBREW_LIBRARY changes | ||||||||||||||
# keg_relocate.rb, formula_cellar_checks.rb, and test/global_spec.rb need to change. | ||||||||||||||
HOMEBREW_LIBRARY="${HOMEBREW_REPOSITORY}/Library" | ||||||||||||||
|
||||||||||||||
# Load Homebrew's variable configuration files from disk. | ||||||||||||||
# First, load the system-wide configuration. | ||||||||||||||
if [[ -f "/etc/homebrew/brew.env" ]] | ||||||||||||||
then | ||||||||||||||
unset SYSTEM_ENV_TAKES_PRIORITY | ||||||||||||||
# only load HOMEBREW_*=* lines | ||||||||||||||
SYSTEM_HOMEBREW_ENV="$(grep -E '^HOMEBREW_[A-Z_]+=.*$' "/etc/homebrew/brew.env")" | ||||||||||||||
if [[ -n "${HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY-}" ]] | ||||||||||||||
then | ||||||||||||||
SYSTEM_ENV_TAKES_PRIORITY="1" | ||||||||||||||
else | ||||||||||||||
eval "${SYSTEM_HOMEBREW_ENV}" | ||||||||||||||
fi | ||||||||||||||
fi | ||||||||||||||
|
||||||||||||||
# Next, load the prefix configuration | ||||||||||||||
if [[ -f "${HOMEBREW_PREFIX}/etc/homebrew/brew.env" ]] | ||||||||||||||
then | ||||||||||||||
# only load HOMEBREW_*=* lines | ||||||||||||||
PREFIX_HOMEBREW_ENV="$(grep -E '^HOMEBREW_[A-Z_]+=.*$' "${HOMEBREW_PREFIX}/etc/homebrew/brew.env")" | ||||||||||||||
eval "${PREFIX_HOMEBREW_ENV}" | ||||||||||||||
unset PREFIX_HOMEBREW_ENV | ||||||||||||||
fi | ||||||||||||||
|
||||||||||||||
# Finally, load the user configuration | ||||||||||||||
if [[ -n "${XDG_CONFIG_HOME-}" ]] | ||||||||||||||
then | ||||||||||||||
HOMEBREW_USER_CONFIG_HOME="${XDG_CONFIG_HOME}/homebrew" | ||||||||||||||
Comment on lines
+105
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carlocab Can you explain that? I don't think either should be needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Env filtering:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carlocab We don't rely on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry, I thought this was in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carlocab that behaviour is already present. We don't pass through For an example: $ export XDG_CONFIG_HOME=fish[~/OSS/Homebrew]
$ brew irb
==> Interactive Homebrew Shell
...
brew(main):001:0> ENV["HOMEBREW_USER_CONFIG_HOME"]
=> "fish/homebrew" |
||||||||||||||
else | ||||||||||||||
HOMEBREW_USER_CONFIG_HOME="${HOME}/.homebrew" | ||||||||||||||
fi | ||||||||||||||
if [[ -f "${HOMEBREW_USER_CONFIG_HOME}/brew.env" ]] | ||||||||||||||
then | ||||||||||||||
# only load HOMEBREW_*=* lines | ||||||||||||||
USER_HOMEBREW_ENV="$(grep -E '^HOMEBREW_[A-Z_]+=.*$' "${HOMEBREW_USER_CONFIG_HOME}/brew.env")" | ||||||||||||||
eval "${USER_HOMEBREW_ENV}" | ||||||||||||||
unset USER_HOMEBREW_ENV | ||||||||||||||
fi | ||||||||||||||
|
||||||||||||||
# If the system configuration takes priority, load it last. | ||||||||||||||
if [[ -n "${SYSTEM_ENV_TAKES_PRIORITY-}" ]] | ||||||||||||||
then | ||||||||||||||
eval "${SYSTEM_HOMEBREW_ENV}" | ||||||||||||||
fi | ||||||||||||||
unset SYSTEM_HOMEBREW_ENV | ||||||||||||||
|
||||||||||||||
# Copy and export all HOMEBREW_* variables previously mentioned in | ||||||||||||||
# manpage or used elsewhere by Homebrew. | ||||||||||||||
|
||||||||||||||
|
@@ -121,6 +170,7 @@ export HOMEBREW_BREW_FILE | |||||||||||||
export HOMEBREW_PREFIX | ||||||||||||||
export HOMEBREW_REPOSITORY | ||||||||||||||
export HOMEBREW_LIBRARY | ||||||||||||||
export HOMEBREW_USER_CONFIG_HOME | ||||||||||||||
|
||||||||||||||
# set from user environment | ||||||||||||||
# shellcheck disable=SC2154 | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to check for whether this is set in
/etc/homebrew/brew.env
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carlocab to avoid it being set by the environment or something else? Allowing it to be set from environment makes testing a bunch easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More to allow the administrator of
/etc/homebrew/brew.env
to decide whether the system env takes priority or not. Otherwise users can just dounset HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY
. We can take the value from the environment too if it's not set in the system env.But I'm not bothered if you'd rather someone who needed it implemented this.