Skip to content

bin/brew: better user config home handling #20250

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

etcusrvar
Copy link

@etcusrvar etcusrvar commented Jul 13, 2025

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Feature: improved HOMEBREW_USER_CONFIG_HOME

HOMEBREW_USER_CONFIG_HOME can now be in a few standard locations

  1. ~/.homebrew
  2. $XDG_CONFIG_HOME/homebrew (if the variable is set)
  3. ~/.config/homebrew
  4. ~/Library/Application Support/homebrew

See issue #20251 for more details.
I've been using this on both macOS and Linux, without XDG_CONFIG_HOME explicitly set, and it reads my ~/.config/homebrew/brew.env whenever I run the brew command, which is nice.
If the idea meets with approval, I can add any appropriate tests and documentation.

@MikeMcQuaid
Copy link
Member

@etcusrvar Let's talk about your use-case specifically: what are you trying to do that the existing code doesn't let you achieve?

@etcusrvar
Copy link
Author

etcusrvar commented Jul 14, 2025

@etcusrvar Let's talk about your use-case specifically: what are you trying to do that the existing code doesn't let you achieve?

Specifically, I'd like to have my user brew.env (not the one located in $HOMEBREW_PREFIX/etc/homebrew) located under ~/.config/homebrew, and have it be used/read by the brew command without having to explicitly set XDG_CONFIG_HOME.
I don't currently explicitly set XDG_CONFIG_HOME for any other tool I use on macOS or Linux, and most (or at least many) of them use ~/.config for config files.
I currently use a wrapper script for the brew command whose sole purpose is to set XDG_CONFIG_HOME before calling brew.

@MikeMcQuaid
Copy link
Member

@etcusrvar Two questions:

  • are you on macOS or Linux?
  • why do you want to avoid setting XDG_CONFIG_HOME in your environment?

Copy link
Member

@carlocab carlocab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour is similar to what tools like git do, so it seems fine to me.

Comment on lines +165 to +167
elif [[ -d "${HOME}/Library/Application Support/homebrew" ]]
then
HOMEBREW_USER_CONFIG_HOME="${HOME}/Library/Application Support/homebrew"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elif [[ -d "${HOME}/Library/Application Support/homebrew" ]]
then
HOMEBREW_USER_CONFIG_HOME="${HOME}/Library/Application Support/homebrew"
elif [[ -d "${HOME}/Library/Application Support/Homebrew" ]]
then
HOMEBREW_USER_CONFIG_HOME="${HOME}/Library/Application Support/Homebrew"

I think directories in ~/Library are usually capitalised.

Copy link
Author

@etcusrvar etcusrvar Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"usually" being the operative word. I do see a handful of directories on my system that aren't. I was aiming for consistency across homebrew options. But I'm fine with having it be capitalized there and lower case in other locations if we want.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please hold on merging until we've discussed this a bit more.

@etcusrvar
Copy link
Author

etcusrvar commented Jul 14, 2025

@etcusrvar Two questions:

  • are you on macOS or Linux?

I believe I've answered that a few times in the comments here and in the linked issue-- yes. both.

  • why do you want to avoid setting XDG_CONFIG_HOME in your environment?

Primarily because no other tool requires it to be explicitly set because I'm using the default of ~/.config.

Many other tools use ~/.config as their default location for config files without needing XDG_CONFIG_HOME being set, on both macOS and Linux. Homebrew is the only one I've come across where it's explicitly required to be set.

Here's the docs on configuration files for a few tools-- chezmoi, fish, git, helix, htop, mise, tmux.

Many of these and others follow the XDG spec, on both Linux and macOS. (And, yes, many don't. :( )

I'm fine with setting app specific environment variables, like HOMEBREW_*, if needed. But XDG_CONFIG_HOME is a standard that is used by many applications and tools, and it doesn't make sense to me to have to explicitly define it for only one tool, when I want to use the standard default location.

Comment on lines +156 to +158
if [[ -d "${HOME}/.homebrew" ]]
then
HOMEBREW_USER_CONFIG_HOME="${HOME}/.homebrew"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already handled by the else case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. The reason I did this this way was because I didn't want a user who might have both ~/.homebrew and one of the other 3 directories created to be surprised when their configuration suddenly changed. But I'm fine with only defining it once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, makes sense, thanks 👍🏻

@MikeMcQuaid
Copy link
Member

Primarily because no other tool requires it to be explicitly set because I'm using the default of ~/.config.

Is it not set by the XDG environment on Linux? What desktop environment/Linux distribution are you using there?

Many of these and others follow the XDG spec, on both Linux and macOS. (And, yes, many don't. :( )

I do not think the XDG specification should be followed on macOS.

But XDG_CONFIG_HOME is a standard that is used by many applications and tools, and it doesn't make sense to me to have to explicitly define it for only one tool, when I want to use the standard default location.

Would setting HOMEBREW_CONFIG_HOME or similar be suitable instead?

Note that the behaviour and/or documentation for both brew bundle --global and HOMEBREW_LIVECHECK_WATCHLIST will need to be tested and updated based on any changes here.

As-is, I'm disinclined to add several new default directories based on one person/PR when it's already configurable. If it's insufficiently configurable: it would be preferable for me for HOMEBREW_CONFIG_HOME or similar to be configurable, default to ~/.homebrew or XDG_CONFIG_HOME if explicitly set.

@etcusrvar
Copy link
Author

Is it not set by the XDG environment on Linux? What desktop environment/Linux distribution are you using there?

I've used Debian, Arch, and others, and none of the XDG_* vars are set by default, because they all have default locations if those vars are unset. Homebrew is not using the default location. In the homebrew/brew docker image that Homebrew provides, none of these variables are set.

I do not think the XDG specification should be followed on macOS.

Agreed. (But many tools do anyway, such as those I listed earlier.) And, as is, without this PR, I use a wrapper script with XDG_CONFIG_HOME defined on macOS, and it works fine, as expected, just as it does on Linux.

Would setting HOMEBREW_CONFIG_HOME or similar be suitable instead?

That would be great!

Note that the behaviour and/or documentation for both brew bundle --global and HOMEBREW_LIVECHECK_WATCHLIST will need to be tested and updated based on any changes here.

Agreed. This is an incomplete draft PR at this point, and is why I mentioned this earlier-- "If the idea meets with approval, I can add any appropriate tests and documentation."

As-is, I'm disinclined to add several new default directories based on one person/PR when it's already configurable. If it's insufficiently configurable: it would be preferable for me for HOMEBREW_CONFIG_HOME or similar to be configurable, default to ~/.homebrew or XDG_CONFIG_HOME if explicitly set.

Ok. The only change for me then as a user would be to explicitly define HOMEBREW_CONFIG_HOME instead of XDG_CONFIG_HOME, which is fine I suppose. It still would be nice if the standard default ~/.config was used.

@MikeMcQuaid
Copy link
Member

The only change for me then as a user would be to explicitly define HOMEBREW_CONFIG_HOME instead of XDG_CONFIG_HOME, which is fine I suppose.

Yup, I think that's the best change here.

It still would be nice if the standard default ~/.config was used.

As long as we still pick up the .homebrew location if it's been already used: I would be fine with a ~/.config default on Linux as long as using .homebrew on Linux will both work and take priority over .config.

Copy link

github-actions bot commented Aug 6, 2025

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale No recent activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants