We use Nix to package all of the dependencies for our dev environment. It does several things for us:
- Enables new devs on macOS or Linux to set up our dev environment with just one command
- Makes sure that everybody on the team is using the same versions of all the tools
- Allows us to isolate development dependencies from affecting the host system
For how Nix package management works, please refer to the official how Nix works guide.
To set up a dev environment using Nix, you will need a macOS or Linux machine.
If you are using a Mac computer with Apple silicon, you will need to install Rosetta 2. You can do this by running:
softwareupdate --install-rosetta
For developers using macOS, go to the Mac App Store to install Xcode; or if you already have it, update it to the latest version.
Once Xcode is installed, open it up. If you are prompted, follow the instructions to install any “Additional Required Components”
For developers using macOS, you need to make sure that the Xcode “Command Line Tools” are installed. You can do this by running:
xcode-select --install
To install and configure the Nix package manager, please run:
# Pull down Git repository
git clone [email protected]:CommE2E/comm.git
cd comm
# Install Nix and Comm binary cache
./scripts/install_nix.sh
Now either close and reopen your terminal window or re-source your shell configuration file in order to have changes applied.
As a first step, you’ll want to set up the JavaScript environment and pull in all necessary NPM packages. Run the following command:
# Create development shell
nix develop
# Install yarn dependencies
yarn cleaninstall
On macOS, installing Xcode is a prerequisite for all workflows.
Run nix develop
to create a dev environment. Nix will handle the installation of all remaining dependencies not mentioned in Workflow prerequisites.
Alternate shells such as zsh or fish can also be used with Nix. To use an alternate shell, run:
nix develop -c $SHELL
You may also replace the bash shell with the shell of your preference.
nix develop
exec zsh # or fish
Nix installs packages in the Nix store at package-specific paths (e.g. /nix/store/x7kdiasp...-clang/bin/clang
). When you run nix develop
, Nix sets environment variables such as PATH
to expose the binary dependencies to your shell. This model can be extended to support other build toolchains such as pkg-config, CMake, and many other language specific package managers.