-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflake.nix
375 lines (336 loc) · 13.3 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# This file is used mainly for continuous integration testing:
# https://headcounter.org/hydra/jobset/picster/godot-trello#tabs-jobs
{
description = "Godot - Trello Reporting Tool";
outputs = { self, nixpkgs }: let
inherit (nixpkgs) lib;
systems = [ "x86_64-linux" ];
in {
packages = lib.genAttrs systems (system: let
pkgs = nixpkgs.legacyPackages.${system};
mkGodotGut = isHeadless: let
godot = if isHeadless then pkgs.godot-headless else pkgs.godot;
godotCmd = if isHeadless then "godot-headless" else "godot";
gutSrc = pkgs.stdenv.mkDerivation {
pname = "gut";
version = "7.0.0";
src = pkgs.fetchFromGitHub {
owner = "bitwes";
repo = "Gut";
rev = "v7.0.0";
sha256 = "0zjz33hxay2w3qbgv7x24izcm93bj0f6x4mayxzz10kl0aa6w9rq";
};
postPatch = ''
sed -i -e 's!res://addons/gut/fonts!'"$out/addons/gut/fonts"'!' \
addons/gut/GutScene.gd
'';
installPhase = "cp -r . \"$out\"";
};
godotGut = godot.overrideAttrs (drv: {
inherit gutSrc;
sconsFlags = (drv.sconsFlags or "")
+ " system_certs_path=/etc/ssl/certs/ca-certificates.crt";
postPatch = (drv.postPatch or "") + ''
# Use system certs if user did not override project settings.
#
# This essentially implements the patch from OpenSUSE at
# https://bit.ly/2SKeYfi but without conflicts.
#
# The issue is tracked upstream at:
# https://github.com/godotengine/godot/issues/22232
sed -i -e '/^#include/ {
a #include <string.h>
:l; n
/#ifdef BUILTIN_CERTS_ENABLED/ {
i else if (strcmp(_SYSTEM_CERTS_PATH, "") != 0) \
default_certs->load(_SYSTEM_CERTS_PATH);
}
bl
}' modules/mbedtls/crypto_mbedtls.cpp
# Godot only has a single base path, where all resources are loaded
# from. We could just copy over Gut into the source tree, but this
# would also mean that we need to keep it updated and prevent
# people from staging it in Git.
#
# Fortunately, there is an undocumented way to do path remapping,
# but it relies on the path_remap/remapped_paths setting for the
# project.
#
# So instead, we just patch the function that is responsible for
# loading the path remaps and inject all files from Gat.
find "$gutSrc" -path '*/addons/gut/*' \
-printf 'path_remaps["res://%P"] = "%p";\n' \
> core/io/path-remaps.h
sed -i -e '/ResourceLoader::load_path_remaps.*{/ {
a #include "path-remaps.h"
}' core/io/resource_loader.cpp
'';
});
in pkgs.writeScriptBin "godot-gut" ''
#!${pkgs.stdenv.shell}
exec ${godotGut}/bin/${godotCmd} --path "$PWD" \
-s "${gutSrc}/addons/gut/gut_cmdln.gd" "$@"
'';
in {
godot-gut = mkGodotGut false;
godot-gut-headless = mkGodotGut true;
gdtoolkit = pkgs.python3Packages.buildPythonApplication rec {
pname = "gdtoolkit";
version = "3.2.8";
src = pkgs.fetchFromGitHub {
owner = "Scony";
repo = "godot-gdscript-toolkit";
rev = version;
sha256 = "1i0y2n636lnmgdivnq49zjd99dh3k4rjcpdyn20qfd2g2w8dmk6j";
};
propagatedBuildInputs = [
# We need to have *exactly* version 0.8.0 to prevent test failures
# and ultimately gdtoolkit from misbehaving.
(pkgs.python3Packages.lark-parser.overridePythonAttrs (drv: rec {
version = "0.8.0";
src = pkgs.fetchFromGitHub {
owner = "lark-parser";
repo = "lark";
rev = version;
sha256 = "sha256-su7kToZ05OESwRCMPG6Z+XlFUvbEb3d8DgsTEcPJMg4=";
};
}))
pkgs.python3Packages.docopt
pkgs.python3Packages.pyyaml
pkgs.python3Packages.setuptools
];
checkInputs = [
pkgs.python3Packages.pytest
(pkgs.writeScriptBin "godot-server" ''
#!${pkgs.stdenv.shell}
exec ${pkgs.godot-headless}/bin/godot-headless "$@"
'')
];
checkPhase = "HOME=\"$PWD\" PATH=\"$out/bin:$PATH\" pytest";
};
minitrello = pkgs.runCommand "minitrello" rec {
uwsgi = pkgs.uwsgi.override {
plugins = [ "python3" ];
withPAM = false;
withSystemd = true;
};
nativeBuildInputs = [
pkgs.python3Packages.flake8
pkgs.python3Packages.mypy
];
python3 = pkgs.python3.withPackages (p: lib.singleton p.flask);
src = tests/minitrello.py;
cmdArgs = lib.escapeShellArgs [
"${uwsgi}/bin/uwsgi" "--die-on-term" "--auto-procname"
"--procname-prefix-spaced=[minitrello]"
"--plugins" "python3" "--callable=app" "--enable-threads"
"--pythonpath" "${python3}/${python3.sitePackages}"
];
} ''
flake8 "$src"
mypy "$src"
install -vD -m 0644 "$src" "$out/libexec/minitrello.py"
mkdir -p "$out/bin"
{ echo ${lib.escapeShellArg "#!${pkgs.stdenv.shell}"}
echo exec "$cmdArgs" --mount "=$out/libexec/minitrello.py" \
--http 127.0.0.1:4444
} > "$out/bin/minitrello"
chmod +x "$out/bin/minitrello"
'';
trello-reporting = pkgs.runCommand "godot-trello-reporting" {
src = self;
nativeBuildInputs = [ self.packages.${system}.gdtoolkit ];
} ''
HOME="$PWD" gdlint "$src"
mkdir -p "$out/libexec"
libexec="$out/libexec/godot-trello-reporting"
cp -rT "$src" "$libexec"
mkdir -p "$out/bin"
{ echo ${lib.escapeShellArg "#!${pkgs.stdenv.shell}"}
echo exec ${pkgs.godot}/bin/godot \
"$libexec/src/Trello_Reporting_Tool.tscn" \
'"$@"'
} > "$out/bin/godot-trello-reporting"
chmod +x "$out/bin/godot-trello-reporting"
'';
proxy = pkgs.runCommand "godot-trello-proxy" {
src = src/proxy.php;
nativeBuildInputs = [ pkgs.php ];
cmdArgs = lib.escapeShellArgs [
"${pkgs.php}/bin/php"
"-d" "error_reporting=E_ALL"
"-d" "display_errors=Off"
"-d" "log_errors=On"
"-S" "127.0.0.1:3333"
"-t" "${placeholder "out"}/libexec/godot-trello-proxy"
];
} ''
php -l "$src"
install -vD -m 0644 "$src" "$out/libexec/godot-trello-proxy/proxy.php"
mkdir -p "$out/bin"
{ echo ${lib.escapeShellArg "#!${pkgs.stdenv.shell}"}
echo exec "$cmdArgs" '"$@"'
} > "$out/bin/godot-trello-proxy"
chmod +x "$out/bin/godot-trello-proxy"
'';
});
checks = lib.genAttrs systems (system: let
pkgs = nixpkgs.legacyPackages.${system};
inherit (self.packages.${system}) godot-gut trello-reporting;
srcPath = "${trello-reporting}/libexec/godot-trello-reporting";
testRunner = pkgs.writeScriptBin "test-runner" ''
#!${pkgs.stdenv.shell} -e
cd ${lib.escapeShellArg srcPath}
exec ${godot-gut}/bin/godot-gut \
-gtest=res://tests/integration.gd -gexit
'';
mkSnakeoilCert = domain: pkgs.runCommand "snakeoil-cert" {
nativeBuildInputs = [ pkgs.openssl ];
OPENSSL_CONF = pkgs.writeText "snakeoil.cnf" ''
[req]
default_bits = 4096
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn
[dn]
CN = ${domain}
[req_ext]
subjectAltName = DNS:${domain}
'';
} ''
mkdir -p "$out"
openssl req -x509 -newkey rsa:2048 -nodes -keyout "$out/key.pem" \
-out "$out/cert.pem" -days 36500
'';
certs.proxy = mkSnakeoilCert "proxy.example";
certs.trello = mkSnakeoilCert "api.trello.com";
commonConfig = { config, nodes, ... }: {
networking.firewall.enable = false;
networking.nameservers = lib.mkForce [
nodes.resolver.config.networking.primaryIPAddress
];
security.pki.certificateFiles = let
getPubkey = drv: "${drv}/cert.pem";
in lib.mapAttrsToList (lib.const getPubkey) certs;
networking.extraHosts = let
allVhosts = config.services.httpd.virtualHosts
// config.services.nginx.virtualHosts;
in lib.concatMapStrings (domain: ''
127.0.0.1 ${domain}
${config.networking.primaryIPAddress} ${domain}
'') (lib.attrNames allVhosts);
};
in {
integration = import (nixpkgs + "/nixos/tests/make-test-python.nix") {
name = "godot-trello-reporting";
nodes.resolver = nixpkgs + "/nixos/tests/common/resolver.nix";
nodes.client = {
imports = [ commonConfig (nixpkgs + "/nixos/tests/common/x11.nix") ];
hardware.opengl.driSupport = true;
virtualisation.memorySize = 1024;
environment.systemPackages = lib.singleton testRunner;
boot.kernelModules = [ "snd-dummy" ];
sound.enable = true;
};
nodes.proxy = { config, ... }: {
imports = [ commonConfig ];
services.httpd.enable = true;
services.httpd.enablePHP = true;
services.httpd.adminAddr = "admin@proxy.example";
services.httpd.virtualHosts."proxy.example" = {
forceSSL = true;
enableACME = false;
sslServerCert = "${certs.proxy}/cert.pem";
sslServerKey = "${certs.proxy}/key.pem";
documentRoot = pkgs.runCommand "docroot" {
src = let
inherit (self.packages.${config.nixpkgs.system}) proxy;
in "${proxy}/libexec/godot-trello-proxy/proxy.php";
YOUR_TRELLO_API_KEY = "6686ab7c98c9478a858c7509cce4e567";
YOUR_TRELLO_API_TOKEN = "903a96bcb0f2457986ed6f4e4d4d5016"
+ "04ea488a45034e57aea56a16ed59528a";
YOUR_TRELLO_LIST_ID = "44b3a1b2db65488e8ba5a9df";
} ''
mkdir "$out"
substitute "$src" "$out/proxy.php" \
--subst-var YOUR_TRELLO_API_KEY \
--subst-var YOUR_TRELLO_API_TOKEN \
--subst-var YOUR_TRELLO_LIST_ID
'';
};
};
nodes.trello = { config, pkgs, ... }: {
imports = [ commonConfig ];
services.nginx.enable = true;
services.nginx.virtualHosts."api.trello.com" = {
forceSSL = true;
enableACME = false;
sslCertificate = "${certs.trello}/cert.pem";
sslCertificateKey = "${certs.trello}/key.pem";
locations."/".extraConfig = ''
include ${config.services.nginx.package}/conf/uwsgi_params;
uwsgi_intercept_errors on;
uwsgi_ignore_client_abort on;
uwsgi_pass unix:///run/minitrello.socket;
'';
};
systemd.sockets.minitrello = {
description = "Socket for minimal Trello API Server";
wantedBy = [ "sockets.target" ];
socketConfig.ListenStream = "/run/minitrello.socket";
socketConfig.SocketUser = "root";
socketConfig.SocketGroup = "nginx";
socketConfig.SocketMode = "0660";
};
systemd.services.minitrello = {
description = "Minimal Trello API Server";
requiredBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig.Type = "notify";
serviceConfig.DynamicUser = true;
serviceConfig.ExecStart = let
inherit (self.packages.${config.nixpkgs.system}) minitrello;
extraArgs = lib.escapeShellArgs [
"--mount" "=${minitrello}/libexec/minitrello.py"
"--socket" "/run/minitrello.socket"
];
in "${minitrello.cmdArgs} ${extraArgs}";
};
};
testScript = ''
# fmt: off
start_all()
resolver.wait_for_unit('bind.service')
trello.wait_for_unit('nginx.service')
trello.wait_for_open_port(443)
proxy.wait_for_unit('httpd.service')
proxy.wait_for_open_port(443)
client.wait_for_x()
client.succeed('ping -c1 proxy.example >&2')
proxy.succeed('ping -c1 api.trello.com >&2')
client.succeed('test-runner >&2')
'';
} { inherit system; };
});
defaultPackage = let
getPackage = system: self.packages.${system}.trello-reporting;
in lib.genAttrs systems getPackage;
devShell = lib.genAttrs systems (system: let
pkgs = nixpkgs.legacyPackages.${system};
in pkgs.mkShell {
nativeBuildInputs = [
pkgs.godot
self.packages.${system}.godot-gut
self.packages.${system}.gdtoolkit
self.packages.${system}.proxy
];
});
hydraJobs = {
tests = self.checks.x86_64-linux;
packages = removeAttrs self.packages.x86_64-linux [
"godot-gut" "godot-gut-headless" "gdtoolkit"
];
};
};
}