File tree Expand file tree Collapse file tree 2 files changed +112
-0
lines changed Expand file tree Collapse file tree 2 files changed +112
-0
lines changed Original file line number Diff line number Diff line change
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
+ ```
Original file line number Diff line number Diff line change 29
29
} ;
30
30
}
31
31
) ;
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
+ ) ;
32
69
} ;
33
70
}
You can’t perform that action at this time.
0 commit comments