No description
  • Nix 68.3%
  • Shell 31.7%
Find a file
Zhaofeng Li 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
.github/workflows .github: Switch to samueldr/lix-gha-installer-action 2025-11-22 09:49:32 -05:00
ci ci: Bump deps 2025-08-03 13:56:33 -06:00
examples examples/migrate: Enable Rosetta 2024-11-15 08:33:25 -07:00
modules brew-src: 4.6.19 -> 5.0.3 2025-11-29 22:21:23 -05:00
pkgs Reapply "refactor: substituteAll -> replaceVars" 2025-05-26 09:17:46 -06:00
scripts Inject own runtimePath to brew.sh 2024-01-22 12:26:10 -07:00
.envrc Initial WIP 2023-07-01 02:22:36 -06:00
.gitignore ci: Delete stray files 2024-11-15 08:33:25 -07:00
flake.lock brew-src: 5.0.3 -> 5.0.12 2026-01-26 09:07:41 -05:00
flake.nix brew-src: 5.0.3 -> 5.0.12 2026-01-26 09:07:41 -05:00
LICENSE Initial WIP 2023-07-01 02:22:36 -06:00
README.md Update README.md 2025-07-31 13:26:40 -06:00

nix-homebrew

nix-homebrew manages Homebrew installations on macOS using 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 in nix-darwin which work well in tandem with nix-homebrew.

Quick Start

First of all, you must have nix-darwin configured already. Add the following to your Flake inputs:

{
  inputs = {
    nix-homebrew.url = "github:zhaofengli/nix-homebrew";

    # Optional: Declarative tap management
    homebrew-core = {
      url = "github:homebrew/homebrew-core";
      flake = false;
    };
    homebrew-cask = {
      url = "github:homebrew/homebrew-cask";
      flake = false;
    };

    # (...)
  };
}

A. New Installation

If you haven't installed Homebrew before, use the following configuration:

{
  output = { self, nixpkgs, darwin, nix-homebrew, homebrew-core, homebrew-cask, ... }: {
    darwinConfigurations.macbook = {
      # (...)
      modules = [
        nix-homebrew.darwinModules.nix-homebrew
        {
          nix-homebrew = {
            # Install Homebrew under the default prefix
            enable = true;

            # Apple Silicon Only: Also install Homebrew under the default Intel prefix for Rosetta 2
            enableRosetta = true;

            # User owning the Homebrew prefix
            user = "yourname";

            # Optional: Declarative tap management
            taps = {
              "homebrew/homebrew-core" = homebrew-core;
              "homebrew/homebrew-cask" = homebrew-cask;
            };

            # Optional: Enable fully-declarative tap management
            #
            # With mutableTaps disabled, taps can no longer be added imperatively with `brew tap`.
            mutableTaps = false;
          };
        }
        # Optional: Align homebrew taps config with nix-homebrew
        ({config, ...}: {
          homebrew.taps = builtins.attrNames config.nix-homebrew.taps;
        })
      ];
    };
  };
}

Once activated, a unified brew launcher will be created under /run/current-system/sw/bin that automatically selects the correct Homebrew prefix to use based on the architecture. 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.

B. Existing Homebrew Installation

If you've already installed Homebrew with the official script, you can let nix-homebrew automatically migrate it:

{
  output = { self, darwin, nix-homebrew, ... }: {
    darwinConfigurations.macbook = {
      # (...)
      modules = [
        nix-homebrew.darwinModules.nix-homebrew
        {
          nix-homebrew = {
            # Install Homebrew under the default prefix
            enable = true;

            # Apple Silicon Only: Also install Homebrew under the default Intel prefix for Rosetta 2
            enableRosetta = true;

            # User owning the Homebrew prefix
            user = "yourname";

            # Automatically migrate existing Homebrew installations
            autoMigrate = true;
          };
        }
      ];
    };
  };
}

Non-Standard Prefixes

Extra prefixes may be configured:

{
  nix-homebrew.prefixes = {
    "/some/prefix" = {
      library = "/some/prefix/Library";
      taps = {
        # ...
      };
    };
  };
}

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.

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.:

       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.