- Nix
- Local Postgres
- (optional) 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;
};
mkdir my_new_project # underscores mean you can skip an argument to mix phx.new
cd my_new_project
git init
nix flake init -t github:code-supply/nix-phoenix
direnv allow
mix phx.new . # and say Y to everything
echo .direnv >> .gitignore # we don't want to store the direnv cache in git
Follow the deps_nix installation instructions.
Fetch the deps_nix dependency:
mix deps.get
mix deps.nix
git add . # make files available to the Nix flake
nix build --print-build-logs # short option is -L
DATABASE_URL=ecto://postgres:postgres@localhost/my_new_project \
MIX_ENV=prod \
SECRET_KEY_BASE="$(mix phx.gen.secret)" \
mix ecto.create
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
Open a browser at http://localhost:4000/ to see your released site.