Skip to content

Latest commit

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Start a new Phoenix project with Nix

Prerequisites

  • Nix
  • Local Postgres
  • (optional) direnv

direnv

Examples assume you've set this up. Use nix develop . instead of direnv allow if you don't want direnv.

To install with Home Manager and nix-direnv caching:

home.direnv={enable=true;nix-direnv.enable=true;};

Instructions

Initialise

mkdir my_new_project # underscores mean you can skip an argument to mix phx.newcd my_new_project
git init
nix flake init -t github:code-supply/nix-phoenix
direnv allow
mix phx.new .# and say Y to everythingecho .direnv >> .gitignore # we don't want to store the direnv cache in git

Add deps_nix

Follow the deps_nix installation instructions.

Fetch the deps_nix dependency:

mix deps.get

Generate the initial deps.nix file

mix deps.nix

Build the project

git add .# make files available to the Nix flake
nix build --print-build-logs # short option is -L

Create a local database

DATABASE_URL=ecto://postgres:postgres@localhost/my_new_project \
MIX_ENV=prod \
SECRET_KEY_BASE="$(mix phx.gen.secret)" \
mix ecto.create

Run the built artifact

DATABASE_URL=ecto://postgres:postgres@localhost/my_new_project \
PHX_SERVER=true \
RELEASE_COOKIE=asdf \
SECRET_KEY_BASE="$(mix phx.gen.secret)" \
./result/bin/my_new_project start

Visit the site

Open a browser at http://localhost:4000/ to see your released site.

About

Tools and instructions for starting Phoenix projects with Nix deployment

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages