-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
93 lines (89 loc) · 3.1 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{
description = "An Elixir Phoenix environment with a PostgreSQL service.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
devenv = {
url = "github:cachix/devenv";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
flake-utils,
devenv,
} @ inputs:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
beam = pkgs.beam;
beamPackages = beam.packagesWith beam.interpreters.erlangR25;
in {
formatter = pkgs.nixpkgs-fmt;
# https://github.com/cachix/devenv/issues/756
# https://github.com/cachix/devenv/issues/756#issuecomment-1761062524
packages.devenv-up = self.devShells.${system}.default.config.procfileScript;
devShells = let
elixir = beamPackages.elixir_1_15;
hex = beamPackages.hex;
postgresql = pkgs.postgresql_15;
in {
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
({pkgs, ...}: {
packages = (
with pkgs;
[
# Elixir.
elixir
hex
beamPackages.elixir-ls
# JavaScript.
pkgs.nodejs_20
# Deployment.
flyctl
]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [
# ExUnit notifications on macOS.
terminal-notifier
# Support Elixir file system watcher on macOS.
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.CoreServices
])
);
# Services can be started in the development shell with `devenv up`.
# Hitting `ctrl-c` in that shell will stop all running services.
services = {
postgres = {
enable = true;
package = postgresql;
# Do not create a database named for the current user.
# Our `ecto` tasks will create platform DBs for us.
createDatabase = false;
listen_addresses = "127.0.0.1";
settings = {
max_connections = 200;
jit = "off";
};
initialScript = ''
CREATE USER postgres SUPERUSER;
'';
};
};
enterShell = ''
# Place Mix/Hex files locally to the project.
export MIX_HOME=$DEVENV_STATE/mix
export HEX_HOME=$DEVENV_STATE/hex
mkdir -p $MIX_HOME
mkdir -p $HEX_HOME
# Expose Nix's hex to Mix.
export MIX_PATH="${hex}/lib/erlang/lib/hex/ebin"
export PATH=$MIX_HOME/bin:$HEX_HOME/bin:$MIX_HOME/escripts:$PATH
'';
})
];
};
};
});
}