A simple guide to installing Nix on macOS and then using the JetPack.io Devbox as your Primary Package Manager.
Note Note: The last time I tested these instructions was November 2023.
To install Nix
on your macOS computer follow these steps.
Install the Xcode Command Line Tools, which is a collection of tools for software developers that run on the command line, in the Terminal application.
xcode-select --install
Install Nix using the Determinate Nix Installer! Which is a fast, friendly, and reliable tool to help you use Nix with Flakes everywhere.
Execute the following command from a macOS Terminal application and when prompted select all of the defaults.
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
Once the above is complete, you will need to add the following line to your ~/.zshrc
file to ensure the Nix binaries are available within your system path:
source '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
On completion, I would recommend restarting your computer. This is normally not required, although I have encountered certain scenarios when it has been. So to avoid debugging any issues, restart your computer.
There are a couple of options which could be followed when installing the JetPack.io Devbox on macOS. However, since we went through the process of first installing Nix, the best option in my opinion is to install using Nix.
Since we started with a clean install of Nix we must first add the available Nix Package channels which will be used when installing software. This can be achieved by executing the following commands from a macOS Terminal application.
nix-channel --add https://nixos.org/channels/nixpkgs-23.05-darwin nixpkgs;
nix-channel --add https://nixos.org/channels/nixpkgs-unstable unstable;
nix-channel --update;
Once complete, execute the following command to install the Devbox package.
nix-env -iA unstable.devbox
JetPack.io provides a great set of documentation on how to use Devbox, which can be found here.
In addition to managing isolated development environments, you can use Devbox as a general package manager. Devbox Global allows you to add packages to a global devbox.json
. This is useful for installing a standard set of tools you want to use across multiple Devbox Projects.
You can install a package using devbox global add [<package>]
, where the package names should be a list of Nix Packages you want to install.
For example, if we wanted to install ripgrep, vim, and git to our global profile, we could run:
devbox global add ripgrep wget git
Once installed, the packages will be available whenever you start a Devbox Shell, even if it's not included in the project's devbox.json
.
To view a full list of global packages, you can run devbox global list
:
devbox global list
If you want to make your global packages available in your host shell, you can add them to your shell PATH. Running devbox global shellenv
will print the command necessary to source the packages.
Add the following command to your ~/.zshrc
file:
Once the above is complete, you will need to add the following line to your .zshrc
file to ensure the Nix binaries are available within your system path:
eval "$(devbox global shellenv --init-hook)"
Make sure to add this hook before any other hooks that use your global packages.
You can use Git to synchronize your devbox global
config across multiple machines using devbox global push <remote>
and devbox global pull <remote>
.
Your global devbox.json
and any other files in the Git remote will be stored in $XDG_DATA_HOME/devbox/global/default
. If $XDG_DATA_HOME
is not set, it will default to ~/.local/share/devbox/global/default
. You can view the current global directory by running devbox global path
.
nix-collect-garbage