Skip to content

schneebyte/elixir_nix_example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 within default.nix & pkg/ folder.

Setup

This repo provides an easy environment setup by the usage of Nix.
Nix currently runs on Linux and macOS.

By 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

For maintaining simplicity, instructions for a manual setup isn't part of this readme.
Anyway, required dependencies:

Development

For convenience an alias configuration exists for some of the following shell commands.

Environment

# Enter shell w/ development environment (no database)
# Alias: `app-env`
nix-shell --pure -A env

# Run commands without shell
nix-shell --pure -A env --run <command>

# Run commands in interactive shell
nix-shell --pure -A env --cmd <command>

# Enter shell w/ development environment and temporary PostgreSQL database
nix-shell --pure -A env_with_db

# Running all tests
# Alias: `app-test`
nix-shell --pure -A env_with_db --argstr MIX_ENV test --run 'mix test'

Basics commands for working with Elixir / Phoenix

# Get Elixir mix deps
mix deps.get

# Get JS packages
npm install --prefix assets

# Start Phoenix server
mix phx.server

# Start Elixir application
mix run --no-halt

# Enter IEx
iex -S mix

# Run tests
mix test

Build

# mix deps
nix-build -A mix_deps --option sandbox relaxed

# JS packages
nix-build -A node_modules --option sandbox relaxed

# Compile
nix-build -A mix_build --option sandbox relaxed

# Compile cacheable -> .nix/_build
nix-shell --pure -A env --command 'mix compile'

# Generate docs using `mix docs`
nix-build -A docs --option sandbox relaxed

# Build procution release using `mix release`
nix-build -A release --argstr MIX_ENV prod --option sandbox relaxed

Maintenance commands

# Update pinned Nix pkgs
elixir pkg/scripts/pkgs_update.exs

# Check outdated Mix deps & NPM packages
mix hex.outdated
npm outdated --prefix assets

# Update Mix deps & NPM packages
mix deps.update --all
npm update --prefix assets

# Removed unused deps from mix.lock
mix deps.clean --unlock --unused

Aliases

# Load aliases into your shell
# You could also source this in your .profile
. pkg/scripts/alias.sh

Working with aliases

# List
alias

# Remove
unalias alias_name

# Remove all
unalias -a

direnv let's you automatically load environment variables per directory defined in .envrc.

Working with direnv

# Install via Nix
nix-env -iA nixpkgs.direnv

# Setup hook
# Add the following to your .profile
eval "$(direnv hook bash)"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 51.8%
  • Nix 21.2%
  • CSS 15.0%
  • JavaScript 5.8%
  • HTML 4.2%
  • Shell 1.1%
  • SCSS 0.9%