A set of Nix tools to work with Elixir's Phoenix web framework, with Elixir 12 and Phoenix 1.6. The goal is reproducible builds, but we also get virtual environments with this setup. For example, one could replace asdf
with nix shells.
Elixir 12 and Phoenix 1.6 bring some important changes. For Nix users, the most important is probably switching out webpack for esbuild to handle front end dependencies, meaning no dependency on Node.js and no additional setup required when compiling a Phoenix app. A big win for reproducibility.
The phx-shell.nix
is standalone, and should be modified to work with the flake.nix
expression.
An example workflow might look something like this:
- pop into a Nix shell (especially if you're using a different Elixir version):
nix-shell phx-shell.nix
. You're now in an environment which specifies Elixir 12 and sets up some env vars you would expect, themix2nix
tool for handling Mix dependencies in Nix, and themix phx.new
task for generating Phoenix projects. - set up your Phoenix project as you usually would:
mix phx.new my-project
. - copy the
flake.nix
andshell.nix
files into your project directory. - Notice that the flake imports a
deps.nix
file, which doesn't exist yet. This is where mix2nix comes in: runmix2nix > deps.nix
. This will look at yourmix.lock
file, query hex for the dependency binaries, and add them to the nix store. Now your environment and your build will query the nix store instead of fetching dependencies externally. - You can now run
nix build
to build a Mix release (which will be underresult/bin/my-project-name
) or hack on the project further withnix develop
. Check out the flake docs for more commands.