DEV Community

Jay
Jay

Posted on • Updated on

Nix as development environment

Nix is a purely functional package manager. It is alternative to homebrew in MacOS, every folder has its own environment with the help of direnv, you can install any version of package on folder base.

Table Of Contents

  • Getting Started
  • Create nix config .envrc and default.nix
  • "Hello World" Node API with Nix

Getting Started

  • Install Nix
 sh \
  <(curl -L https://nixos.org/nix/install) \
  --darwin-use-unencrypted-nix-store-volume
Enter fullscreen mode Exit fullscreen mode
  • NOTE: this are for who have intel MacBook
  • Add nix profile in your favorite shell config
    • ~/.zshrc or ~/.bashrc - create if file not exist
   . /Users/<your-user-name>/.nix-profile/etc/profile.d/nix.sh
   source $HOME/.nix-profile/etc/profile.d/nix.sh
   export NIX_PATH="nixpkgs=$HOME/.nix-defexpr/channels/nixpkgs"
Enter fullscreen mode Exit fullscreen mode
  • Close your terminal to reload ~/.zshrc or ~/.bashrc file
  • For M1 or arm MacBook please see
 https://nix.dev/tutorials/install-nix
Enter fullscreen mode Exit fullscreen mode
  • Open new terminal, then type:
 nix-env --version
Enter fullscreen mode Exit fullscreen mode
  • Update all the channels link
nix-channel --update
Enter fullscreen mode Exit fullscreen mode
  • Install direnv
    • is an extension for your shell. It augments existing shells with a new feature that can load and unload environment variables depending on the current directory.
nix-env -i direnv
Enter fullscreen mode Exit fullscreen mode
eval "$(direnv hook zsh)"
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
sithuhlaing profile image
Si Thu Hlaing

I can't find ".nix-profile/etc" folder in mac, after installing NIX. how can I install like your instruction.