-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevenv.nix
142 lines (119 loc) · 3.33 KB
/
devenv.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
{ config, pkgs, lib, ... }:
let
caddyUrl = config.env.APP_URL;
mysqlDatabase = config.env.DB_DATABASE;
mysqlUsername = config.env.DB_USERNAME;
mysqlPassword = config.env.DB_PASSWORD;
redisPassword = config.env.REDIS_PASSWORD;
reverbHost = config.env.REVERB_SERVER_HOST;
reverbPort = config.env.REVERB_SERVER_PORT;
in {
env = let mkFallback = lib.mkOverride 1500;
in {
APP_ENV = lib.mkForce "devenv";
APP_HOST = mkFallback "localhost";
APP_PORT = mkFallback "8000";
APP_SCHEME = mkFallback "http";
APP_URL = mkFallback "${config.env.APP_SCHEME}://${config.env.APP_HOST}:${config.env.APP_PORT}";
DB_DATABASE = mkFallback "bibroomz";
DB_PASSWORD = mkFallback "bibroomz";
DB_USERNAME = mkFallback "bibroomz";
MAIL_HOST = mkFallback "localhost";
MAIL_MAILER = mkFallback "mailpit";
REDIS_PASSWORD = mkFallback "";
REVERB_HOST = mkFallback "localhost";
REVERB_PORT = mkFallback "6001";
REVERB_SCHEME = mkFallback "http";
REVERB_SERVER_HOST = mkFallback "127.0.0.1";
REVERB_SERVER_PORT = mkFallback "6001";
VITE_API_URL = mkFallback "${config.env.APP_URL}";
};
cachix.enable = false;
dotenv = {
enable = true;
disableHint = true;
filename = ".env.devenv";
};
languages = {
javascript = {
enable = true;
npm.enable = true;
package = pkgs.nodejs_20;
};
php = {
enable = true;
package = pkgs.php83.buildEnv { extensions = { all, enabled }: enabled ++ [ all.redis ]; };
fpm.pools.web.settings = {
"clear_env" = "no";
"pm" = "dynamic";
"pm.max_children" = 10;
"pm.min_spare_servers" = 1;
"pm.max_spare_servers" = 5;
"pm.start_servers" = 2;
};
};
};
process.before = "installScript";
processes = {
build.exec = ''
php artisan ziggy:generate
npm run build -- --mode devenv
'';
queue-worker = {
exec = "php artisan queue:listen";
process-compose.availability.restart = "always";
};
schedule-worker.exec = "php artisan schedule:work";
reverb.exec = "php artisan reverb:start --debug";
};
scripts = {
installScript.exec = ''
set -x
composer install
npm clean-install --silent
'';
setupScript.exec = ''
set -x
php artisan migrate
php artisan db:seed
'';
};
services = {
caddy = {
enable = true;
config = lib.mkIf (config.env.APP_SCHEME == "https") ''
{
auto_https disable_redirects
skip_install_trust
servers {
listener_wrappers {
http_redirect
tls
}
}
}
'';
virtualHosts."${caddyUrl}".extraConfig = ''
root * public
php_fastcgi unix/${config.languages.php.fpm.pools.web.socket}
file_server
reverse_proxy /app/* ${reverbHost}:${reverbPort}
tls internal
'';
};
mailpit.enable = true;
mysql = {
enable = true;
ensureUsers = [{
name = mysqlUsername;
password = mysqlPassword;
ensurePermissions = { "${mysqlDatabase}.*" = "ALL PRIVILEGES"; };
}];
initialDatabases = [{ name = mysqlDatabase; }];
};
redis = {
enable = true;
extraConfig = if redisPassword == "" then "" else "requirepass ${redisPassword}";
};
};
}