Configure nix on macOS

#nix#macos

16 March 2025 | Updated on 25 March 2025

Learn how to install and configure nix on macOS.

ℹ️
There are different ways to install and configure nix. This is an example on how I configured my nix on macOS.

Install nix

  • go to nix download page
  • choose macOS > Multi-user installation
  • run the sh command shown on the website

Configure nix

Verify zshrc configuration

Add the following at the top of your user ~/.zshrc configuration file

~/.zshrc
# Nix
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
  . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# End Nix

By default this code block could already be available at the end of /etc/zshrc. But sometimes it gets deleted after macOS updates. So I only keep it at the top of my user ~/.zshrc and delete it in /etc/zshrc so it does not get executed twice.

Enable flakes

add the following to your nix configuration file

~/.config/nix/nix.conf
experimental-features = nix-command flakes

Learn how to use nix flakes as development environment

Configure Visual Studio Code

  • Nix uses the path environment variable to configure its custom shell environment
  • The following vscode settings configuration ensures that vscode does not incorrectly overwrite the path environment variable
../User/settings.json
{
"terminal.integrated.defaultProfile.osx": "zsh",
  "terminal.integrated.profiles.osx": {
    "zsh": {
      "path": "zsh",
      "args": []
    }
  }
}

Now you can start vscode in nix shell

Additional resources


Related content