-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
261 lines (222 loc) · 6.6 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
{
description = "Pterodactyl Panel";
inputs = {
dream2nix = {
url = "github:nix-community/dream2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
mk-node-package = {
url = "github:winston0410/mkNodePackage";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
};
nixpkgs = {
url = "github:NixOS/nixpkgs/nixos-unstable";
};
};
outputs = {
self,
dream2nix,
flake-utils,
mk-node-package,
nixpkgs,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
version = "latest";
pkgs = import nixpkgs {inherit system;};
mkNodePackage = mk-node-package.lib."${system}".mkNodePackage;
php81WithExtensions = with pkgs; (php81.buildEnv {
extensions = {
enabled,
all,
}:
enabled
++ (with all; [
redis
xdebug
]);
extraConfig = ''
xdebug.mode=debug
'';
});
composer = with pkgs; (php81Packages.composer.override {php = php81WithExtensions;});
caCertificates = pkgs.runCommand "ca-certificates" {} ''
mkdir -p $out/etc/ssl/certs $out/etc/pki/tls/certs
ln -s ${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt $out/etc/ssl/certs/ca-bundle.crt
ln -s ${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt $out/etc/ssl/certs/ca-certificates.crt
ln -s ${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt $out/etc/pki/tls/certs/ca-bundle.crt
'';
caddyfile = pkgs.writeText "Caddyfile" ''
:80 {
root * /var/www/html/public/
file_server
header {
-Server
-X-Powered-By
Referrer-Policy "same-origin"
X-Frame-Options "deny"
X-XSS-Protection "1; mode=block"
X-Content-Type-Options "nosniff"
}
encode gzip zstd
php_fastcgi localhost:9000
try_files {path} {path}/ /index.php?{query}
}
'';
phpfpmConf = pkgs.writeText "php-fpm.conf" ''
[global]
error_log = /dev/stderr
daemonize = no
[www]
user = nobody
group = nobody
listen = 0.0.0.0:9000
pm = dynamic
pm.start_servers = 4
pm.min_spare_servers = 4
pm.max_spare_servers = 16
pm.max_children = 64
pm.max_requests = 256
clear_env = no
catch_workers_output = yes
decorate_workers_output = no
'';
configs = pkgs.runCommand "configs" {} ''
mkdir -p $out/etc/caddy
ln -s ${caddyfile} $out/etc/caddy/Caddyfile
ln -s ${phpfpmConf} $out/etc/php-fpm.conf
'';
src = with pkgs.lib;
cleanSource (cleanSourceWith {
filter = name: type: let
baseName = baseNameOf (toString name);
in
!(builtins.elem baseName [
".direnv"
".github"
"bootstrap/cache"
"node_modules"
"public/build"
"public/hot"
"storage"
"vendor"
".editorconfig"
".env"
".env.testing"
".envrc"
".gitignore"
".php-cs-fixer.cache"
".phpunit.result.cache"
"BUILDING.md"
"CODE_OF_CONDUCT.md"
"CONTRIBUTING.md"
"docker-compose.development.yaml"
"docker-compose.example.yaml"
"docker-compose.yaml"
"flake.lock"
"flake.nix"
"shell.nix"
]);
src = ./.;
});
app =
(dream2nix.lib.makeFlakeOutputs {
config.projectRoot = src;
source = src;
settings = [
{
translator = "composer-lock";
subsystemInfo.noDev = true;
}
];
systems = [system];
autoProjects = true;
})
.packages
."${system}"
."pterodactyl/panel";
ui = mkNodePackage {
inherit src version;
pname = "pterodactyl";
buildInputs = [];
buildPhase = ''
yarn run build
'';
installPhase = ''
mkdir -p $out
cp -r public/build $out
'';
};
panel = pkgs.stdenv.mkDerivation {
inherit src version;
pname = "pterodactyl";
buildInputs = [app ui];
installPhase = ''
cp -r ${app}/lib/vendor/pterodactyl/panel $out
chmod 755 $out
chmod 755 $out/public
mkdir -p $out/public/build
cp -r ${ui}/build/* $out/public/build
rm $out/composer.json.orig
'';
};
in {
defaultPackage = panel;
devShell = import ./shell.nix {inherit composer php81WithExtensions pkgs;};
packages = {
inherit panel;
development = with pkgs;
dockerTools.buildImage {
name = "pterodactyl/development";
tag = "panel";
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [
dockerTools.fakeNss
caCertificates
caddy
composer
configs
coreutils
mysql80
nodejs-18_x
nodePackages.npm
nodePackages.pnpm
nodePackages.yarn
php81WithExtensions
postgresql_14
];
pathsToLink = ["/bin" "/etc"];
};
};
oci = with pkgs;
dockerTools.buildImage {
name = "pterodactyl/panel";
tag = version;
copyToRoot = buildEnv {
name = "image-root";
paths = [
dockerTools.fakeNss
caCertificates
caddy
configs
php81WithExtensions
panel
];
pathsToLink = ["/bin" "/etc"];
};
config = {
Cmd = [];
};
};
};
}
);
}