2023-11-28 16:21:31 +00:00
# Phoenix Flake Template
This is a template for constructing a environment for Elixir development
(version 1.15.7, Erlang/OTP 25) with the [Phoenix ](https://www.phoenixframework.org/ )
(version 1.7.10) framework. [direnv ](https://direnv.net/ ) can be used to launch
a dev shell upon entering this directory (refer to `.envrc` ). Otherwise run via:
```bash
2023-12-01 17:12:16 +00:00
$ nix develop
2023-11-28 16:21:31 +00:00
```
## Quickstart
2023-12-01 17:06:17 +00:00
An empty Postgres cluster is initialized at `/db` . To start the database, run
2023-11-28 17:21:56 +00:00
the following:
2023-11-28 16:21:31 +00:00
```bash
2023-12-01 17:12:16 +00:00
$ pg_ctl -D db -l db/logfile -o --unix_socket_directories=@phoenix start
2023-11-28 16:21:31 +00:00
```
2023-12-01 17:06:17 +00:00
In the above command, `@phoenix` refers to an [abstract socket name ](https://www.postgresql.org/docs/15/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES ).
Rename to whatever is appropriate for your use case. To then connect to this
database instance, run:
2023-11-28 16:21:31 +00:00
```bash
2023-12-01 17:12:16 +00:00
$ psql -h @phoenix
2023-11-28 16:21:31 +00:00
```
2023-12-01 17:06:17 +00:00
To later shut the database down, run:
2023-11-28 17:21:56 +00:00
```bash
2023-12-01 17:12:16 +00:00
$ pg_ctl -D db stop
2023-11-28 17:21:56 +00:00
```
2023-11-28 16:21:31 +00:00
Afterward, you can run the Phoenix setup commands:
```bash
2023-12-01 17:12:16 +00:00
$ mix ecto.setup
$ mix assets.setup
2023-11-28 16:21:31 +00:00
```
and then start the local server:
```bash
2023-12-01 17:12:16 +00:00
$ mix phx.server
2023-11-28 16:21:31 +00:00
```
## Dependencies
This project pins Mix dependencies using [mix2nix ](https://github.com/ydlr/mix2nix ).
After updating your `mix.lock` file, make sure to re-run the following:
```bash
2023-12-01 17:12:16 +00:00
$ mix2nix > deps.nix
2023-11-28 16:21:31 +00:00
```
As of now, `mix2nix` cannot handle git dependencies found inside the `mix.lock`
file. If you have git dependencies, add them manually or use
[FODs ](https://nixos.org/manual/nixpkgs/stable/#packaging-beam-applications ).
2023-11-29 16:18:10 +00:00
## Language Server
The [elixir-ls ](https://github.com/elixir-lsp/elixir-ls ) LSP (version 0.17.10)
is included in this flake.
## Formatting
Formatting depends on the `mix format` task. A `pre-commit` hook is included in
`.githooks` that can be used to format all `*.exs?` files prior to commit.
Install via:
```bash
2023-12-01 17:12:16 +00:00
$ git config --local core.hooksPath .githooks/
2023-11-29 16:18:10 +00:00
```
If running [direnv ](https://direnv.net/ ), this hook is installed automatically
when entering the directory.