This is a minimal starter repo for using nix-shell to run an Elixir Phoenix project with PostGreSQL. The environment variables needed to bootstrap the PostGreSQL database are included in .envrc, which is not ignored by .gitignore. However, in a real project, you will likely want to keep the contents of this file secret by including it in .gitignore.
Make sure you have already installed nix package manager and configured the nixpkgs channel as with nix-channels.
Run nix-shell from the repo root to start the shell environment. If you're running it for the first time, a PostGreSQL database will be initialized. When you exit the shell, the PostGreSQL instance will be stopped. If you need to stop PostGres manually, you can run ./postgres-local.sh stop.
Follow the Phoenix installation guide linked here by running mix phx.new <project-name> inside the nix-shell.
When finished, edit the config/dev.exs file to include socket_dir: "#{System.get_env("PGHOST")}", after the database key, replacing the generated line hostname: "localhost", with a configuration that looks similar to this:
# Configure your database
config :hello, Hello.Repo,
username: "postgres",
password: "postgres",
database: "hello_dev",
socket_dir: "#{System.get_env("PGHOST")}",
show_sensitive_data_on_connection_error: true,
pool_size: 10With that, you can run mix ecto.create from the project directory and you'll be off to the races.
After configuring the project to use the socket_dir for the local PostGreSQL database, you can run either mix phx.server or iex -S mix phx.server for regular development on the project.