Customising unbound build for MacOS on M1 using homebrew tooling
Got broken package and got stuck on how to fix it? Let's get it back to life by using example of unbound package.
First you will need to remove the package you already have in your system:
brew remove unboundThen you should create a new local tap for your customisation
brew tap-new $USER/local-unboundThe successful output will be looking like (replace <user> by your real username):
Initialized empty Git repository in /opt/homebrew/Library/Taps/<user>/homebrew-local-unbound/.git/
[main (root-commit) 5317ce5] Create <user>/local-unbound tap
3 files changed, 90 insertions(+)
create mode 100644 .github/workflows/publish.yml
create mode 100644 .github/workflows/tests.yml
create mode 100644 README.md
==> Created <user>/local-unbound
/opt/homebrew/Library/Taps/<user>/homebrew-local-unbound
When a pull request making changes to a formula (or formulae) becomes green (all checks passed), then you can publish the built bottles.
To do so, label your PR as `pr-pull` and the workflow will be triggered.Now you should clone your package from some exisiting point. In our example we are going to restore version 1.7.1 of the package:
brew extract --version=1.7.1 unbound $USER/local-unbound
==> Searching repository history
==> Writing formula for unbound from revision 512758e to:
/opt/homebrew/Library/Taps/<user>/homebrew-local-unbound/Formula/unbound@1.7.1.rbThe package may won’t install because of error like (plist_options was deprecated time ago, and now it is completely disabled):
Error: unbound@1.7.1: Calling plist_options is disabled! Use service.require_root instead.So, edit the formula to match the homebrew rules and to fit your needs (file /opt/homebrew/Library/Taps/<user>/homebrew-local-unbound/Formula/unbound@1.7.1.rb). Example:
class UnboundAT171 < Formula
desc "Validating, recursive, caching DNS resolver"
homepage "https://www.unbound.net"
url "https://www.unbound.net/downloads/unbound-1.7.1.tar.gz"
sha256 "56e085ef582c5372a20207de179d0edb4e541e59f87be7d4ee1d00d12008628d"
deprecated_option "with-python" => "with-python@2"
depends_on "openssl"
depends_on "libevent"
depends_on "expat"
depends_on "python@2" => :optional
depends_on "swig" if build.with? "python@2"
def install
args = %W[
--prefix=#{prefix}
--sysconfdir=#{etc}
--with-libevent=#{Formula["libevent"].opt_prefix}
--with-ssl=#{Formula["openssl"].opt_prefix}
--with-libexpat=#{Formula["expat"].opt_prefix}
]
if build.with? "python@2"
ENV.prepend "LDFLAGS", `python-config --ldflags`.chomp
ENV.prepend "PYTHON_VERSION", "2.7"
args << "--with-pyunbound"
args << "--with-pythonmodule"
args << "PYTHON_SITE_PKG=#{lib}/python2.7/site-packages"
end
# args << "--with-libexpat=#{Formula["expat"].opt_prefix}" unless MacOS::CLT.installed?
system "./configure", *args
inreplace "doc/example.conf", 'username: "unbound"', 'username: "@@HOMEBREW-UNBOUND-USER@@"'
system "make"
system "make", "test"
system "make", "install"
end
def post_install
conf = etc/"unbound/unbound.conf"
return unless conf.exist?
return unless conf.read.include?('username: "@@HOMEBREW-UNBOUND-USER@@"')
inreplace conf, 'username: "@@HOMEBREW-UNBOUND-USER@@"',
"username: \"#{ENV["USER"]}\""
end
service do
run [opt_sbin/"unbound", "-d", "-c", etc/"unbound/unbound.conf"]
working_dir HOMEBREW_PREFIX
keep_alive true
require_root true
end
test do
system sbin/"unbound-control-setup", "-d", testpath
end
end And then just install the resulting fomula:
brew install unbound@1.7.1Enjoy!

