webuhu/elixir_nix_example
{ "createdAt": "2019-07-22T14:51:43Z", "defaultBranch": "main", "description": null, "fullName": "webuhu/elixir_nix_example", "homepage": null, "language": "Nix", "name": "elixir_nix_example", "pushedAt": "2021-12-15T09:23:34Z", "stargazersCount": 32, "topics": [], "updatedAt": "2025-10-31T14:47:33Z", "url": "https://github.com/webuhu/elixir_nix_example"}Elixir (Phoenix) Nix Example
Section titled “Elixir (Phoenix) Nix Example”Example repo to show off how I use Nix as build environment for Elixir / Phoenix projects.
Important Nix stuff is located withinflake.nix/default.nix&pkg/folder.
This repo is not a working project! It just contains parts of the workflow.
Note
Since starting this example a lot of positive things have happened or are happening within Nixpkgs.
You may be interested in mixRelease or friends.
I for myself stopped to use a full Nix leveraging build setup. I only use parts of this workflow anymore with reusing local _build & deps as it speeds up things for my requirements enorm.
This repo provides an easy environment setup by the usage of Nix (w/ flakes enabled).
Nix currently runs on Linux and macOS.
Enabling Nix flakes (Nix v2.4)
experimental-features = nix-command flakesBy using Nix, beside Nix nothing else needs to be installed manually.
Windows
Recommended also using Nix within a Linux Virtual Machine or WSL 2.
Manual Setup
Section titled “Manual Setup”For maintaining simplicity, instructions for a manual setup isn’t part of this readme.
Anyway, required dependencies:
- Elixir (& Erlang)
- PostgreSQL
- (Node.js)
Development
Section titled “Development”Environment
Section titled “Environment”# Enter shell w/ development environment + temporary PostgreSQL databasenix develop
# Run commands without shellnix develop --command <command>Basics commands for working with Elixir / Phoenix
Section titled “Basics commands for working with Elixir / Phoenix”# Get Elixir mix depsmix deps.get
# Get JS packagesnpm install --prefix assets
# Start Phoenix servermix phx.server
# Start Elixir applicationmix run --no-halt
# Enter IExiex -S mix
# Run testsmix test# mix depsnix build --file default.nix mix_deps --relaxed-sandbox
# JS packagesnix build --file default.nix node_modules --relaxed-sandbox
# Compilenix build --file default.nix mix_build --relaxed-sandbox
# Compile cacheable `_build`nix develop --command mix compile
# Generate docs using `mix docs`nix build --file default.nix docs --relaxed-sandbox
# Build production release using `mix release`nix build --file default.nix release --relaxed-sandboxMaintenance
Section titled “Maintenance”# Update pinned Nix pkgselixir pkg/scripts/pkgs_update.exs# Update flake.locknix flake update
# Check / update / clean Mix depsmix hex.outdatedmix deps.update --allmix deps.clean --unlock --unused
# Check / update / clean NPM packagesnpm outdated --prefix assetsnpm update --prefix assetsnpm prune --prefix assets
# Flake checksnix flake checkdirenv let’s you automatically load environment variables per directory defined in .envrc.
Working with direnv
# Install via Nixnix profile install nixpkgs#direnv
# Setup hook# Add the following to your .profileeval "$(direnv hook bash)"