Homebrew works on NixOS only inside an FHS-like environment - NixOS has no /usr/bin, no /lib64/ld-linux-x86-64.so.2, so brew's bottles (dynamically linked against the standard loader) fail out of the box. The prefix itself (/home/linuxbrew/.linuxbrew) is fine; the linker is the problem.
Three viable routes, most reliable first.
User
i want linuxbrew
Assistant
Now wire it into matic.
Assistant
Wired linuxbrew into the NixOS side of the repo. Changes:
brew-env drops you into an FHS shell; install and use brew there. Caveat: brew-installed binaries only run inside that shell.
3. programs.nix-ld.enable = true
Provides /lib64/ld-linux-x86-64.so.2 plus NIX_LD_LIBRARY_PATH. Many bottles then run directly from a normal shell, but it is per-package trial and error - anything needing a library you did not list in programs.nix-ld.libraries breaks at runtime. Fragile as a general solution.
Repo notes
home-manager/programs/fish/default.nix:47 hardcodes /opt/homebrew/bin/brew (darwin). Linux prefix is /home/linuxbrew/.linuxbrew/bin/brew - would need a second branch.
Straight recommendation: unless a specific formula has no nixpkgs equivalent, do not put Homebrew on NixOS - use nixpkgs, and reach for distrobox for the handful of exceptions.
username
services.envfs.enable - supplies /bin/bash (brew's shebang is #!/bin/bash -pu) and /usr/bin/*, with ${pkgs.bash}/bin/bash in the fallback path
programs.nix-ld + libs (glibc, libgcc, libxcrypt-legacy, zlib, ncurses, openssl, curl) - provides /lib64/ld-linux-x86-64.so.2 for bottles and portable-ruby
systemd.tmpfiles.rules creating /home/linuxbrew and /home/linuxbrew/.linuxbrew user-owned, so brew never needs sudo
system build deps per the Homebrew-on-Linux docs: curl, file, gcc, git, gnumake, procps
New: home-manager/activation/install-linuxbrew.sh - idempotent git-clone install (git clone --depth=1 Homebrew/brew + relative symlink bin/brew), skipping install.sh entirely since the prefix is already user-owned. Warns and exits 0 when the prefix is missing or unwritable, so activation never breaks.
named-hosts/matic/default.nix - imports the module and runs the installer via home.activation.installLinuxbrew (delegated-bash form, passes scripts/check-nix-inline-scripts.sh).
Shell integration - brew shellenv eval guarded by file existence in fish (login + interactive) and zshenvExtra, plus /home/linuxbrew/.linuxbrew/bin in the PATH blocks of fish/zsh/bash, next to the existing /opt/homebrew entries. No-ops on darwin.
Module evaluated standalone against the pinned nixpkgs: envfs = true, nix-ld = true, tmpfiles rules present, /lib64/ld-linux-x86-64.so.2 -> nix-ld in the ruleset
Full .#nixosConfigurations.matic eval is not possible from darwin (IFD hits an x86_64-linux docker.service.drv) - matches the existing "can't be validated in darwin CI" note in flake.nix:68. Needs an on-device rebuild.
On matic:
make switch
Then brew --version. Only matic opts in; add the same module line to viper/kyber if you want it there.