Skip to content

Latest commit

 

History

History
160 lines (117 loc) · 7.04 KB

nix_dev_env.md

File metadata and controls

160 lines (117 loc) · 7.04 KB

Motivation

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.

Supported workflows

Some workflows require additional steps after the Nix installation. These steps are documented in Workflow prerequisites.

Workflow macOS supported
keyserver (Node.js)
web & landing (Webpack)
native iOS (React Native)
native Android (React Native)
C++ services *
Rust services

* Workflow requires documentation; and it requires the RabbitMQ and AWS/Localstack services to be available.

Requirements

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

Prerequisites

Xcode

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”

Xcode Command Line Tools

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

Nix package manager

To install and configure the Nix package manager, please run:

# Pull down Git repository
git clone git@github.com: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.

Install development dependencies

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

Workflow-specific prerequisites

On macOS, installing Xcode is a prerequisite for all workflows.

Development environment

Run nix develop to create a dev environment. Nix will handle the installation of all remaining dependencies not mentioned in Workflow prerequisites.

Development workflows

Production workflows

Using alternate shells with Nix

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

How Nix introduces dependencies to a development environment

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.