Skip to content

Commit 94900ca

Browse files
committed
Working instructions with mismatched Tailwind/esbuild
1 parent 684c8f4 commit 94900ca

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Start a new Phoenix project with Nix
2+
3+
## Prerequisites
4+
5+
- Nix
6+
- Local Postgres
7+
- (optional) [direnv](https://direnv.net/)
8+
9+
### direnv
10+
11+
Examples assume you've set this up. Use `nix develop .` instead of `direnv allow` if you don't want direnv.
12+
13+
To install with Home Manager and nix-direnv caching:
14+
15+
```nix
16+
home.direnv = {
17+
enable = true;
18+
nix-direnv.enable = true;
19+
};
20+
```
21+
22+
## Instructions
23+
24+
### Initialise
25+
26+
```shell
27+
mkdir my_new_project # underscores mean you can skip an argument to mix phx.new
28+
cd my_new_project
29+
git init
30+
nix flake init -t github:code-supply/nix-phoenix
31+
direnv allow
32+
mix phx.new . # and say Y to everything
33+
echo .direnv >> .gitignore # we don't want to store the direnv cache in git
34+
```
35+
36+
### Add deps_nix
37+
38+
Follow the [deps_nix installation instructions](https://github.com/code-supply/deps_nix?tab=readme-ov-file#installation).
39+
40+
Fetch the deps_nix dependency:
41+
42+
```shell
43+
mix deps.get
44+
```
45+
46+
### Generate the initial deps.nix file
47+
48+
```shell
49+
mix deps.nix
50+
```
51+
52+
### Build the project
53+
54+
```shell
55+
git add . # make files available to the Nix flake
56+
nix build --print-build-logs # short option is -L
57+
```
58+
59+
### Create a local database
60+
61+
```shell
62+
DATABASE_URL=ecto://postgres:postgres@localhost/my_new_project \
63+
MIX_ENV=prod \
64+
mix ecto.create
65+
```
66+
67+
### Run the built artifact
68+
69+
```shell
70+
DATABASE_URL=ecto://postgres:postgres@localhost/my_new_project \
71+
PHX_SERVER=true \
72+
RELEASE_COOKIE=asdf \
73+
SECRET_KEY_BASE="$(mix phx.gen.secret)" \
74+
./result/bin/my_new_project start
75+
```

flake-template/flake.nix

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,42 @@
2929
};
3030
}
3131
);
32+
33+
packages = forAllSystems (
34+
{ pkgs, ... }:
35+
let
36+
mixNixDeps = pkgs.callPackages ./deps.nix { };
37+
in
38+
{
39+
default =
40+
with pkgs;
41+
beamPackages.mixRelease {
42+
inherit mixNixDeps;
43+
pname = "my_phoenix_app";
44+
src = ./.;
45+
version = "0.0.0";
46+
47+
DATABASE_URL = "";
48+
SECRET_KEY_BASE = "";
49+
50+
postBuild = ''
51+
tailwind_path="$(mix do \
52+
app.config --no-deps-check --no-compile, \
53+
eval 'Tailwind.bin_path() |> IO.puts()')"
54+
esbuild_path="$(mix do \
55+
app.config --no-deps-check --no-compile, \
56+
eval 'Esbuild.bin_path() |> IO.puts()')"
57+
58+
ln -sfv ${tailwindcss}/bin/tailwindcss "$tailwind_path"
59+
ln -sfv ${esbuild}/bin/esbuild "$esbuild_path"
60+
ln -sfv ${mixNixDeps.heroicons} deps/heroicons
61+
62+
mix do \
63+
app.config --no-deps-check --no-compile, \
64+
assets.deploy --no-deps-check
65+
'';
66+
};
67+
}
68+
);
3269
};
3370
}

0 commit comments

Comments
 (0)