1{ lib, pkgs, ... }:
2{
3 name = "velocity";
4 meta.maintainers = [ lib.maintainers.Tert0 ];
5
6 nodes.server =
7 { ... }:
8 {
9 imports =
10 let
11 mkVelocityService = name: pkg: {
12 systemd.sockets.${name} = {
13 socketConfig = {
14 ListenFIFO = "/run/${name}.stdin";
15 Service = "${name}";
16 };
17 };
18 systemd.services.${name} = {
19 serviceConfig = {
20 ExecStart = "${pkg}/bin/velocity";
21 DynamicUser = true;
22 StateDirectory = "${name}";
23 WorkingDirectory = "/var/lib/${name}";
24
25 Sockets = "${name}.socket";
26 StandardInput = "socket";
27 StandardOutput = "journal";
28 StandardError = "journal";
29 };
30 };
31 };
32 in
33 [
34 (mkVelocityService "velocity-without-native" (
35 pkgs.velocity.override { withVelocityNative = false; }
36 ))
37 (mkVelocityService "velocity-with-native" (pkgs.velocity.override { withVelocityNative = true; }))
38 ];
39
40 environment.systemPackages = [ (pkgs.python3.withPackages (p: [ p.mcstatus ])) ];
41 };
42
43 testScript = ''
44 def test_velocity(name: str, native: bool):
45 server.start_job(name)
46 server.wait_for_unit(name);
47 server.wait_for_open_port(25565)
48 server.wait_until_succeeds(f"journalctl -b -u {name} | grep -q 'Booting up Velocity nixpkgs-${pkgs.velocity.version}...'")
49 connections_startup_query = "Connections will use epoll channels, libdeflate (.+) compression, OpenSSL 3.x.x (.+) ciphers" if native else "Connections will use epoll channels, Java compression, Java ciphers"
50 server.wait_until_succeeds(f"journalctl -b -u {name} | grep -q -E '{connections_startup_query}'")
51 server.wait_until_succeeds(f"journalctl -b -u {name} | grep -q 'Done ([0-9]*.[0-9]*s)!'");
52
53 _, status_result = server.execute("python -m mcstatus localhost:25565 status")
54 assert "A Velocity Server" in status_result
55
56 server.execute(f"echo stop > /run/{name}.stdin")
57 server.wait_for_closed_port(25565);
58
59 test_velocity("velocity-without-native", False)
60 test_velocity("velocity-with-native", True)
61 '';
62}