bootstrap/specs/phoenix/template
Joshua Potter 07eb1fa382 Add pre-commit guard on empty state. 2023-12-03 11:32:45 -07:00
..
.githooks Add pre-commit guard on empty state. 2023-12-03 11:32:45 -07:00
.envrc Add formatting pre-commit to elixir projects. 2023-11-29 09:18:10 -07:00
README.md Add phoenix documentation and full pre-commit. 2023-12-02 06:32:19 -07:00
default.nix Add phoenix spec. 2023-11-28 09:21:31 -07:00
deps.nix Add phoenix spec. 2023-11-28 09:21:31 -07:00
flake.lock Add phoenix spec. 2023-11-28 09:21:31 -07:00
flake.nix Bundle frontend dependencies into release. (#11) 2023-12-02 06:28:37 -07:00

README.md

Phoenix Flake Template

This is a template for constructing a environment for Elixir development (version 1.15.7, Erlang/OTP 25) with the Phoenix (version 1.7.10) framework. direnv can be used to launch a dev shell upon entering this directory (refer to .envrc). Otherwise run via:

$ nix develop

Quickstart

An empty Postgres cluster is initialized at db. To start the database, run the following:

$ pg_ctl -D db -l db/logfile -o --unix_socket_directories=@phoenix start

In the above command, @phoenix refers to an abstract socket name. Rename to whatever is appropriate for your use case. To then connect to this database instance, run:

$ psql -h @phoenix

To later shut the database down, run:

$ pg_ctl -D db stop

Afterward, you can run the Phoenix setup commands:

$ mix ecto.setup
$ mix assets.setup

and then start the local server:

$ mix phx.server

Dependencies

Backend

Mix dependencies are packaged using mix2nix. After updating your mix.lock file, make sure to re-run the following:

$ mix2nix > deps.nix

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.

Frontend

Frontend dependencies (i.e. assets found in the /assets folder) are packaged using node2nix. You can generate the relevant nix files for import using the following sequence of commands:

$ cd assets
$ rm -r node_modules  # If this directory exists.
$ node2nix -l

In the above, we must remove node_modules (if it exists). Otherwise the node packages will be included in the Nix build, influencing the outcome of node2nix. The above generates three files:

  • node-packages.nix
    • Captures the packages that can be deployed (including all its required dependencies)
  • node-env.nix
    • Contains build logic
  • default.nix
    • A composition expression allowing users to deploy the package. For an example of this deployment, refer to flake.nix

NOTE: Do not update the lock version used in assets. node2nix currently only supports lock versions 1 and 2.

Language Server

The elixir-ls LSP (version 0.17.10) and typescript-language-server (version 4.1.2) is included in this flake.

Formatting

Formatting depends on prettier (version 3.1.0) and the mix format task. A pre-commit hook is included in .githooks that can be used to format all *.exs?, *.jsx?, and *.tsx? files prior to commit. Install via:

$ git config --local core.hooksPath .githooks/

If running direnv, this hook is installed automatically when entering the directory.