In this tutorial, you will learn how to add flake.nix
to an Elixir Phoenix project.
Initialize a new project
Make
mix
executable available:Terminal window nix shell nixpkgs#elixirInstall the scaffolder for Phoenix using
mix archive.install
command. You need to do this only once per machine:Terminal window mix archive.install hex phx_newUse
mix phx.new
to scaffold a new project with your preferred options:Terminal window mix phx.new 'your_new_project' --no-ectoEnter the directory:
Terminal window cd 'your_new_project'
Add flake.nix to the project
Initialize the template from the root directory of the project:
Terminal window nix flake init github:akirak/flake-templates#elixir-appOpen
flake.nix
and set the Erlang and Elixir versions:let# Set the Erlang versionerlangVersion = "erlang_26";erlangVersion = "erlang_27";# Set the Elixir versionelixirVersion = "elixir_1_15";elixirVersion = "elixir_1_18";inAdd
.envrc
:Terminal window use flakeAllow direnv:
Terminal window direnv allow
Switch the language server
Lexical is the default language server for Elixir, but you can change it to a different one:
[ erlang elixir # You are likely to need Node.js if you develop a Phoenix # application. nodejs # Add the language server of your choice. inputs.lexical.packages.${system}.default elixir-ls # I once added Hex via a Nix development shell, but now I install # and upgrade it using Mix. Hex installed using Nix can cause an # issue if you manage Elixir dependencies using Mix.]