Easily set up a Nix flake-based development environment for your Elixir/Phoenix-project.
To create a new Phoenix project that's already initialized with a Nix flake, run the following command:
mix igniter.new flakify_test --install flakify --with phx.new --with-args="--no-ecto"
This will:
-
Add a
flake.nixwith a development shell that contains elixir, tailwind and esbuild. And also sets theMIX_TAILWIND_PATHandMIX_ESBUILD_PATHenvironment variables. -
Modify
config/config.exssuch that theesbuildandtailwindconfigurations useMIX_ESBUILD_PATHandMIX_TAILWIND_PATHrespectively to find the corresponding executables.
After performing the install, you should be able to run nix develop -c mix phx.server to run the Phoenix server using the flake development environment.
In an existing project, you can run:
mix igniter.install flakify
After running the installer, flakify will remove itself from your project dependencies.
When specifying --package (this is also the default), flakify will add a
package derivation that builds a Mix release of the Elixir project. It relies on
deps_nix to convert Mix dependencies to Nix
derivations, so you will need to add the generated deps.nix to your git
repository. After doing so, building should be as simple as:
$ nix buildThe resulting release can be run by e.g. the following command:
PHX_SERVER=1 SECRET_KEY_BASE=`mix phx.gen.secret` RELEASE_COOKIE="secret" ./result/bin/your_app start- Add option to also add a package definition to
flake.nix, probably usingdeps_nix. - Add option to specify whether tailwind and esbuild should actually be installed.
- Add option to add an .envrc file for direnv
- Add option to specify the nixos/nixpkgs version to use
- Add option to specify which version of elixir/beam to use
- Add option to add a nixos module definition and/or systemd service definition