Skip to content

ca-la/nix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Nix Development Environment

Why?

To have a consistent development environment without the overhead of Docker or other containerization services. Provides a consistent set of development dependencies, such as Node, PostgreSQL, ElasticMQ, pgcli, etc.

Installing Nix on macOS

Official documentation

For Intel architecture

# Install Apple command line developer tools
xcode-select --install

# Install nix itself in multi-user mode
sh <(curl -L https://releases.nixos.org/nix/nix-2.6.1/install) --daemon

# Start a new terminal session to ensure `nix` is in your path
which nix # to confirm you have `nix` in your path

# Create nix configuration to enable flakes and `nix` support
mkdir -p ~/.config/nix
cat > ~/.config/nix/nix.conf<< EOF
experimental-features = nix-command flakes
EOF

For Apple M1 architecture

# Install Apple command line developer tools and Rosetta
xcode-select --install
softwareupdate --install-rosetta

# Install nix itself in multi-user mode
sh <(curl -L https://releases.nixos.org/nix/nix-2.6.1/install) --daemon

# Start a new terminal session to ensure `nix` is in your path
which nix # to confirm you have `nix` in your path

# Create nix configuration to enable Intel platform, flakes, and `nix` support
mkdir -p ~/.config/nix
cat > ~/.config/nix/nix.conf<< EOF
system = aarch64-darwin
extra-platforms = x86_64-darwin
experimental-features = nix-command flakes
EOF

Set up CALA services

# Initial setup of CALA nix repo
cd ~/cala # or where ever your other CALA repos live
git clone git@github.com:ca-la/nix.git
cd nix

# Open a bash shell with our dependencies installed
# Note: first run will take a while to download and install packages
nix develop .

# Create a "database cluster" for running the Postgres server
cd ~/cala # or where ever your other CALA repos live
initdb data
pg_ctl start -D data

# ElasticMQ (SQS compatible message service)
elasticmq& # queues are preconfigured, so no additional work needed

pg_ctl and elasticmq& run the PostgreSQL and ElasticMQ servers until you restart your system. Don't worry about closing the nix shell. elasticmq it's only needed if you want to work on asynchronous/worker-related tasks.

Once you've completed these steps, you should be able to clone the API repository and run bin/boostrap to set up the required databases, insert pricing data, etc.

To avoid running elasticmq, generally you can start just the API without the worker. To do that you can run bin/dev api inside the API repo, instead of the default bin/dev.

Usage

Using the nix develop . command from within the nix git repo, you can enter a shell with all of our tools installed in your PATH.

Bring your own shell

nix develop --command zsh will create a subshell within the bash session that nix develop would create. That means you'll get the PATH set up by nix, but it will create a new zsh session, giving you the best of both worlds!

One caveat here is that nix works by putting the correct tools in your PATH, so if you have things in your shell profile scripts that would add to the PATH you have to be careful not to override the tools provided by nix. When in doubt, check which foo-tool and make sure it points to something in the /nix/store. Approaches to this will vary depending on your setup and needs, but here's one simple solution.

Uninstalling Nix

If the installation fails in the middle, or you just decide to delete nix for some reason, here the installer itself contains some instructions on how to uninstall. At the time this README was written, that is the following:

# Remove entry from fstab
sudo vifs
# Find the /nix data volume
diskutil list
# Destroy the /nix data volume
diskutil apfs deleteVolume diskNsN # value from previous command
# Remove the `nix` line from /etc/sythentic.conf
sudo vim /etc/synthetic.conf

About

A consistent CALA development environment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages