Hide & Seek - Fort Collins
  • Elixir 44.7%
  • Nix 35.1%
  • TypeScript 16.9%
  • JavaScript 1.7%
  • CSS 1.2%
  • Other 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2024-06-02 13:40:49 -06:00
.githooks Initial commit. 2024-03-24 10:36:30 -06:00
assets Auth is not required on new user creation. 2024-06-02 13:40:49 -06:00
config Add hideandseek.live (sub)domains. 2024-05-18 12:20:05 -06:00
lib Auth is not required on new user creation. 2024-06-02 13:40:49 -06:00
priv Add eye in speech bubble favicon. 2024-05-14 10:36:19 -06:00
test Add new user creation endpoint. 2024-05-23 17:21:27 -06:00
.envrc Initial commit. 2024-03-24 10:36:30 -06:00
.formatter.exs Initial commit. 2024-03-24 10:36:30 -06:00
.gitignore Initial commit. 2024-03-24 10:36:30 -06:00
default.nix Add a default.nix file. 2024-04-12 11:31:28 -06:00
deps.nix Install corsica. 2024-05-18 12:33:45 -06:00
flake.lock Add a default.nix file. 2024-04-12 11:31:28 -06:00
flake.nix v0.2.0 -> v0.2.1 2024-05-13 08:36:49 -06:00
mix.exs Bypass CORS with relative base URL. 2024-05-18 12:37:48 -06:00
mix.lock Install corsica. 2024-05-18 12:33:45 -06:00
README.md Add instructions on seeding the database. 2024-04-12 18:16:02 -06:00

Reconn(ect)

This is the backend and web application for hide and seek. We use Elixir (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=@reconn start

In the above command, @reconn 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 @reconn

To later shut the database down, run:

$ pg_ctl -D db stop

Afterward, you can run the Phoenix setup commands:

$ mix 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 \
>   --development \
>   --output nix/dev/node-packages.nix \
>   --composition nix/dev/default.nix \
>   --node-env nix/dev/node-env.nix -l
$ node2nix \
>   --output nix/prod/node-packages.nix \
>   --composition nix/prod/default.nix \
>   --node-env nix/prod/node-env.nix \
>   -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.

Deployment

Seeding

When first launching the service, we need to remote shell into our running server and seed the database:

$ nix-shell -p elixir
$ iex --sname seed --erl "-setcookie <COOKIE>"
> Node.connect(:<NODE>@<HOST>)
> Node.spawn(:<NODE>@<HOST>, fn -> Reconn.Repo.seed() end)

<COOKIE> can be found by looking under the /releases directory of the build. <NODE> likely refers to the name of the Erlang node (e.g. reconn) and <HOST> refers to the hostname of the machine the Erland node is on.