Migrating from Homebrew to NixOS with flakes
Moving from Homebrew to NixOS takes five steps: take an inventory with a Brewfile, map each formula to nixpkgs, build a flake with home-manager, replace brew services with systemd, and give each project its own dev shell. Homebrew is a list of tools you add to over the years. NixOS is the whole machine in a file you rebuild from. So the move is mostly translation, with a bit of spring cleaning.
This guide is for moving to a Linux machine, whether that's a laptop or a box on a separate lab network. If you're staying on a Mac, nix-darwin with home-manager is the equivalent route, and most of what follows still applies.
Take an inventory with brew bundle dump
Before installing anything, find out what Homebrew has been quietly doing for you all these years. brew bundle dump writes every tap, cask and Mac App Store app, and every formula you installed yourself, to a Brewfile, which becomes the checklist for the rest of the move.
# Everything you installed, as a checklist (--force overwrites an old Brewfile)
brew bundle dump --file=Brewfile --force
# Formulae nothing else depends on, as a cross-check
brew leaves
# Background services Homebrew is running
brew services list
The Brewfile already leaves out dependencies, and that's what you want: dependencies come along automatically in Nix as well, so you only need to translate the packages you chose. brew leaves is a cross-check. A formula it lists that isn't in the Brewfile is usually a fossil from something you've since removed, and may not need translating at all.
Map Homebrew formulae to nixpkgs
Most command-line tools have the same name in nixpkgs. The exceptions are versioned formulae, where Homebrew uses @ and nixpkgs uses an underscore or a separate attribute. search.nixos.org or nix search nixpkgs <name> settles any doubt.
| Homebrew | nixpkgs | Where it goes |
|---|---|---|
ripgrep, fd, jq, gh | same names | home.packages |
node@22 | nodejs_22 | project dev shell |
[email protected] | python312 | project dev shell |
awscli | awscli2 | home.packages |
postgresql@16 + brew services | services.postgresql | configuration.nix |
git and its config | programs.git | home-manager |
casks such as visual-studio-code | vscode (unfree) | home.packages |
The third column is where the actual thinking happens. NixOS gives you three places to put a package, and choosing well keeps the configuration tidy.
- System configuration for services and anything every user needs: databases, Docker, SSH, fonts.
- home-manager for your own tools and dotfiles. It replaces both
brew installand the dotfiles repo you were symlinking by hand. - Per-project dev shells for language runtimes. A project pins its own Node or Python version, so nothing needs to be installed globally.
Build a flake with home-manager
A flake pins the exact nixpkgs revision in flake.lock, which is the equivalent of Homebrew never upgrading anything behind your back. This is a minimal one that wires home-manager into the system build, so one command updates both. The names and versions in these examples are placeholders for your own.
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
home-manager.url = "github:nix-community/home-manager/release-26.05";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { nixpkgs, home-manager, ... }: {
nixosConfigurations.workbench = nixpkgs.lib.nixosSystem {
modules = [
./configuration.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.matt = import ./home.nix;
}
];
};
};
}
There's no system argument because the hardware-configuration.nix that the installer generates, and configuration.nix imports, already sets nixpkgs.hostPlatform. Flakes only see files Git tracks, so git add each new file before you rebuild, or the build fails as if the file didn't exist. Everyone gets caught by this once.
The Brewfile's command-line tools then become a list in home.nix, and tools with configuration get a programs.* module instead of a dotfile:
{ pkgs, ... }: {
home.stateVersion = "26.05";
home.packages = with pkgs; [
ripgrep fd jq gh awscli2 vscode
];
programs.git = {
enable = true;
settings.user.name = "Matt Oddie";
settings.init.defaultBranch = "main";
};
# nix-direnv caches dev shells
programs.direnv.enable = true;
programs.direnv.nix-direnv.enable = true;
}
The home-manager manual lists every programs.* module. Watch for secrets as you move dotfiles across: anything written into a Nix file ends up in the Nix store, which every user on the machine can read. Keep tokens and keys out of the flake, or encrypt them with sops-nix or agenix.
Replace brew services with systemd
Everything in brew services list becomes a NixOS service option. These are better than their Homebrew equivalents in one respect: the service, its config file, its user and its data directory all come from the same few lines, so rebuilding a machine brings the whole service back.
{ pkgs, ... }: {
# Flakes and the nix command are off on a fresh install
nix.settings.experimental-features = [ "nix-command" "flakes" ];
nixpkgs.config.allowUnfree = true; # vscode and friends
services.postgresql = {
enable = true;
package = pkgs.postgresql_16;
ensureDatabases = [ "matt" ];
ensureUsers = [ { name = "matt"; ensureDBOwnership = true; } ];
};
virtualisation.docker.enable = true;
users.users.matt.extraGroups = [ "docker" ];
}
ensureDBOwnership only works on a database with the same name as the user, which is why the database is called matt. Without an owner, the database exists but your user can't create tables in it. Pin the PostgreSQL version as above: moving to a new major version, such as postgresql_17, needs a manual data migration, which the NixOS manual walks through.
Membership of the docker group is root-equivalent, as it is on any Linux machine. If that matters, use virtualisation.docker.rootless.enable or Podman instead.
Give each project a dev shell
With Homebrew, one version of Node serves every project on the machine. On NixOS each project can carry a small flake listing what it needs, such as Node 22 for a TypeScript MCP server:
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
outputs = { nixpkgs, ... }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
devShells.x86_64-linux.default = pkgs.mkShell {
packages = [ pkgs.nodejs_22 ];
};
};
}
Use aarch64-linux on an ARM machine. direnv loads the shell when you cd into the directory: put this line in the project's .envrc and run direnv allow once.
use flake
nix-direnv caches the shell, so it loads instantly after the first time. Two projects on different Node versions stop being your problem.
If you already use mise or asdf with a .tool-versions file, that keeps working on NixOS too, once nix-ld is on (see below), because the runtimes they download are prebuilt binaries. It's a reasonable halfway step while you convert projects one at a time.
Downloaded binaries won't runNixOS has only a stub at /lib64/ld-linux-x86-64.so.2, so prebuilt binaries from release pages, npm postinstall scripts and editor extensions fail with "Could not start dynamically linked executable" and a note that NixOS cannot run them out of the box. Set programs.nix-ld.enable = true; in the system configuration and most of them start working. Some need a library the default set leaves out, such as icu for .NET tools; add it with programs.nix-ld.libraries = [ pkgs.icu ];.
What doesn't translate
- Mac App Store entries in the Brewfile have no equivalent. Find the Linux version or an alternative for each.
- Apps that update themselves fight the read-only Nix store. Install them from nixpkgs and let the flake update them, or run them as a Flatpak.
- Taps for niche tools sometimes have no nixpkgs package. Check for a flake in the tool's repository first, since many projects now ship one, and package it yourself only as a last resort.
Upgrade and roll back with nixos-rebuild
brew update && brew upgrade becomes two commands. Update the lock file, then rebuild:
nix flake update
sudo nixos-rebuild switch --flake .#workbench
# Something broke? Go back to the previous generation
sudo nixos-rebuild switch --rollback
The rollback is the bit Homebrew never had. Every rebuild is a generation you can return to from the command line or the boot menu, so an upgrade that breaks something takes one command to undo. It only reverts the system, though: database contents, and anything your programs wrote to your home directory, stay as they are.
Generations pile up in the Nix store until you remove them. Setting nix.gc.automatic = true; with nix.gc.options = "--delete-older-than 30d"; deletes old ones on a schedule, and boot.loader.systemd-boot.configurationLimit caps how many the boot menu keeps.
Keep the flake in Git and work down the Brewfile line by line. Once every entry is either translated or deliberately dropped, the move is done, and you get to enjoy owning a machine you could rebuild from scratch.
Written by Matt Oddie · Markdown version