Advice needed: how best to integrate nix home-manager config and homebrew (macOS)?

I have been using a standalone (i.e. no nix-darwin), flake-based, home-manager config on macOS for a while now, and love having a declarative setup. However, there are a few tools that are more easily installed through homebrew, as well as casks that have no counterpart on nix for macOS.

At the moment, I have installed homebrew separately, but I manage the config files of the homebrew-installed binaries (e.g. yabai, skhd, sketchybar) with home-manager using xdg.configFile and so on, as well as keeping a Brewfile in my dotfiles repo.

This mostly works fine (though I have an odd issue with sketchybar only when it is managed this way that I need to dig into), but I wondered how other macOS folk manage homebrew stuff? I see there are nix packages for yabai, skhd and sketchybar, so I might be able to install them with nix, but I don’t know how you then manage starting/restarting/stopping the launchctl services for them.

Any help or guidance would be very welcome - I haven’t been able to find much through Googling the topic, and anything I have found seems to be specific to nix-darwin, which might mean it’s not possible for my use-case I guess.

Thanks!

Is there a reason why you’re not willing to use nix-darwin? Is it a lack of sudo privileges?

Declaratively configuring homebrew and launchctl are some of the major reasons for using nix-darwin. Maybe you can explain why nix-darwin is not an option for you, if for context more than anything else?

If you really can’t use nix-darwin, then maybe you could make use of activationScripts to run the install, upgrade, and/or launchctl commands that you need during home-manager activation to keep them tightly coupled.

1 Like

I do have sudo privileges, so I could go that route. I started with home-manager as it felt a more gradual way to familiarise myself with nix as a package manager. I guess I might feel brave enough soon to take the plunge and use nix-darwin.

Can you recommend a tutorial or even a set of config files that make it easy to learn by example?

Home Manager is best suited for user configuration, but the things you mention all belongs to system-wide configuration. For system-wide stuff, nix-darwin is the best tool for the job. Many people, myself included, use both.

Check out the official repo for installation instructions (you will have to run some one-time commands).

Since you’re using flakes, I would look at their flake example. You can separate your darwinConfiguration from homeConfiguration if you run them separately, but you can also use home-manager as a module inside nix-darwin and configure home resources at the same time. The glossary lists all of the configuration options.

I’ll offer my config if you’re curious, but unfortunately it’s not that simple and may be hard to follow since it’s a monorepo with a lot going on. My homebrew config looks like this. Everyone organizes their config differently; I manage both NixOS and macOS together, so I can’t necessarily recommend my setup as the best approach for everyone.

1 Like

Thanks so much @noah and @midchildan for your help! I think I will give it a go after looking at the docs and your configs to figure out what I need to do. I didn’t realise that you could use nix-darwin and home-manager separately, so that’s interesting. Wish me luck!

1 Like

I’m a former nix-darwin user, but I stopped for a few reasons.

  • nix-darwin doesn’t seem to be all that well maintained. Module quality is sometimes quite poor. For example, last I checked, the Postgres and/or redis module was broken by default for trying to write to a nonexistent folder.
  • installation is kind of invasive. I don’t remember exact details, but I do recall that nix-darwin wants to modify some system-wide files on install, add a nix-darwin channel, etc. I don’t understand why that’s necessary, why can’t it be basically like home-manager but ask for sudo on activation? Anyway, this is annoying for bootstrapping systems with a nix flake.
  • (not nix-darwins fault) it’s easy to be left with a messed up system after a macOS upgrade since Apple rewrites system files (like /etc/shells) on upgrade.

For these reasons, I decided no thanks. The experience does not meet my quality bar.

@bsag if I had homebrew packages I depended on, I would look in to adapting the nix-darwin module for use with home-manager.

Hi Andrew -

As someone almost-delighted-but-sometimes-very-frustrated with nix-darwin, I’d be interested to know what you use now… are you still using nix, or home-manager, or have you decided nix and MacOS aren’t a good match.
(I’ve just reinstalled homebrew for a package I couldn’t get to install with nix…)
Quentin

Nix-Darwin is great, but the way it mixes per-user and systemwide responsibilities and uses sudo to switch between them (only working right when being launched unprivileged) is a big source of pain for me at work thanks to software we have to run which meddles with sudo behavior, requiring me to enter my password multiple times and breaking TouchID integration.

I’d be happier with a Nix-Darwin that focused only on the privileged, systemwide stuff, alongside some optional Mac-specific integrations for Home Manager.

1 Like