Development Setup using Nix
Explains how to set up a Rails development environment using Nix, Docker, and direnv for advanced users.
What this file does
Explains how to set up a Rails development environment using Nix, Docker, and direnv for advanced users.
When to use it
- You already use Nix and want a reproducible dev shell
- You need to run a Rails app with a Docker database but no Docker for Rails
- You want automatic environment loading via direnv
Assumes this stack
Development Setup using Nix
[!WARNING] This is meant for advanced users already familiar with Nix. If you're looking for general development instructions, please see README.md.
Prerequisites
- Nix
- Docker w/ Compose via Docker Desktop or equivalent - this setup runs Rails directly but uses a container for the database.
- direnv - technically optional but helpful to get the environment to automatically load when entering the project directory
Initial Dependencies
If you have direnv, the .envrc file in the repository will get everything set
up for you automatically, you just need to run direnv allow. If you're not
using direnv, you can manually start a development shell with nix develop.
Database
This setup uses the development database configured in docker-compose.yml,
which can be started like this:
$ docker compose up -d database
The database is working properly if this command produces a list of databases:
$ psql -l "$DATABASE_URL"
Bootstrapping
Use the setup script to get started for the first time.
$ bin/setup
This script will:
- Fetch Ruby and NPM dependencies
- Bootstrap the development database
- Load some sample data into the development database
The setup script doesn't create the test database, so do that separately:
$ bin/rails db:create:all
Asset Compilation
You can get the assets automatically compiling on file changes by leaving this command running in a shell:
$ bin/dev -m all=1,web=0
Note this skips the Rails server, which we run separately below. This is because something is preventing Rails from loading properly within the Foreman environment. If somebody figures this out update this guide!
Development Server
Run the Rails server in a separate shell:
$ bin/rails server
Running Tests
All tests should be able to run normally:
# Unit tests
$ bin/rails test
# Selenium tests
$ bin/rails test:system
The Selenium tests are run by having Nix install Chromium and ChromeDriver and
set a SELENIUM_CHROME_BINARY environment variable to point Selenium at
Chromium in test/application_system_test_case.rb.
Precommit Hooks
Precommit hooks are managed by lefthook, which is automatically installed
into the Nix development shell. Install the hooks to get them to run on every
commit:
$ lefthook install
What's inside
7 sections: prerequisites, dependencies, database, bootstrapping, asset compilation, server, tests, precommit hooks. 6 code blocks.
Change this for your project
- Replace
docker-compose.ymlwith your own compose file if different - Replace
bin/setupwith your own bootstrap script if not using Rails default - Replace
test/application_system_test_case.rbwith your own Selenium config path
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Using Nix to install Chromium and set Selenium binary path avoids system-level dependencies
- Running Rails directly while keeping the database in Docker reduces complexity
Related Documents
Dev Setup Install Instructions
Walks through setting up a conda environment, installing dependencies, and configuring MinKNOW for simulated Flongle replay and adaptive sampling.
canvas_dev_setup
Guides developers through setting up a local Canvas LMS instance with Apache and integrating it with the Wiki Education Dashboard via LTI 1.3.
My current setup (2026 edition)
Documents a developer's personal IDE, terminal, macOS, iOS, hardware, and tooling choices in 2026.
dev_setup
Explains how to install, run, test, profile, and contribute to the Vimflowy project locally.