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