137 Commits
Author SHA1 Message Date
Zhaofeng LiandGitHub 60623ec512 Merge pull request #162 from ELD/update-brew-src
brew-src: 6.0.11 -> 6.0.12
2026-07-24 11:26:01 -04:00
Eric Dattore 0a58629fa9 brew-src: 6.0.11 -> 6.0.12
Updates the brew CLI to support new install steps in formulaes that
break on older versions of the brew CLI.
2026-07-21 14:37:03 -06:00
Zhaofeng LiandGitHub 842eeb863e Merge pull request #160 from zhaofengli/brew-6.0.11
brew-src: 6.0.9 -> 6.0.11
2026-07-15 19:54:24 -04:00
Zhaofeng Li 52524493b5 brew-src: 6.0.9 -> 6.0.11 2026-07-15 13:14:48 -04:00
Zhaofeng LiandGitHub 60641da832 Merge pull request #158 from Azd325/bump-brew-6.0.7
brew-src: 6.0.1 -> 6.0.9
2026-07-12 13:04:18 -04:00
Tim Kleinschmidt be2ea0e091 brew-src: 6.0.7 -> 6.0.9 2026-07-09 08:11:50 +02:00
Tim Kleinschmidt c3fca26799 brew-src: 6.0.1 -> 6.0.7
Includes Homebrew/brew#22961, which adds the `init_data_dir`
InstallSteps DSL action. Without it, homebrew-core's current
postgresql@18 formula fails with:

    undefined method 'init_data_dir' for an instance of
    Homebrew::InstallSteps::DSL
2026-07-06 20:44:32 +02:00
Zhaofeng LiandGitHub de7953a08e Merge pull request #157 from zhaofengli/tap-trust
Add support for adding trust entries during activation
2026-06-13 18:20:46 -04:00
Zhaofeng Li df1ada99b7 Add support for adding trust entries during activation
Instead of trusting whole taps automatically, let the user configure
what to trust. I think this implementation better aligns with upstream
intent.

Fixes #156.
2026-06-13 17:55:36 -04:00
Zhaofeng LiandGitHub 5e721fc775 Merge pull request #154 from zhaofengli/brew-6.0.0
brew-src: 5.1.14 -> 6.0.1
2026-06-12 09:05:51 -04:00
Zhaofeng Li 6835b13e03 ci: Update deprecated nixfmt-rfc-style alias 2026-06-12 08:35:11 -04:00
Zhaofeng Li 9c3819c9d6 Fix Homebrew README.md matching
Now there's a 🍺 emoji.
2026-06-12 08:35:11 -04:00
Zhaofeng Li 716a3c73f5 brew-src: 5.1.14 -> 6.0.0 2026-06-12 08:35:11 -04:00
Zhaofeng LiandGitHub e3f2579efe Merge pull request #150 from TyceHerrman/fix/tap-validation
Fix cask tap materialization
2026-06-11 23:33:48 -04:00
Tyce HerrmanandZhaofeng Li 6a201170a3 Fix cask tap materialization 2026-06-11 22:59:00 -04:00
Zhaofeng LiandGitHub 562332f97d Merge pull request #147 from Azd325/brew-5.1.14
chore(deps): upgrade brew-src to 5.1.14
2026-06-03 09:14:27 -04:00
Tim Kleinschmidt ec9ad01617 chore(deps): upgrade brew-src to 5.1.14 2026-06-02 15:13:54 +02:00
Zhaofeng LiandGitHub b3a87b4793 Merge pull request #141 from zhaofengli/brew-5.1.11
brew-src: 5.1.10 -> 5.1.11
2026-05-15 09:26:04 -04:00
Zhaofeng Li 4b41cb0579 brew-src: 5.1.10 -> 5.1.11 2026-05-15 08:56:42 -04:00
Zhaofeng LiandGitHub 7d0038b5bb Merge pull request #136 from matinzd/patch-1
chore: update homebrew to 5.1.10
2026-05-09 09:16:31 -04:00
Matin Zadeh DolatabadandZhaofeng Li f128474792 brew-src: 5.1.7 -> 5.1.10
Fixes #138.

Bug: https://github.com/Homebrew/brew/issues/22165#issuecomment-4396297893
2026-05-09 09:04:14 -04:00
Zhaofeng LiandGitHub aeb2069920 Merge pull request #133 from Azd325/main
chore(deps): upgrade brew-src to 5.1.7
2026-04-26 20:43:41 -04:00
Tim Kleinschmidt 8eb1c803b4 fix(deps): adapt brew.tail.sh to Homebrew 5.1.7 changes 2026-04-24 18:20:36 +02:00
Tim Kleinschmidt 0ea5a1aa98 chore(deps): upgrade brew-src to 5.1.7 2026-04-24 18:16:42 +02:00
Zhaofeng LiandGitHub a7760a3a83 Merge pull request #130 from zhaofengli/brew-5.1.1
brew-src: 5.0.12 -> 5.1.1
2026-03-28 13:51:07 -04:00
Zhaofeng Li 99c7ead19c brew-src: 5.0.12 -> 5.1.1 2026-03-28 13:31:56 -04:00
Zhaofeng Li 0406ffd7d3 ci: Update nixpkgs and nix-darwin (unstable, 25.05 -> 25.11) 2026-03-28 13:31:56 -04:00
Zhaofeng Li f15662134d ci: Upgrade runners to macos-26 2026-03-28 13:31:56 -04:00
Zhaofeng LiandGitHub a5409abd0d Merge pull request #124 from Azd325/bump-homebrew-5.0.7
Update brew to version 5.0.12
2026-01-26 09:23:52 -05:00
Tim KleinschmidtandZhaofeng Li 30cd0d2ae1 brew-src: 5.0.3 -> 5.0.12 2026-01-26 09:07:41 -05:00
Zhaofeng LiandGitHub 6a8ab60bfd Merge pull request #120 from rick-yao/main
brew-src: 4.6.19 -> 5.0.3
2025-11-29 22:34:58 -05:00
Rick YaoandZhaofeng Li bacea0c124 brew-src: 4.6.19 -> 5.0.3 2025-11-29 22:21:23 -05:00
Zhaofeng LiandGitHub ff7c5f264d Merge pull request #122 from zhaofengli/switch-gha-nix-installer
.github: Switch to samueldr/lix-gha-installer-action
2025-11-29 22:14:29 -05:00
Zhaofeng Li 9bae20a37d .github: Switch to samueldr/lix-gha-installer-action 2025-11-22 09:49:32 -05:00
Zhaofeng LiandGitHub 3cae36b3a1 Merge pull request #117 from Yeradon/main
brew-src: 4.6.12 -> 4.6.19
2025-10-31 12:17:50 -04:00
Kai 5a9a0141b8 brew-src 4.6.12 -> 4.6.19 2025-10-29 16:07:51 +01:00
Zhaofeng Li f36e5db56e brew-src: 4.6.7 -> 4.6.12 2025-09-22 23:30:28 -04:00
Christoph HerbandZhaofeng Li 3aa475996c brew-src: 4.5.13 -> 4.6.7 2025-08-28 12:29:06 -04:00
Zhaofeng Li 314d057294 brew-src: 4.5.9 -> 4.5.13 2025-08-03 13:56:33 -06:00
Zhaofeng Li 9335d8c81b ci: Bump deps 2025-08-03 13:56:33 -06:00
Vinicius DeolindoandZhaofeng Li db11cc216d flake: add a default entry to darwinModules 2025-07-31 16:39:25 -06:00
Drewry PopeandZhaofeng Li a3c09bc7ce Update README.md 2025-07-31 13:26:40 -06:00
Drewry PopeandZhaofeng Li a8788a90eb document homebrew/nix-homebrew interaction
fixes: #5
2025-07-31 13:26:40 -06:00
Zhaofeng Li 69c1aa2f13 ci: Bump deps 2025-07-10 09:22:53 -06:00
Zhaofeng Li 205d9d14e8 brew-src: 4.5.6 -> 4.5.9 2025-07-10 09:22:53 -06:00
Zhaofeng Li 37126f06f4 ci: Bump deps 2025-06-14 19:50:50 -06:00
hcbtandZhaofeng Li e048b6646b brew-src: 4.5.4 -> 4.5.6 2025-06-09 19:30:04 -06:00
isabelandZhaofeng Li 5108f0846c module: remove mentions of removed lib.mdDoc 2025-06-04 12:27:53 -06:00
Zhaofeng Li 29fe08d458 brew-src: 4.5.3 -> 4.5.4 2025-06-02 11:35:38 -06:00
Mike SplainandZhaofeng Li 7751744573 brew-src: 4.5.2 -> 4.5.3 2025-05-27 15:04:53 -06:00
Zhaofeng Li 6f94d412d3 Don't patch shebang of prefix-specific brew launcher
This was broken during the switch to replaceVarsWith.
2025-05-26 18:24:08 -06:00
Zhaofeng Li 5538fdcbdb ci: Test executing brew under Rosetta 2025-05-26 18:24:08 -06:00
Zhaofeng Li 5a2272eeb2 Require system-wide activation 2025-05-26 09:17:46 -06:00
Zhaofeng Li 23747f69ea Reapply "refactor: substituteAll -> replaceVars"
This reverts commit 61ca6faf84.
2025-05-26 09:17:46 -06:00
Zhaofeng Li 09c0111fe0 Split CI into separate flake, test multiple releases
This is so that users won't need to download our pinned
nixpkgs/nix-darwin versions.
2025-05-25 15:43:00 -06:00
Zhaofeng Li bb068c5df0 pkgs: Don't pass all inputs 2025-05-25 15:43:00 -06:00
Zhaofeng Li 159f21ae77 Tweak logging during setup 2025-05-16 19:08:29 -06:00
Zhaofeng Li 0d8905164e Support nix-darwin system-wide activation
Fixes #60.

Ref:
- https://github.com/LnL7/nix-darwin/pull/1341
- https://github.com/LnL7/nix-darwin/issues/96
2025-05-16 19:08:29 -06:00
Zhaofeng Li 61ca6faf84 Revert "refactor: substituteAll -> replaceVars"
This reverts commit d42da140a6.
2025-05-12 09:33:10 -06:00
Zhaofeng LiandGitHub fae199aa8b Merge pull request #86 from isabelroses/fix-replacevars
refactor: substituteAll -> replaceVars
2025-05-09 20:34:51 -06:00
Zhaofeng LiandGitHub d0fe6dffc8 Merge pull request #85 from mikesplain/brew_4.5.2
Bump brew to 4.5.2
2025-05-09 17:01:24 -06:00
isabel d42da140a6 refactor: substituteAll -> replaceVars 2025-05-09 20:12:59 +01:00
Mike Splain 4945f477bc Bump brew to 4.5.2 2025-05-09 10:12:00 -04:00
Zhaofeng LiandGitHub 20e4702906 Merge pull request #82 from guhou/update-to-ruby-3-4
brew-src: 4.4.25 -> 4.5.0, upgrade to Ruby 3.4
2025-05-05 11:06:28 -06:00
Zhaofeng Li 0ac6769623 brew-src: 4.4.25 -> 4.5.0 2025-05-05 11:00:34 -06:00
Zhaofeng Li fb2891f058 flake.lock: Update nixpkgs 2025-05-05 11:00:34 -06:00
Zhaofeng LiandGitHub 2a04193744 Merge pull request #78 from thanegill/patch-1
Use substituteInPlace --replace-fail
2025-05-05 10:48:15 -06:00
Angus Houston c8a6b93909 Upgrade to Ruby 3.4
As of recent release (I think [Homebrew
4.5.0](https://github.com/Homebrew/brew/releases/tag/4.5.0), the minimum
required Ruby version for Homebrew is 3.4. I've changed the Nix package
from `pkgs.ruby_3_3` to `pkgs.ruby_3_4`, which currently installs Ruby
3.4.3 on the unstable and 24.11 channels.

Fixes zhaofengli/nix-homebrew#81
2025-05-02 11:47:19 +10:00
Thane GillandGitHub f05578ef67 Use substituteInPlace --replace-fail
Plain `--replace` is deprecated.
2025-04-18 14:32:28 -07:00
Zhaofeng LiandGitHub 53507607d6 Merge pull request #75 from derrik-fleming/chore/update-readme-example
chore(docs): update example in `README`
2025-04-13 11:05:14 -06:00
Zhaofeng LiandGitHub 743089d0fd Merge pull request #76 from isabelroses/git-min
refactor: use git minimal
2025-04-13 11:04:20 -06:00
isabel bf49c5ecd1 refactor: use git minimal
we should use git minimal here since it brings less deps (e.g. perl) and
functions the same for the purpose of the script
2025-04-09 23:42:38 +01:00
derrik-fleming c4a0f6fac5 chore(docs): update example in README 2025-04-01 09:50:38 -04:00
Zhaofeng LiandGitHub 04b0536479 Merge pull request #72 from Iamanaws/patch-1
Remove homebrew-bundle from README.md
2025-03-21 22:56:34 -06:00
Zhaofeng LiandGitHub 0c93e7dc33 Merge pull request #71 from JacobHayes/push-xrqvvmrllxrp
Bump to brew 4.4.25
2025-03-21 22:55:25 -06:00
Angel JandGitHub e677508f1f Remove homebrew-bundle from README.md
Homebrew Bundle repo deprecated
https://github.com/Homebrew/homebrew-bundle

Follows Brew update
https://github.com/zhaofengli/nix-homebrew/pull/71
2025-03-21 12:28:54 -07:00
Jacob Hayes 3ed9210931 Bump to brew 4.4.25 2025-03-20 11:38:45 -05:00
Zhaofeng LiandGitHub a82c55b07f Merge pull request #63 from zhaofengli/brew-4.4.23
brew-src: 4.4.5 -> 4.4.23
2025-03-03 13:14:38 -07:00
Zhaofeng LiandGitHub 51468504ca Merge pull request #59 from folliehiyuki/extra-env
Implement extraEnv option
2025-03-03 13:12:08 -07:00
Zhaofeng Li 83cb1dc7ec brew-src: 4.4.5 -> 4.4.23 2025-03-03 13:03:53 -07:00
Zhaofeng Li 85fdc3b239 README.md: Mention homebrew options in nix-darwin 2025-03-03 13:03:53 -07:00
Hoang Nguyen eac24bd063 Implement extraEnv option 2025-02-03 00:00:00 +07:00
Zhaofeng LiandGitHub a6d99cc743 Merge pull request #57 from isabelroses/chore-drop-fu
chore: drop flake-utils
2025-01-04 18:52:37 -07:00
isabel 77d88873ad chore: drop flake-utils
flake-utils' main utility is making flakes easier to make. but more
modernly they don't provide much utility above of overrideable systems,
which is not being utlised here. So instead lets remove the input and
vendor our own "forAllSystems" function to recreate what we previously
used flake-utils for.
2025-01-04 17:28:41 +00:00
Zhaofeng LiandGitHub ac3945ee61 Merge pull request #50 from zhaofengli/fix-homebrew-install-check-2
Ignore unused INSTALLING_HOMEBREW error in older nix-darwin
2024-11-20 16:32:23 -07:00
Zhaofeng Li cf10b2c735 Ignore unused INSTALLING_HOMEBREW shellcheck error in older nix-darwin versions
Probably better to just ignore it instead :/

Ref: #48.
2024-11-20 15:50:33 -07:00
Zhaofeng LiandGitHub f358056384 Merge pull request #49 from zhaofengli/fix-homebrew-install-check 2024-11-20 15:42:00 -07:00
Zhaofeng Li 333d5b28cc Only set INSTALLING_HOMEBREW if homebrew module is enabled
Fallout of #47.

Fixes #48.
2024-11-20 15:11:27 -07:00
Zhaofeng LiandGitHub 5eb00c5e01 Merge pull request #47 from isabelroses/patch-1
fix: disable homebrew install checks
2024-11-19 15:25:08 -07:00
IsabelandGitHub b7c185c9c3 fix: sepecify lib.mkBefore 2024-11-19 17:04:15 +00:00
IsabelandGitHub 07fb2844e9 fix: disable homebrew install checks 2024-11-19 13:05:51 +00:00
Zhaofeng LiandGitHub 0312ad2a33 Merge pull request #46 from zhaofengli/ci-upgrade 2024-11-15 08:42:12 -07:00
Zhaofeng Li 6e20c028b2 examples/migrate: Enable Rosetta 2024-11-15 08:33:25 -07:00
Zhaofeng Li 280bf59451 ci: Pass system through attribute 2024-11-15 08:33:25 -07:00
Zhaofeng Li 6a229f1d7b ci: Delete stray files 2024-11-15 08:33:25 -07:00
Zhaofeng Li 2eea1d33ec Fix tty color 2024-11-15 08:33:25 -07:00
Zhaofeng Li 5d8ad87e44 .github: Update CI runner to macos-latest 2024-11-15 08:33:25 -07:00
Zhaofeng LiandGitHub 348c09d6d5 Merge pull request #44 from zhaofengli/brew-4.4.5
brew-src: 4.3.24 -> 4.4.5
2024-11-15 07:59:59 -07:00
Zhaofeng LiandGitHub 2ed1e70db2 Merge pull request #37 from dezren39/patch-1
add homebrew-bundle to example
2024-11-12 11:09:16 -07:00
Zhaofeng Li 275db24af7 brew-src: 4.3.24 -> 4.4.5 2024-11-12 11:00:57 -07:00
Zhaofeng LiandGitHub d66fc9c14a Merge pull request #40 from dezren39/patch-2
Document Declarative Taps
2024-11-12 10:57:35 -07:00
Zhaofeng LiandGitHub b5224d5101 Merge pull request #39 from dezren39/shellIntegration
enable shell integration
2024-11-12 10:56:44 -07:00
Drewry PopeandGitHub c59b075806 Update README.md 2024-10-22 21:33:36 -05:00
Drewry PopeandGitHub 404707420f Update README.md 2024-10-22 21:32:37 -05:00
Drewry PopeandGitHub f04abdba9f Document Declarative Taps
fixes: 15
2024-10-22 21:29:52 -05:00
Drewry Pope 28aafdb199 comment 2024-10-22 20:12:01 -05:00
Drewry Pope 896a49cfd2 enable shell integration 2024-10-22 19:52:48 -05:00
Drewry PopeandGitHub 784add2844 Update README.md 2024-10-22 19:01:18 -05:00
Drewry PopeandGitHub 5cba86fce2 add homebrew-bundle to example
#32 #9
2024-10-22 18:59:55 -05:00
Zhaofeng LiandGitHub 86af3bb8f7 Merge pull request #34 from chrishrb/update-brew-4.3.24
Update brew to version 4.3.24
2024-10-05 12:37:42 -06:00
Christoph Herb 098c1e2b64 Update brew to version 4.3.24 2024-09-24 12:17:57 +02:00
Zhaofeng LiandGitHub 0afc51fd86 Merge pull request #26 from abayomi185/brew-4.3.5
brew-src: 4.3.1 -> 4.35 - support for macOS Sequioa
2024-06-30 00:03:31 -04:00
Yomi Ikuru 83d5093567 brew-src: 4.3.1 -> 4.35 - support for Sequioa 2024-06-12 00:03:39 +01:00
Zhaofeng LiandGitHub 31e9c8105a Merge pull request #23 from zhaofengli/brew-4.3.1
brew-src: 4.2.16 -> 4.3.1
2024-05-27 13:34:57 -06:00
Zhaofeng Li fe640d4e65 ci: Remove old /etc/nix/nix.conf before first activation 2024-05-27 13:30:45 -06:00
Zhaofeng Li 71f3e17124 flake.lock: Update 2024-05-27 13:30:45 -06:00
Zhaofeng Li e88b940e4c Pin to Ruby 3.3
We are using their bundled gems and this can be extremely fragile :/
2024-05-27 13:30:45 -06:00
Zhaofeng Li c481a6255a Bypass git describe caching in brew.sh
Probably a good idea to work out a cleaner way with upstream.
2024-05-27 13:30:45 -06:00
Zhaofeng Li c9c4eb588b brew-src: 4.2.16 -> 4.3.1 2024-05-27 13:30:45 -06:00
Zhaofeng Li 445f7989e0 Patch Homebrew to embed version number
homebrew-bundle now depends on $HOMEBREW_VERSION, which is set by
`brew.sh` using the output of `git describe`. We don't have a git
repo, so let's embed the version directly.

Fixes #19.
2024-04-03 16:19:39 -06:00
Zhaofeng Li 0b38f9df1f brew-src: 4.2.4 -> 4.2.16 2024-04-03 16:19:39 -06:00
Zhaofeng Li 40f5ee46b5 Merge branch 'brew-4.2.4' 2024-01-22 12:33:54 -07:00
Zhaofeng Li afca10658b Patch Homebrew to disable vendored Ruby 2024-01-22 12:26:27 -07:00
Zhaofeng Li 6049f4b25f Inject own runtimePath to brew.sh 2024-01-22 12:26:27 -07:00
Zhaofeng Li 51ffd69941 Update brew.tail.sh 2024-01-22 12:26:27 -07:00
Zhaofeng Li 27ca85935b brew-src: 4.1.22 -> 4.2.4 2024-01-22 12:26:27 -07:00
Zhaofeng Li 62c13be6f0 Patch Homebrew to disable vendored Ruby 2024-01-22 12:26:10 -07:00
Zhaofeng Li d517a7ad8a Inject own runtimePath to brew.sh 2024-01-22 12:26:10 -07:00
Zhaofeng Li 0e295b050c Update brew.tail.sh 2024-01-22 12:26:10 -07:00
Zhaofeng Li f3cf08e589 brew-src: 4.1.22 -> 4.2.4 2024-01-22 12:26:10 -07:00
Zhaofeng Li 35768b9ac2 nuke-homebrew-directory: Also delete stray vendor directory 2024-01-22 01:16:34 -07:00
Zhaofeng Li b120ba7e22 Automatically extract the bootstrap script from upstream Homebrew 2024-01-05 09:46:21 -07:00
Zhaofeng Li 7dae8051e6 brew-src: 4.1.11 -> 4.1.22 2024-01-05 09:46:21 -07:00
Zhaofeng Li 6ab33c5e92 Add env config handling from upstream
Fixes #7.
2023-09-18 11:18:18 -06:00
Zhaofeng Li 512e51ddcd brew-src: 4.1.1 -> 4.1.11 2023-09-17 12:52:26 -06:00
Zhaofeng Li d2738b78fd brew-src: 4.0.26 -> 4.1.1 2023-07-27 16:08:30 -06:00
Zhaofeng Li 18a4c8cb8c Use nixpkgs-provided git
This reduces the dependency on Xcode/CLT.
2023-07-13 12:32:04 -06:00
21 changed files with 1086 additions and 328 deletions
+24 -29
View File
@@ -5,41 +5,36 @@ on:
pull_request:
jobs:
check:
runs-on: macos-13
nix-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Test nuke-homebrew-repository
- uses: actions/checkout@v4
- uses: samueldr/lix-gha-installer-action@v2025-10-27
- id: set-matrix
name: Generate Nix Matrix
run: |
nix build .#nuke-homebrew-repository.passthru.tests.test-nuke -L
- name: Install some package with Homebrew
run: |
brew install unbound
- name: Add a third-party tap imperatively
run: |
brew tap koekeishiya/formulae
set -Eeu
matrix="$(nix eval --json '.#githubActions.matrix')"
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
check:
name: ${{ matrix.name }} (${{ matrix.system }})
needs: nix-matrix
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v4
- uses: samueldr/lix-gha-installer-action@v2025-10-27
- name: Set up /run for nix-darwin
run: |
printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf
sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t || true
- name: Migrate existing Homebrew installation (imperative taps)
- name: Run test
run: |
sudo rm /etc/bashrc
./ci/activate-example.sh migrate
- name: Check that we can still use the unbound package
run: $(brew --prefix)/sbin/unbound -V
- name: Check that we can still use the tap that we added imperatively
run: brew install koekeishiya/formulae/yabai
#- name: Migrate to fully-declarative tap management
# run: |
# false
export NIX_HOMEBREW_CI=1
ci_script=$(nix build -L '.#${{ matrix.attr }}' --print-out-paths)
"$ci_script"
+2
View File
@@ -3,6 +3,8 @@
result*
/ci/*.json
*.o
*.out
+58 -2
View File
@@ -1,8 +1,12 @@
# nix-homebrew (WIP)
# nix-homebrew
`nix-homebrew` manages Homebrew installations on macOS using [nix-darwin](https://github.com/LnL7/nix-darwin).
It pins the Homebrew version and optionally allows for declarative specification of taps.
`nix-homebrew` only installs Homebrew itself and does not manage any package installed by it.
For declarative formula/cask management, use the [`homebrew.*` options](https://daiderd.com/nix-darwin/manual/index.html#opt-homebrew.enable) in nix-darwin which work well in tandem with `nix-homebrew`.
## Quick Start
First of all, you must have [nix-darwin](https://github.com/LnL7/nix-darwin) configured already.
@@ -11,7 +15,7 @@ Add the following to your Flake inputs:
```nix
{
inputs = {
nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew";
nix-homebrew.url = "github:zhaofengli/nix-homebrew";
# Optional: Declarative tap management
homebrew-core = {
@@ -60,8 +64,23 @@ If you haven't installed Homebrew before, use the following configuration:
#
# With mutableTaps disabled, taps can no longer be added imperatively with `brew tap`.
mutableTaps = false;
# Optional: Declarative Homebrew tap trust entries.
#
# Note: The trust entries are _not_ removed if you remove them from those lists!
# Use the `brew untrust` command to remove a trust entry.
trust = {
formulae = [ ];
casks = [ ];
commands = [ ];
taps = [ ];
};
};
}
# Optional: Align homebrew taps config with nix-homebrew
({config, ...}: {
homebrew.taps = builtins.attrNames config.nix-homebrew.taps;
})
];
};
};
@@ -73,6 +92,27 @@ Run `arch -x86_64 brew` to install X86-64 packages through Rosetta 2.
With `nix-homebrew.mutableTaps = false`, taps can be removed by deleting the corresponding attribute in `nix-homebrew.taps` and activating the new configuration.
Setting `homebrew.taps` to equal `nix-homebrew.taps` attribute names reduces configuration mismatches.
For non-official taps, Homebrew requires [explicit trust](https://docs.brew.sh/Tap-Trust).
You may use imperative `brew trust`/`brew untrust` commands, or configure `nix-homebrew` to add trust entries during activation:
```nix
nix-homebrew.trust = {
formulae = [ "user/repo/formula" ];
casks = [ "user/repo/cask" ];
commands = [ "user/repo/command" ];
# To quote upstream documentation:
# > Trust a whole tap only when you are comfortable with all current and
# > future formulae, casks and external commands from that tap being loaded
# > by Homebrew.
taps = [ "user/repo" ];
};
```
Note that when you remove items from those lists, the corresponding trust entries are _not_ removed automatically.
Use the `brew untrust` command to remove a trust entry.
### B. Existing Homebrew Installation
If you've already installed Homebrew with the official script, you can let `nix-homebrew` automatically migrate it:
@@ -123,3 +163,19 @@ Extra prefixes may be configured:
```
Note that with a non-standard prefix, you will no longer be able to use most bottles (prebuilt packages).
## Declarative Taps
In Homebrew, the repo part of all taps always have `homebrew-` prepended.
- https://docs.brew.sh/Taps
- https://docs.brew.sh/Interesting-Taps-and-Forks
`brew tap <user>/<repo>` makes a clone of the repository at `https://github.com/<user>/homebrew-<repo>` into `$(brew --repository)/Library/Taps`.
When declaring taps, please ensure to name the key as a unique folder starting with `homebrew-`, e.g.:
```diff
nix-homebrew.taps = {
- "mtslzr/marmaduke-chromium" = inputs.marmaduke-chromium;
+ "mtslzr/homebrew-marmaduke-chromium" = inputs.marmaduke-chromium;
```
The exact GitHub `<user>/<repo>` should almost always work.
-20
View File
@@ -1,20 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
DIR=$(dirname $0)
if [[ "$#" != "1" ]]; then
>&2 echo "Usage: $0 [example]"
exit 1
fi
example="$1"
nix-instantiate --eval --json -E 'builtins.currentSystem' >"${DIR}/system.json"
systemProfile=$(nix build "./${DIR}/..#darwinConfigurations.ci.${example}.system" -L --no-link --print-out-paths)
>&2 echo "Built $systemProfile"
sudo "$systemProfile/activate"
"$systemProfile/activate-user"
# vim: set et ts=2 sw=2:
-25
View File
@@ -1,25 +0,0 @@
# Activates example configurations on CI
{ self, nix-darwin, nixpkgs, ... }:
let
system = builtins.fromJSON (builtins.readFile ./system.json);
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
makeProfile = example: nix-darwin.lib.darwinSystem {
inherit system pkgs;
modules = [
self.darwinModules.nix-homebrew
(../examples + "/${example}.nix")
{
documentation.enable = false;
services.nix-daemon.enable = true;
nix-homebrew = {
user = lib.mkForce "runner";
};
}
];
};
in {
migrate = makeProfile "migrate";
}
-1
View File
@@ -1 +0,0 @@
migrate
+11
View File
@@ -0,0 +1,11 @@
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
flakeCompat = import (fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
});
flake = flakeCompat {
src = ./.;
};
in
flake.defaultNix.outputs
Generated
+153
View File
@@ -0,0 +1,153 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1747046372,
"narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"nix-darwin_26_05": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1780789116,
"narHash": "sha256-+/LcDMJGYQVLp3ECZ1jBhj3GcQU+Yt+OTsDsQFz8cMs=",
"owner": "nix-darwin",
"repo": "nix-darwin",
"rev": "731951a251ca96cbd12a8e1bde63737e21947644",
"type": "github"
},
"original": {
"owner": "nix-darwin",
"ref": "nix-darwin-26.05",
"repo": "nix-darwin",
"type": "github"
}
},
"nix-darwin_unstable": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1773000227,
"narHash": "sha256-zm3ftUQw0MPumYi91HovoGhgyZBlM4o3Zy0LhPNwzXE=",
"owner": "nix-darwin",
"repo": "nix-darwin",
"rev": "da529ac9e46f25ed5616fd634079a5f3c579135f",
"type": "github"
},
"original": {
"owner": "nix-darwin",
"repo": "nix-darwin",
"type": "github"
}
},
"nix-github-actions": {
"inputs": {
"nixpkgs": [
"nixpkgs_unstable"
]
},
"locked": {
"lastModified": 1737420293,
"narHash": "sha256-F1G5ifvqTpJq7fdkT34e/Jy9VCyzd5XfJ9TO8fHhJWE=",
"owner": "nix-community",
"repo": "nix-github-actions",
"rev": "f4158fa080ef4503c8f4c820967d946c2af31ec9",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nix-github-actions",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1779622335,
"narHash": "sha256-ViA62qtL5za7V3d5I8OA9q9JcFhsVAiL5jVHwEclWqk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "705e9929918b43bd7b715dc0a878ac870449bb03",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-26.05-darwin",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1765934234,
"narHash": "sha256-pJjWUzNnjbIAMIc5gRFUuKCDQ9S1cuh3b2hKgA7Mc4A=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "af84f9d270d404c17699522fab95bbf928a2d92f",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_26_05": {
"locked": {
"lastModified": 1780902259,
"narHash": "sha256-q8yYEC5f1mFlQO9RGna4LTc9QrcvWunX6FYp83munkQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "bd0ff2d3eac24699c3664d5966b9ef36f388e2ca",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-26.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_unstable": {
"locked": {
"lastModified": 1774386573,
"narHash": "sha256-4hAV26quOxdC6iyG7kYaZcM3VOskcPUrdCQd/nx8obc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "46db2e09e1d3f113a13c0d7b81e2f221c63b8ce9",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"nix-darwin_26_05": "nix-darwin_26_05",
"nix-darwin_unstable": "nix-darwin_unstable",
"nix-github-actions": "nix-github-actions",
"nixpkgs_26_05": "nixpkgs_26_05",
"nixpkgs_unstable": "nixpkgs_unstable"
}
}
},
"root": "root",
"version": 7
}
+130
View File
@@ -0,0 +1,130 @@
# Only used for development & CI
{
inputs = {
nixpkgs_unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs_26_05.url = "github:NixOS/nixpkgs/nixos-26.05";
nix-darwin_unstable.url = "github:nix-darwin/nix-darwin";
nix-darwin_26_05.url = "github:nix-darwin/nix-darwin/nix-darwin-26.05";
nix-github-actions = {
url = "github:nix-community/nix-github-actions";
inputs.nixpkgs.follows = "nixpkgs_unstable";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs =
inputs:
let
inherit (inputs.nixpkgs_unstable) lib;
supportedSystems = [
"x86_64-darwin"
"aarch64-darwin"
];
releases = {
"unstable" = {
nixpkgs = inputs.nixpkgs_unstable;
nix-darwin = inputs.nix-darwin_unstable;
};
"26.05" = {
nixpkgs = inputs.nixpkgs_26_05;
nix-darwin = inputs.nix-darwin_26_05;
};
};
githubPlatforms = {
"aarch64-darwin" = "macos-26";
"x86_64-darwin" = "macos-26";
};
matrix =
let
names = {
release = builtins.attrNames releases;
test = builtins.attrNames (
import ./tests.nix {
self = null;
pkgs = null;
nix-darwin = null;
}
);
};
in
lib.pipe names [
lib.cartesianProduct
(map (setup: {
name = "${setup.test}-${setup.release}";
value = setup;
}))
lib.listToAttrs
];
forAllSystems =
f: lib.genAttrs supportedSystems (system: f inputs.nixpkgs_unstable.legacyPackages.${system});
makeCi =
{ self, brew-src }:
let
assembleTest =
{
system,
release,
test,
}:
let
inputs' = releases.${release};
pkgs = inputs'.nixpkgs.legacyPackages.${system};
tests = import ./tests.nix {
inherit self pkgs;
inherit (inputs') nix-darwin;
};
in
tests.${test};
ciTests = lib.genAttrs supportedSystems (
system:
lib.mapAttrs (
name:
{ release, test }:
assembleTest {
inherit system release test;
}
) matrix
);
ciScripts = lib.mapAttrs (
system: tests: lib.mapAttrs (name: test: test.config.system.build.ci-script) tests
) ciTests;
in
{
inherit ciTests;
packages = forAllSystems (
pkgs:
pkgs.callPackages (self + "/pkgs") {
inherit brew-src;
}
);
devShell = forAllSystems (
pkgs:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
nixfmt
];
BREW_SRC = brew-src;
}
);
githubActions = inputs.nix-github-actions.lib.mkGithubMatrix {
checks = ciScripts;
platforms = githubPlatforms;
};
};
in
{
inherit makeCi;
};
}
-1
View File
@@ -1 +0,0 @@
"migrate"
-1
View File
@@ -1 +0,0 @@
"aarch64-darwin"
+214
View File
@@ -0,0 +1,214 @@
{
self,
pkgs,
nix-darwin,
}:
let
inherit (pkgs) lib system;
tools = self.packages.${pkgs.system};
makeTest =
module:
nix-darwin.lib.darwinSystem {
inherit system pkgs;
modules = [
self.darwinModules.nix-homebrew
module
(
{
pkgs,
lib,
config,
...
}:
{
options = {
ci = {
preScript = lib.mkOption {
type = lib.types.lines;
default = "";
};
script = lib.mkOption {
type = lib.types.lines;
default = ''
sudo rm -f /etc/bashrc /etc/nix/nix.conf /etc/nix/nix.custom.conf
sudo "${config.system.build.toplevel}/activate"
export PATH=/run/current-system/sw/bin:$PATH
'';
};
postScript = lib.mkOption {
type = lib.types.lines;
default = "";
};
};
};
config = {
documentation.enable = false;
system.stateVersion = 6;
nix-homebrew = {
user = lib.mkForce "runner";
};
system.build.ci-script = pkgs.writeShellScript "ci-script.sh" ''
set -euo pipefail
if [[ -z "''${NIX_HOMEBREW_CI:-}" ]]; then
>&2 echo "This script can only be run on nix-homebrew CI."
exit 1
fi
set -x
${config.ci.preScript}
${config.ci.script}
${config.ci.postScript}
'';
};
}
)
];
};
makeTapValidationTest =
module:
makeTest (
{ pkgs, config, ... }:
let
prefixName =
if pkgs.stdenv.hostPlatform.isAarch64 then
config.nix-homebrew.defaultArm64Prefix
else
config.nix-homebrew.defaultIntelPrefix;
library = config.nix-homebrew.prefixes.${prefixName}.library;
fakeCaskTap = pkgs.runCommandLocal "homebrew-cask-test-tap" { } ''
mkdir -p "$out/Casks/u"
touch "$out/Casks/u/ungoogled-chromium.rb"
'';
fakeThirdPartyTap = pkgs.runCommandLocal "thirdparty-test-tap" { } ''
mkdir -p "$out/Formula" "$out/Casks" "$out/cmd"
touch "$out/Formula/foo.rb"
touch "$out/Casks/test-cask.rb"
touch "$out/cmd/brew-test-command.rb"
'';
in
{
imports = [
module
];
_module.args.library = library;
nix-homebrew = {
enable = true;
autoMigrate = true;
taps = {
"homebrew/homebrew-cask" = fakeCaskTap;
"thirdparty/homebrew-testtap" = fakeThirdPartyTap;
};
trust = {
formulae = [ "thirdparty/testtap/foo" ];
casks = [ "thirdparty/testtap/test-cask" ];
commands = [ "thirdparty/testtap/test-command" ];
};
};
ci.preScript = ''
>&2 echo "Removing runner Homebrew taps before declarative tap validation"
if [[ -e "${library}/Taps" || -L "${library}/Taps" ]]; then
sudo rm -rf "${library}/Taps"
fi
'';
ci.postScript = ''
>&2 echo "Checking declarative cask tap realpaths"
tap_root="${library}/Taps"
cask_path="$tap_root/homebrew/homebrew-cask/Casks/u/ungoogled-chromium.rb"
test -f "$cask_path"
>&2 echo "Checking declarative Homebrew trust entries"
brew trust --json=v1 --formula | grep '"thirdparty/testtap/foo"'
brew trust --json=v1 --cask | grep '"thirdparty/testtap/test-cask"'
brew trust --json=v1 --command | grep '"thirdparty/testtap/test-command"'
if brew trust --json=v1 --tap | grep '"thirdparty/testtap"'; then
>&2 echo "Expected thirdparty/testtap not to be trusted as a whole tap"
exit 1
fi
tap_root_real="$(${pkgs.coreutils}/bin/realpath "$tap_root")"
cask_real="$(${pkgs.coreutils}/bin/realpath "$cask_path")"
case "$cask_real" in
"$tap_root_real"/*) ;;
*)
>&2 echo "Expected cask realpath to stay under managed Taps root"
>&2 echo "Taps realpath: $tap_root_real"
>&2 echo "Cask realpath: $cask_real"
exit 1
;;
esac
'';
}
);
in
{
migrate = makeTest (
{ pkgs, config, ... }:
{
imports = [
(self + "/examples/migrate.nix")
];
nix-homebrew.enableRosetta = lib.mkForce pkgs.stdenv.hostPlatform.isAarch64;
# We only have Apple Silicon instances - Only test the install steps on native
# Apple Silicon for now
ci.preScript = lib.optionalString pkgs.stdenv.hostPlatform.isAarch64 ''
>&2 echo "Installing some package with Homebrew"
brew install unbound
>&2 echo "Adding a third-party tap imperatively"
brew tap koekeishiya/formulae
'';
ci.postScript = ''
>&2 echo "Checking brew"
which brew
''
+ lib.optionalString pkgs.stdenv.hostPlatform.isAarch64 ''
>&2 echo "Checking that we can still use the unbound package"
$(brew --prefix)/sbin/unbound -V
>&2 echo "Checking that we can still use the tap we added imperatively"
brew install koekeishiya/formulae/yabai
''
+ lib.optionalString config.nix-homebrew.enableRosetta ''
>&2 echo "Checking we can execute the Intel brew with arch -x86_64"
arch -x86_64 /usr/local/bin/brew config | grep "HOMEBREW_PREFIX: /usr/local"
>&2 echo "Checking that the unified brew launcher selects the correct prefix"
arch -arm64 brew config | grep "HOMEBREW_PREFIX: /opt/homebrew"
arch -x86_64 brew config | grep "HOMEBREW_PREFIX: /usr/local"
'';
}
);
tap-validation-mutable = makeTapValidationTest { };
tap-validation-declarative = makeTapValidationTest (
{ library, ... }:
{
nix-homebrew.mutableTaps = false;
ci.preScript = ''
>&2 echo "Removing runner Homebrew taps before declarative tap validation"
if [[ -e "${library}/Taps" || -L "${library}/Taps" ]]; then
sudo rm -rf "${library}/Taps"
fi
'';
}
);
nuke-homebrew-repository = makeTest {
ci.script = lib.mkForce ''
cat "${tools.nuke-homebrew-repository.passthru.tests.test-nuke}"
'';
};
}
+1
View File
@@ -4,6 +4,7 @@
{
nix-homebrew = {
enable = true;
enableRosetta = true;
autoMigrate = true;
user = "yourname";
};
Generated
+5 -88
View File
@@ -3,106 +3,23 @@
"brew-src": {
"flake": false,
"locked": {
"lastModified": 1687876440,
"narHash": "sha256-4hoGm5PUYmz091Pqrii4rpfsLsE7/gjIThHVBq6Vquk=",
"lastModified": 1784558651,
"narHash": "sha256-woXJ1ATKpSYRWCy46TQJjmm9XzAeZVEZw9xDfVG9NYI=",
"owner": "Homebrew",
"repo": "brew",
"rev": "eff45ef570f265e226f14ce91da72d7a6e7d516a",
"rev": "b48c7994b5f0eed7bef532efa63cb4e4f763887a",
"type": "github"
},
"original": {
"owner": "Homebrew",
"ref": "4.0.26",
"ref": "6.0.12",
"repo": "brew",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1687709756,
"narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nix-darwin": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1688307440,
"narHash": "sha256-7PTjbN+/+b799YN7Tk2SS5Vh8A0L3gBo8hmB7Y0VXug=",
"owner": "LnL7",
"repo": "nix-darwin",
"rev": "b06bab83bdf285ea0ae3c8e145a081eb95959047",
"type": "github"
},
"original": {
"owner": "LnL7",
"repo": "nix-darwin",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1687274257,
"narHash": "sha256-TutzPriQcZ8FghDhEolnHcYU2oHIG5XWF+/SUBNnAOE=",
"path": "/nix/store/22qgs3skscd9bmrxv9xv4q5d4wwm5ppx-source",
"rev": "2c9ecd1f0400076a4d6b2193ad468ff0a7e7fdc5",
"type": "path"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1688049487,
"narHash": "sha256-100g4iaKC9MalDjUW9iN6Jl/OocTDtXdeAj7pEGIRh4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4bc72cae107788bf3f24f30db2e2f685c9298dc9",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"brew-src": "brew-src",
"flake-utils": "flake-utils",
"nix-darwin": "nix-darwin",
"nixpkgs": "nixpkgs_2"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
"brew-src": "brew-src"
}
}
},
+17 -22
View File
@@ -2,39 +2,34 @@
description = "Homebrew installation manager for nix-darwin";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nix-darwin.url = "github:LnL7/nix-darwin";
flake-utils.url = "github:numtide/flake-utils";
brew-src = {
url = "github:Homebrew/brew/4.0.26";
url = "github:Homebrew/brew/6.0.12";
flake = false;
};
};
outputs = { self, nixpkgs, nix-darwin, flake-utils, brew-src, ... } @ inputs: let
# System types to support.
supportedSystems = [ "x86_64-darwin" "aarch64-darwin" ];
in flake-utils.lib.eachSystem supportedSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
outputs = { self, brew-src }: let
flakeLock = builtins.fromJSON (builtins.readFile ./flake.lock);
brewVersion = flakeLock.nodes.brew-src.original.ref;
ci = (import ./ci/flake-compat.nix).makeCi {
inherit self brew-src;
};
in {
packages = pkgs.callPackage ./pkgs {
inherit inputs;
};
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
];
};
}) // {
darwinModules = {
darwinModules = rec {
nix-homebrew = { lib, ... }: {
imports = [
./modules
];
nix-homebrew.package = lib.mkOptionDefault brew-src.outPath;
nix-homebrew.package = lib.mkOptionDefault (brew-src // {
name = "brew-${brewVersion}";
version = brewVersion;
});
};
default = nix-homebrew;
};
darwinConfigurations = {
ci = import ./ci inputs;
};
inherit (ci) packages devShell ciTests githubActions;
};
}
+233
View File
@@ -0,0 +1,233 @@
# -----
# The following is copied from upstream bin/brew
# Copyright (c) 2009-present, Homebrew contributors
# -----
# nix-homebrew:
# Run scripts/update-brew-tail.sh to update this
# These variables are exported in this file and are not allowed to be overridden by the user.
BIN_BREW_EXPORTED_VARS=(
HOMEBREW_BREW_FILE
HOMEBREW_PREFIX
HOMEBREW_REPOSITORY
HOMEBREW_LIBRARY
HOMEBREW_USER_CONFIG_HOME
HOMEBREW_ORIGINAL_BREW_FILE
)
BIN_BREW_EXPORTED_VARS_REGEX="^($(
IFS='|'
echo "${BIN_BREW_EXPORTED_VARS[*]}"
))(=|$)"
# Load Homebrew's variable configuration files from disk.
export_homebrew_env_file() {
local env_file
env_file="${1}"
[[ -r "${env_file}" ]] || return 0
while read -r line
do
# only load variables defined in env_config.rb
[[ "${line}" =~ ^(HOMEBREW_|SUDO_ASKPASS=|(all|no|ftp|https?)_proxy=) ]] || continue
# forbid overriding variables that are set in this file
[[ "${line}" =~ ${BIN_BREW_EXPORTED_VARS_REGEX} ]] && continue
if [[ "${line}" == HOMEBREW_EXPERIMENTAL_RUST_FRONTEND=* ]]
then
echo "Warning: Ignoring HOMEBREW_EXPERIMENTAL_RUST_FRONTEND. This cannot be set in an env file." >&2
continue
fi
export "${line?}"
done <"${env_file}"
}
# We only want to be able to set this in `brew.env` files.
unset HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER
# First, load the system-wide configuration.
export_homebrew_env_file "/etc/homebrew/brew.env"
unset SYSTEM_ENV_TAKES_PRIORITY
if [[ -n "${HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY-}" ]]
then
SYSTEM_ENV_TAKES_PRIORITY="1"
fi
# Next, load the prefix configuration
export_homebrew_env_file "${HOMEBREW_PREFIX}/etc/homebrew/brew.env"
# Finally, load the user configuration
if [[ -n "${XDG_CONFIG_HOME-}" ]]
then
HOMEBREW_USER_CONFIG_HOME="${XDG_CONFIG_HOME}/homebrew"
elif [[ -n "${HOMEBREW_XDG_CONFIG_HOME-}" ]]
then
HOMEBREW_USER_CONFIG_HOME="${HOMEBREW_XDG_CONFIG_HOME}/homebrew"
else
HOMEBREW_USER_CONFIG_HOME="${HOME}/.homebrew"
fi
export_homebrew_env_file "${HOMEBREW_USER_CONFIG_HOME}/brew.env"
# If the system configuration takes priority, load it again to override any previous settings.
if [[ -n "${SYSTEM_ENV_TAKES_PRIORITY-}" ]]
then
export_homebrew_env_file "/etc/homebrew/brew.env"
fi
# Use HOMEBREW_FORCE_BREW_WRAPPER if set.
export HOMEBREW_ORIGINAL_BREW_FILE="${HOMEBREW_BREW_FILE}"
if [[ -n "${HOMEBREW_FORCE_BREW_WRAPPER:-}" ]]
then
HOMEBREW_BREW_FILE="${HOMEBREW_FORCE_BREW_WRAPPER}"
fi
# Copy and export all HOMEBREW_* variables previously mentioned in
# manpage or used elsewhere by Homebrew.
# These variables are allowed to be set by the user as, e.g., `HOMEBREW_BROWSER`.
MANPAGE_VARS=(
BAT_CONFIG_PATH
BAT_THEME
BROWSER
BUNDLE_USER_CACHE
DISPLAY
EDITOR
NO_COLOR
)
for VAR in "${MANPAGE_VARS[@]}"
do
# Skip if variable value is empty or set to 0.
[[ -z "${!VAR:-}" || "${!VAR:-}" = "0" ]] && continue
VAR_NEW="HOMEBREW_${VAR}"
# Skip if existing HOMEBREW_* variable is set.
[[ -n "${!VAR_NEW:-}" ]] && continue
export "${VAR_NEW}"="${!VAR}"
done
# We don't want to take the user's value for, e.g., `HOMEBREW_PATH` here!
USED_BY_HOMEBREW_VARS=(
CARGO_HOME
CARGO_INSTALL_ROOT
CODESPACES
COLORTERM
DBUS_SESSION_BUS_ADDRESS
GOBIN
GOPATH
LANG
NODENV_ROOT
PATH
PYENV_ROOT
RBENV_ROOT
RUSTUP_HOME
SSH_TTY
SUDO_USER
TMPDIR
TMUX
VSCODE_IPC_HOOK_CLI
WSL_DISTRO_NAME
XDG_CACHE_HOME
XDG_CONFIG_HOME
XDG_DATA_DIRS
XDG_DATA_HOME
XDG_RUNTIME_DIR
ZDOTDIR
)
for VAR in "${USED_BY_HOMEBREW_VARS[@]}"
do
# Skip if variable value is empty.
[[ -z "${!VAR:-}" ]] && continue
# We unconditionally override `HOMEBREW_*` here.
VAR_NEW="HOMEBREW_${VAR}"
export "${VAR_NEW}"="${!VAR}"
done
unset VAR VAR_NEW MANPAGE_VARS USED_BY_HOMEBREW_VARS
for VAR in "${BIN_BREW_EXPORTED_VARS[@]}"
do
export "${VAR?}"
done
# set from user environment
# shellcheck disable=SC2154
# Use VISUAL if HOMEBREW_EDITOR and EDITOR are unset.
if [[ -z "${HOMEBREW_EDITOR:-}" && -n "${VISUAL:-}" ]]
then
export HOMEBREW_EDITOR="${VISUAL}"
fi
# set from user environment
# shellcheck disable=SC2154
# Set CI variable for Azure Pipelines and Jenkins
# (Set by default on GitHub Actions, Circle and Travis CI)
if [[ -z "${CI:-}" ]] && [[ -n "${TF_BUILD:-}" || -n "${JENKINS_HOME:-}" ]]
then
export CI="1"
fi
if [[ -n "${GITHUB_ACTIONS:-}" && -n "${ImageOS:-}" && -n "${ImageVersion:-}" ]]
then
export HOMEBREW_GITHUB_HOSTED_RUNNER=1
fi
# don't filter the environment for `brew bundle (exec|env|sh)`
if [[ "${1:-}" == "bundle" ]]
then
if [[ "${2:-}" == "exec" || "${2:-}" == "env" || "${2:-}" == "sh" ]]
then
exec /bin/bash -p "${HOMEBREW_LIBRARY}/Homebrew/brew.sh" "$@"
exit $?
fi
fi
# filter the user environment
PATH="@runtimePath@:/usr/bin:/bin:/usr/sbin:/sbin"
FILTERED_ENV=()
ENV_VAR_NAMES=(
HOME SHELL PATH TERM TERMINFO TERMINFO_DIRS COLUMNS DISPLAY LOGNAME USER CI SSH_AUTH_SOCK SUDO_ASKPASS
http_proxy https_proxy ftp_proxy no_proxy all_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY
)
# Filter all but the specific variables.
for VAR in "${ENV_VAR_NAMES[@]}" "${!HOMEBREW_@}"
do
# Skip if variable value is empty.
[[ -z "${!VAR:-}" ]] && continue
FILTERED_ENV+=("${VAR}=${!VAR}")
done
if [[ -n "${CI:-}" ]]
then
for VAR in "${!GITHUB_@}"
do
# Skip if variable value is empty.
[[ -z "${!VAR:-}" ]] && continue
# Skip variables that look like tokens.
[[ "${VAR}" = *TOKEN* ]] && continue
FILTERED_ENV+=("${VAR}=${!VAR}")
done
fi
if [[ -n "${HOMEBREW_RDBG:-}" ]]
then
for VAR in "${!RUBY_DEBUG_@}"
do
# Skip if variable value is empty.
[[ -z "${!VAR:-}" ]] && continue
FILTERED_ENV+=("${VAR}=${!VAR}")
done
fi
unset VAR ENV_VAR_NAMES
exec /usr/bin/env -i "${FILTERED_ENV[@]}" /bin/bash -p "${HOMEBREW_LIBRARY}/Homebrew/brew.sh" "$@"
+192 -128
View File
@@ -22,7 +22,7 @@
# that automatically selects the correct prefix based on the architecture.
# Use `arch -x86_64 brew` to install X86-64 packages.
{ pkgs, lib, config, ... }:
{ pkgs, lib, config, options, ... }:
let
inherit (lib) types;
@@ -35,16 +35,21 @@ let
tools = pkgs.callPackage ../pkgs { };
brew = if cfg.patchBrew then patchBrew cfg.package else cfg.package;
ruby = pkgs.ruby_4_0;
# Sadly, we cannot replace coreutils since the GNU implementations
# behave differently.
runtimePath = lib.makeBinPath [ pkgs.gitMinimal ];
prefixType = types.submodule ({ name, ... }: {
options = {
enable = lib.mkOption {
description = lib.mdDoc ''
description = ''
Whether to set up this Homebrew prefix.
'';
};
prefix = lib.mkOption {
description = lib.mdDoc ''
description = ''
The Homebrew prefix.
By default, it's `/opt/homebrew` for Apple Silicon Macs and
@@ -54,7 +59,7 @@ let
default = name;
};
library = lib.mkOption {
description = lib.mdDoc ''
description = ''
The Homebrew library.
By default, it's `/opt/homebrew/Library` for Apple Silicon Macs and
@@ -63,7 +68,7 @@ let
type = types.str;
};
taps = lib.mkOption {
description = lib.mdDoc ''
description = ''
A set of Nix-managed taps.
'';
type = types.attrsOf types.package;
@@ -85,7 +90,7 @@ let
# Our unified brew launcher script.
#
# We use `/bin/bash` (Bash 3.2 :/) instead of `${runtimeShell}`
# for compatibility with `arch -x86_64`.
# for compatibility with `arch -x86_64`.
brewLauncher = pkgs.writeScriptBin "brew" (''
#!/bin/bash
set -euo pipefail
@@ -124,111 +129,23 @@ let
'' + lib.optionalString (prefix.taps ? "homebrew/homebrew-core") ''
# Disable API to use pinned homebrew-core
export HOMEBREW_NO_INSTALL_FROM_API=1
'' + ''
# -----
# The following is copied from upstream bin/brew
# Copyright (c) 2009-present, Homebrew contributors
# -----
# Copy and export all HOMEBREW_* variables previously mentioned in
# manpage or used elsewhere by Homebrew.
# These variables are allowed to be set by the user as, e.g., `HOMEBREW_BROWSER`.
MANPAGE_VARS=(
BAT_CONFIG_PATH
BAT_THEME
BROWSER
DISPLAY
EDITOR
NO_COLOR
)
for VAR in "''${MANPAGE_VARS[@]}"
do
# Skip if variable value is empty.
[[ -z "''${!VAR:-}" ]] && continue
VAR_NEW="HOMEBREW_''${VAR}"
# Skip if existing HOMEBREW_* variable is set.
[[ -n "''${!VAR_NEW:-}" ]] && continue
export "''${VAR_NEW}"="''${!VAR}"
done
# We don't want to take the user's value for, e.g., `HOMEBREW_PATH` here!
USED_BY_HOMEBREW_VARS=(
CODESPACES
DBUS_SESSION_BUS_ADDRESS
PATH
TMUX
XDG_RUNTIME_DIR
)
for VAR in "''${USED_BY_HOMEBREW_VARS[@]}"
do
# Skip if variable value is empty.
[[ -z "''${!VAR:-}" ]] && continue
# We unconditionally override `HOMEBREW_*` here.
VAR_NEW="HOMEBREW_''${VAR}"
export "''${VAR_NEW}"="''${!VAR}"
done
unset VAR VAR_NEW MANPAGE_VARS USED_BY_HOMEBREW_VARS
# set from user environment
# shellcheck disable=SC2154
# Use VISUAL if HOMEBREW_EDITOR and EDITOR are unset.
if [[ -z "''${HOMEBREW_EDITOR:-}" && -n "''${VISUAL:-}" ]]
then
export HOMEBREW_EDITOR="''${VISUAL}"
fi
# set from user environment
# shellcheck disable=SC2154
# Set CI variable for Azure Pipelines and Jenkins
# (Set by default on GitHub Actions, Circle and Travis CI)
if [[ -z "''${CI:-}" ]] && [[ -n "''${TF_BUILD:-}" || -n "''${JENKINS_HOME:-}" ]]
then
export CI="1"
fi
# filter the user environment
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
FILTERED_ENV=()
ENV_VAR_NAMES=(
HOME SHELL PATH TERM TERMINFO TERMINFO_DIRS COLUMNS DISPLAY LOGNAME USER CI SSH_AUTH_SOCK SUDO_ASKPASS
http_proxy https_proxy ftp_proxy no_proxy all_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY
)
# Filter all but the specific variables.
for VAR in "''${ENV_VAR_NAMES[@]}" "''${!HOMEBREW_@}"
do
# Skip if variable value is empty.
[[ -z "''${!VAR:-}" ]] && continue
FILTERED_ENV+=("''${VAR}=''${!VAR}")
done
if [[ -n "''${CI:-}" ]]
then
for VAR in "''${!GITHUB_@}"
do
# Skip if variable value is empty.
[[ -z "''${!VAR:-}" ]] && continue
# Skip variables that look like tokens.
[[ "''${VAR}" = *TOKEN* ]] && continue
FILTERED_ENV+=("''${VAR}=''${!VAR}")
done
fi
unset VAR ENV_VAR_NAMES
exec /usr/bin/env -i "''${FILTERED_ENV[@]}" /bin/bash "''${HOMEBREW_LIBRARY}/Homebrew/brew.sh" "$@"
'');
in pkgs.substituteAll {
'' + (lib.optionalString (cfg.extraEnv != {})
(lib.concatLines (lib.mapAttrsToList (name: value: "export ${name}=${lib.escapeShellArg value}") cfg.extraEnv)))
+ (builtins.readFile ./brew.tail.sh));
in pkgs.replaceVarsWith {
name = "brew";
src = template;
isExecutable = true;
inherit (prefix) prefix library;
# Must retain #!/bin/bash, otherwise `arch -x86_64 /usr/local/bin/brew`
# on Apple Silicon will not work.
dontPatchShebangs = true;
replacements = {
out = placeholder "out";
inherit runtimePath;
inherit (prefix) prefix library;
};
};
setupHomebrew = let
@@ -270,7 +187,7 @@ let
if test -n "${toString cfg.enableRosetta}" && ! pgrep -q oahd; then
warn "The Intel Homebrew prefix has been set up, but Rosetta isn't installed yet."
ohai 'Run ''${tty_bold}softwareupdate --install-rosetta''${tty_reset} to install it.'
ohai "Run ''${tty_bold}softwareupdate --install-rosetta''${tty_reset} to install it."
fi
'';
@@ -326,6 +243,7 @@ let
"''${MKDIR[@]}" "$HOMEBREW_LIBRARY/.homebrew-is-managed-by-nix/.git"
"''${CHOWN[@]}" "$NIX_HOMEBREW_UID:$NIX_HOMEBREW_GID" "$HOMEBREW_LIBRARY/.homebrew-is-managed-by-nix"
"''${CHMOD[@]}" 775 "$HOMEBREW_LIBRARY/.homebrew-is-managed-by-nix/"{,.git}
"''${TOUCH[@]}" "$HOMEBREW_LIBRARY/.homebrew-is-managed-by-nix/.git/HEAD"
# Link generated bin/brew
BIN_BREW="$HOMEBREW_PREFIX/bin/brew"
@@ -334,6 +252,19 @@ let
exit 1
fi
/bin/ln -shf "${makeBinBrew prefix}" "$BIN_BREW"
${setupTrust}
'';
setupTrust = let
trustEntries = flag: entries: lib.concatMapStrings (entry: ''
/usr/bin/sudo -n -u ${lib.escapeShellArg cfg.user} -H "$BIN_BREW" trust ${flag} ${lib.escapeShellArg entry} >/dev/null
'') entries;
in ''
${trustEntries "--tap" cfg.trust.taps}
${trustEntries "--formula" cfg.trust.formulae}
${trustEntries "--cask" cfg.trust.casks}
${trustEntries "--command" cfg.trust.commands}
'';
setupTaps = taps:
@@ -350,24 +281,31 @@ let
error "$tty_underline${namespaceDir}$tty_reset is in the way and needs to be moved out for $tty_underline${path}$tty_reset"
exit 1
fi
if is_occupied "${tapDir}"; then
if [[ -L "${tapDir}" ]]; then
rm "${tapDir}"
elif [[ -d "${tapDir}" ]]; then
:
# directory
elif is_occupied "${tapDir}"; then
error "An existing $tty_underline${tapDir}$tty_reset is in the way"
exit 1
fi
"''${MKDIR[@]}" "${namespaceDir}"
"''${CHOWN[@]}" "$NIX_HOMEBREW_UID:$NIX_HOMEBREW_GID" "${namespaceDir}"
"''${CHMOD[@]}" "ug=rwx" "${namespaceDir}"
/bin/ln -shf "${target}" "${tapDir}"
/usr/bin/rsync -rL --delete "${target}/" "${tapDir}"
'') (builtins.attrNames taps)
# Fully declarative taps
else let
env = pkgs.runCommandLocal "taps-env" {} (lib.concatMapStrings (path: let
env = pkgs.runCommandLocal "taps-env" { } (''
mkdir -p "$out"
'' + lib.concatMapStrings (path: let
namespace = builtins.head (lib.splitString "/" path);
target = taps.${path};
in ''
mkdir -p "$out/${namespace}"
ln -s "${target}" "$out/${path}"
cp -RH "${target}" "$out/${path}"
'') (builtins.attrNames taps));
in ''
if is_occupied "$HOMEBREW_LIBRARY/Taps"; then
@@ -378,19 +316,41 @@ let
/bin/ln -shf "${env}" "$HOMEBREW_LIBRARY/Taps"
'';
# Patch Homebrew to disable self-update behavior
patchBrew = brew: pkgs.runCommandLocal "${brew.name or "brew"}-patched" {} ''
patchBrew = brew: pkgs.runCommandLocal "${brew.name or "brew"}-patched" {} (''
cp -r "${brew}" "$out"
chmod u+w "$out" "$out/Library/Homebrew/cmd"
# Disable self-update behavior
substituteInPlace "$out/Library/Homebrew/cmd/update.sh" \
--replace 'for DIR in "''${HOMEBREW_REPOSITORY}"' "for DIR in "
'';
--replace-fail 'for DIR in "''${HOMEBREW_REPOSITORY}"' "for DIR in "
# Disable vendored Ruby
#
# Homebrew passes --disable=gems,rubyopt ($HOMEBREW_RUBY_DISABLE_OPTIONS)
# and inserts vendored libraries into LOAD_PATH (vendor/bundle/bundler/setup.rb, standalone/init.rb).
# Instead of re-enabling gems, we add in additional required gems into LOAD_PATH.
ruby_sh="$out/Library/Homebrew/utils/ruby.sh"
bundler_setup_rb="$out/Library/Homebrew/vendor/bundle/bundler/setup.rb"
if [[ -e "$ruby_sh" ]] && grep "setup-ruby-path" "$ruby_sh" >/dev/null; then
>&2 echo "Patching vendored Ruby..."
chmod u+w "$ruby_sh" "$bundler_setup_rb"
echo -e "setup-ruby-path() { export HOMEBREW_RUBY_PATH=\"${ruby}/bin/ruby\"; }" >>"$ruby_sh"
echo -e "$:.unshift \"${ruby.gems.fiddle}/${ruby.gemPath}/gems/fiddle-${ruby.gems.fiddle.version}/lib\"" >>"$bundler_setup_rb"
fi
'' + lib.optionalString (brew ? version) ''
# Embed version number instead of checking with git
brew_sh="$out/Library/Homebrew/brew.sh"
chmod u+w "$out/Library/Homebrew" "$brew_sh"
sed -i -e 's/^HOMEBREW_VERSION=.*/HOMEBREW_VERSION="${brew.version}"/g' "$brew_sh"
# 4.3.5: Clear GIT_REVISION to bypass caching mechanism
sed -i -e 's/^GIT_REVISION=.*/GIT_REVISION=""; HOMEBREW_VERSION="${brew.version}"/g' "$brew_sh"
'');
in {
options = {
nix-homebrew = {
enable = lib.mkOption {
description = lib.mdDoc ''
description = ''
Whether to install Homebrew.
'';
type = types.bool;
@@ -406,13 +366,13 @@ in {
default = false;
};
package = lib.mkOption {
description = lib.mdDoc ''
description = ''
The homebrew package itself.
'';
type = types.package;
};
taps = lib.mkOption {
description = lib.mdDoc ''
description = ''
A set of Nix-managed taps.
These are applied to the default prefixes.
@@ -431,7 +391,7 @@ in {
'';
};
mutableTaps = lib.mkOption {
description = lib.mdDoc ''
description = ''
Whether to allow imperative management of taps.
When enabled, taps can be managed via `brew tap` and
@@ -443,6 +403,68 @@ in {
type = types.bool;
default = true;
};
trust = lib.mkOption {
description = ''
Tap trust entries to be added during activation.
Note: The trust entries are _not_ removed if you remove them from
those lists! Use the `brew untrust` command to remove a trust entry.
Refer to upstream documentations for more information:
<https://docs.brew.sh/Tap-Trust>
'';
type = types.submodule {
options = {
taps = lib.mkOption {
description = ''
Taps to trust in their entirety.
This should be used with caution. To quote upstream documentation:
> Trust a whole tap only when you are comfortable with all current and
> future formulae, casks and external commands from that tap being loaded
> by Homebrew.
'';
type = types.listOf types.str;
default = [];
example = [
"user/repo"
];
};
formulae = lib.mkOption {
description = ''
Fully-qualified formulae to trust.
'';
type = types.listOf types.str;
default = [];
example = [
"user/repo/formula"
];
};
casks = lib.mkOption {
description = ''
Fully-qualified casks to trust.
'';
type = types.listOf types.str;
default = [];
example = [
"user/repo/cask"
];
};
commands = lib.mkOption {
description = ''
Fully-qualified external commands to trust.
'';
type = types.listOf types.str;
default = [];
example = [
"user/repo/command"
];
};
};
};
default = {};
};
autoMigrate = lib.mkOption {
description = ''
Whether to allow nix-homebrew to automatically migrate existing Homebrew installations.
@@ -454,13 +476,13 @@ in {
default = false;
};
user = lib.mkOption {
description = lib.mdDoc ''
description = ''
The user owning the Homebrew directories.
'';
type = types.str;
};
group = lib.mkOption {
description = lib.mdDoc ''
description = ''
The group owning the Homebrew directories.
'';
type = types.str;
@@ -479,7 +501,7 @@ in {
type = types.attrsOf prefixType;
};
defaultArm64Prefix = lib.mkOption {
description = lib.mdDoc ''
description = ''
Key of the default Homebrew prefix for ARM64 macOS.
'';
internal = true;
@@ -487,7 +509,7 @@ in {
default = "/opt/homebrew";
};
defaultIntelPrefix = lib.mkOption {
description = lib.mdDoc ''
description = ''
Key of the default Homebrew prefix for Intel macOS or Rosetta 2.
'';
internal = true;
@@ -495,7 +517,7 @@ in {
default = "/usr/local";
};
extraEnv = lib.mkOption {
description = lib.mdDoc ''
description = ''
Extra environment variables to set for Homebrew.
'';
type = types.attrsOf types.str;
@@ -513,6 +535,19 @@ in {
type = types.bool;
default = true;
};
# Shell integrations
enableBashIntegration = lib.mkEnableOption "homebrew bash integration" // {
default = true;
};
enableFishIntegration = lib.mkEnableOption "homebrew fish integration" // {
default = true;
};
enableZshIntegration = lib.mkEnableOption "homebrew zsh integration" // {
default = true;
};
};
};
@@ -522,6 +557,12 @@ in {
assertion = cfg.enableRosetta -> pkgs.stdenv.hostPlatform.isAarch64;
message = "nix-homebrew.enableRosetta is set to true but this isn't an Apple Silicon Mac";
}
{
# nix-darwin has migrated away from user activation in
# <https://github.com/LnL7/nix-darwin/pull/1341>.
assertion = options.system ? primaryUser;
message = "Please update your nix-darwin version to use system-wide activation";
}
];
nix-homebrew = {
@@ -539,15 +580,38 @@ in {
};
};
# Shell integrations
programs.bash.interactiveShellInit = lib.mkIf cfg.enableBashIntegration ''
eval "$(brew shellenv 2>/dev/null || true)"
'';
programs.zsh.interactiveShellInit = lib.mkIf cfg.enableZshIntegration ''
eval "$(brew shellenv 2>/dev/null || true)"
'';
programs.fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration ''
brew shellenv 2>/dev/null | source || true
'';
environment.systemPackages = [ brewLauncher ];
system.activationScripts = {
# We set up a new system activation step that sets up Homebrew
extraUserActivation.text = lib.mkAfter ''
# Set up the Homebrew prefixes before nix-darwin's homebrew
# activation takes place.
homebrew.text = lib.mkBefore ''
${config.system.activationScripts.setup-homebrew.text}
'';
setup-homebrew.text = ''
sudo ${setupHomebrew}
>&2 echo "setting up Homebrew prefixes..."
${setupHomebrew}
'';
};
# disable the install homebrew check
# see https://github.com/LnL7/nix-darwin/pull/1178 and https://github.com/zhaofengli/nix-homebrew/issues/45
system.checks.text = lib.mkIf config.homebrew.enable (lib.mkBefore ''
# Ignore unused variable in nix-darwin versions without it
# shellcheck disable=SC2034
INSTALLING_HOMEBREW=1
'');
};
}
+2 -2
View File
@@ -1,6 +1,6 @@
{ callPackage, inputs ? {} }:
{ callPackage, brew-src ? null }:
{
nuke-homebrew-repository = callPackage ./nuke-homebrew-repository {
inherit inputs;
inherit brew-src;
};
}
+10 -8
View File
@@ -1,6 +1,6 @@
{ lib
, pkgs
, substituteAll
, replaceVarsWith
, runtimeShell
, coreutils
, findutils
@@ -8,23 +8,25 @@
, gnused
, gitMinimal
, inputs
, brew-src ? null
, runCommandLocal
}:
let
script = substituteAll {
script = replaceVarsWith {
name = "nuke-homebrew-repository";
src = ./nuke-homebrew-repository.sh.in;
isExecutable = true;
inherit runtimeShell;
path = lib.makeBinPath [ coreutils findutils gnugrep gnused gitMinimal ];
replacements = {
inherit runtimeShell;
path = lib.makeBinPath [ coreutils findutils gnugrep gnused gitMinimal ];
};
};
brew-src = inputs.brew-src or (throw "The tests can only be run with flakes");
test-nuke = runCommandLocal "test-nuke" {
test-nuke =
assert (lib.assertMsg (brew-src != null) "brew-src must be provided");
runCommandLocal "test-nuke" {
nativeBuildInputs = [ gitMinimal ];
} ''
must_exist() {
@@ -30,7 +30,7 @@ if [[ ! -e ".git" ]]; then
exit 1
fi
if ! grep -E "^# Homebrew" "README.md" >/dev/null; then
if ! grep -E "^#.*Homebrew" "README.md" >/dev/null; then
>&2 echo "${PWD} does not looks like a Homebrew checkout"
exit 1
fi
@@ -45,6 +45,11 @@ done < <(git ls-files)
printf "%s\0" "${files_to_delete[@]}" | xargs -0 rm
if [[ -e "Library/Homebrew/vendor" ]]; then
>&2 echo "Removing stray vendor directory"
rm -rf --one-file-system "Library/Homebrew/vendor"
fi
# Next, delete all directories
while read -r dir; do
if [[ -d "$dir" ]]; then
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
: "${BREW_SRC:=}"
root="$(dirname $0)/.."
brew_tail="$root/modules/brew.tail.sh"
brew_upstream="${BREW_SRC}/bin/brew"
if [[ -z "${BREW_SRC}" ]]; then
>&2 echo "\$BREW_SRC must be set"
exit 1
fi
>&2 echo "Updating ${brew_tail} using ${brew_upstream}"
cat >"${brew_tail}" <<EOF
# -----
# The following is copied from upstream bin/brew
# Copyright (c) 2009-present, Homebrew contributors
# -----
# nix-homebrew:
# Run scripts/update-brew-tail.sh to update this
EOF
sed \
-e '1,/^HOMEBREW_LIBRARY=/d' \
-e 's/^PATH="/PATH="@runtimePath@:/' \
"${brew_upstream}" >>"${brew_tail}"