macoshomebrewpackage-managersnix

macOS Package Managers: Using Nix alongside Homebrew?


I was wondering if there would be any issues with installing Nix and Homebrew on the same system?

I know Homebrew tends to install things all over different directories, but from what I have read, Nix is very clean. If I understand this correctly, Nix installs it's packages all within one single directory.

So if this is the case, could I try running them both side-by-side? I would be careful not to install too many of the same packages from both places in (ie. I wouldn't install grep, htop, or whatever else from both Homebrew and Nix and if I did I would take precautions).

Side-note: This would not be permanent. I am thinking about switching from Homebrew to Nix (just to mix things up a bit), and I wanted to try Nix on my main machine before taking the leap (if at all). I know I could just try Nix on a VM, but I would not get the same experience unless I tried it on my main system. So it would be nice to install it along Homebrew and give it a shot before going through the pains of removing Homebrew and replacing all my Homebrew packages with Nix packages.


Solution

  • Yes, you can install Nix along side Homebrew.

    Nix will install all its packages within /nix/store For example, on my NixOS system vim is currently installed in /nix/store/j6nrk9h1rpxrzmccm0yq520ik625gd1q-vim-8.1.0578

    Your shell will choose whether to use a package from Nix or Homebrew, according to how $PATH is set up. For example, if it so happens that the Nix paths are first, then they will take precedence.

    Note

    A common source of confusion is that install means something different on Nix. When you install a package, such as Python, it becomes part of a Nix environment, and as such can be executed without specifying the full path; Just as you'd expect from any package manager.

    However, if you install a package which has, say, Python, as a dependency, Python would get installed, but more likely than not it would not be included in the environment. Hence it can only be executed via the absolute path.

    On a related note, due to a similar reason, if you install a library with Nix and then try to compile against it outside of Nix, it will not work; The build tools will not find the library.