-
-
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
Allow configuring Homebrew with .env
files
#15787
Conversation
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-}" ]] |
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 do unset 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.
For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
if [[ -n "${XDG_CONFIG_HOME-}" ]] | ||
then | ||
HOMEBREW_USER_CONFIG_HOME="${XDG_CONFIG_HOME}/homebrew" |
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.
if [[ -n "${XDG_CONFIG_HOME-}" ]] | |
then | |
HOMEBREW_USER_CONFIG_HOME="${XDG_CONFIG_HOME}/homebrew" | |
if [[ -n "${HOMEBREW_XDG_CONFIG_HOME-}" ]] | |
then | |
HOMEBREW_USER_CONFIG_HOME="${HOMEBREW_XDG_CONFIG_HOME}/homebrew" |
and XDG_CONFIG_HOME
needs to be added to USED_BY_HOMEBREW_VARS
in bin/brew
.
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 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Env filtering:
❯ XDG_CONFIG_HOME=foo brew ruby -e 'puts ENV["XDG_CONFIG_HOME"].present?'
false
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 We don't rely on XDG_CONFIG_HOME
being set anywhere after env filtering is applied (unless I missed something), no?
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.
Ah, sorry, I thought this was in brew.sh
. 😅 That said, don't we want to have the same behaviour for the livecheck watchlist? i.e. check $XDG_CONFIG_HOME/homebrew/livecheck_watchlist.txt
if XDG_CONFIG_HOME
is set?
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 that behaviour is already present. We don't pass through XDG_CONFIG_HOME
because we don't want/need to. It's documented that we use it if set but that's only needed/used in brew.sh
which in turn sets HOMEBREW_USER_CONFIG_HOME
accordingly and that is used afterwards.
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"
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.
Aha, yes. I clearly did not understand the changes here. Thanks for bearing with me!
@carlocab you're very welcome, thanks for the review! ❤️ |
Hi! After this change, I'm having issues running Every state I try to run with
I've checked how if runas:
_cmd = ["sudo -i -n -H -u {} -- ".format(runas)]
_cmd = _cmd + [salt.utils.path.which("brew")] + list(cmd)
_cmd = " ".join(_cmd) It apparently tries to set the However, I've not been able to reproduce the error in any other more isolated way. Update: As a temporary fix, I have checkout my Homebrew installation to point to the latest release: git -C ${fetch --all
git -C ${HOMEBREW_PREFIX} checkout 4.1.3 |
@cdalvaro I'll work on a fix for this tomorrow. |
Great!!! Thank you very much! Let me know if I can help you! |
For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that.
Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user.
The system-wide configuration file is
/etc/homebrew/brew.env
, the prefix-specific configuration file is$HOMEBREW_PREFIX/etc/homebrew/brew.env
and the user-specific configuration file is~/.homebrew/brew.env
.As we need to read these files from Bash in
bin/brew
(so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in abrew.json
/brew.yaml
file in the same directory.As this is relying on
eval
in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting settingHOMEBREW_*
variables and nothing more.To give a bit of power to system administrators, the
HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY
variable can be set in/etc/homebrew/brew.env
to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings.Now that we have an actual location for configuration files, let's also change the
brew livecheck
watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.