rcmdnk / homebrew-file

Brewfile manager for Homebrew
http://homebrew-file.readthedocs.io/
MIT License
356 stars 29 forks source link

repository taps always get written to top-level brew file #280

Open zcutlip opened 3 months ago

zcutlip commented 3 months ago

I have a top-level brew file called Brewfile I also have a host specific brew file where I have the directive tap homebrew/services

When I run brew-file update that tap also gets added to Brewfile, although it remains in the host specific one as well.

Is there a way to keep the tap from being added to the top Brewfile?

I can paste in my files if it helps.

rcmdnk commented 3 months ago

Could you please try to delete tap homebrew/services from Brewfile and try brew-file update again?

If tap homebrew/services exists in a host specific file and does not exist in top level file, brew-file update should keep the tap only in a host specific file.

My top level Brewfile is like:

# tap repositories and their packages

tap homebrew/core

tap homebrew/cask

# Main file
main ./Brewfile.$PLATFORM.$HOSTTYPE

and main file Brewfile.darwin.arm64:

# tap repositories and their packages

tap homebrew/core
brew automake
...

tap homebrew/cask
cask accessmenubarapps
...

tap homebrew/services

...

When I execute brew-file update, these structures are kept.

zcutlip commented 3 months ago

I may be doing something wrong, but I did what you said, and the line reappeared

Here's brew-file get_files:

/Users/zach/.dotfiles/brewfile/Brewfile
/Users/zach/.dotfiles/brewfile/sarapin.Brewfile
/Users/zach/.dotfiles/brewfile/mac-server.Brewfile
/Users/zach/.dotfiles/brewfile/arch_x86_64.Brewfile
/Users/zach/.dotfiles/brewfile/bootstrap.Brewfile
/Users/zach/.dotfiles/brewfile/common.Brewfile

Here's ag 'homebrew\/services':

brewfile/sarapin.Brewfile
4:tap homebrew/services

brewfile/Brewfile
12:tap homebrew/services

Happy to share any other details or output!

rcmdnk commented 3 months ago

sorry for the late reply. Could you give me a structure of these Brewfile?

Information at least:

zcutlip commented 2 months ago

Sorry! This got filtered to a folder and I missed it

I'm not sure if this is what you're asking for, but here's Brewfile:


# tap repositories and their packages

tap homebrew/core

tap homebrew/cask

tap homebrew/bundle

tap homebrew/command-not-found

tap homebrew/services

tap rcmdnk/file

tap saagarjha/tap

tap teamookla/speedtest

tap vitorgalvao/tiny-scripts

tap zcutlip/extras

# Additional files
file ./${HBB_EXTRA}-casks.Brewfile
file ./${HOSTNAME_OVERRIDE}.Brewfile
file ./${HOSTNAME}-mas.Brewfile
file ./${HOSTNAME}.Brewfile
file ./arch_${ARCH}.Brewfile
file ./bootstrap.Brewfile
file ./common.Brewfile

And here's sarapin.Brewfile:


# tap repositories and their packages

tap homebrew/services

# Other Homebrew packages
brew colima
brew docker
brew docker-buildx
brew docker-compose

# Other Cask applications
cask 1password
cask syncthing
cask tailscale

# Additional files
file ./mac-server.Brewfile

I could tar up all of my brewfiles if that's helpful, but they're quite complex and probably more hindrance than help.

rcmdnk commented 2 months ago

I understand the issue.

Currently, all taps are written to the main Brewfile, even if they are specified in other Brewfiles.

Since you are only using the file command, the current main Brewfile is treated as the top-level Brewfile.

This behavior is intentional: https://github.com/rcmdnk/homebrew-file/blob/2d5a169de64255ae040c2190f0684562288cc457/src/brew_file/brew_file.py#L1036

If you rewrite top level file like:

# Additional files
main ./${HOSTNAME}.Brewfile

file ./${HBB_EXTRA}-casks.Brewfile
file ./${HOSTNAME_OVERRIDE}.Brewfile
file ./${HOSTNAME}-mas.Brewfile
file ./arch_${ARCH}.Brewfile
file ./bootstrap.Brewfile
file ./common.Brewfile

Then all taps are written in sarapin.Brewfile.

[!Note] In this case, if you add new formula, it is added into sarapin.Brewfile instead of the top level file.

Honestly, I do not remember why all taps are remained, but it was implemented like this when file command is introduced.

Maybe it depends on how extra files are used and there might be some side effects if they are not remained in the main file.

But it seems they can be removed in my current usage, too.

Let me check some more time to confirm the behavior.

zcutlip commented 2 months ago

Oh, I see. I wasn't even aware of the main command. But I've looked it up now, and I'll see if I can rewrite it that way