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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
|
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.pumpkin;
settingsFormat = pkgs.formats.toml { };
jsonFormat = pkgs.formats.json { };
hasSecret = path: settings: (lib.attrByPath path null settings) != null;
filterNulls =
v: if lib.isAttrs v then lib.mapAttrs (_: filterNulls) (lib.filterAttrs (_: x: x != null) v) else v;
settingsWithoutSecrets = filterNulls (
cfg.settings
// {
networking = cfg.settings.networking // {
rcon =
(builtins.removeAttrs cfg.settings.networking.rcon [ "passwordFile" ])
// lib.optionalAttrs (cfg.settings.networking.rcon.passwordFile != null) {
password = "@PUMPKIN_RCON_PASSWORD@";
};
proxy = cfg.settings.networking.proxy // {
velocity =
(builtins.removeAttrs cfg.settings.networking.proxy.velocity [ "secretFile" ])
// lib.optionalAttrs (cfg.settings.networking.proxy.velocity.secretFile != null) {
secret = "@PUMPKIN_VELOCITY_SECRET@";
};
};
};
}
);
configFile = settingsFormat.generate "pumpkin.toml" settingsWithoutSecrets;
whitelistFile = jsonFormat.generate "whitelist.json" cfg.whitelist.entries;
in
{
meta.maintainers = with lib.maintainers; [
DerGrumpf
jk
];
options.services.pumpkin = {
enable = lib.mkEnableOption "Pumpkin, a Minecraft server written in Rust";
package = lib.mkPackageOption pkgs "pumpkin" { };
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to open the firewall for the ports enabled under
{option}`services.pumpkin.settings.networking`.
'';
example = true;
};
dataDir = lib.mkOption {
type = lib.types.path;
default = "/var/lib/pumpkin";
description = ''
Directory holding Pumpkin's state (config, worlds, logs, etc.).
If this is a subdirectory of `/var/lib`, it is managed automatically
via systemd's `StateDirectory`; otherwise you are responsible for
ensuring the directory exists with the correct permissions.
'';
example = "/srv/pumpkin";
};
whitelist.entries = lib.mkOption {
type = lib.types.listOf (
lib.types.submodule {
options = {
uuid = lib.mkOption {
type = lib.types.str;
description = "The player's UUID, in dashed form.";
};
name = lib.mkOption {
type = lib.types.str;
description = "The player's username.";
};
};
}
);
default = [ ];
description = ''
Initial whitelist entries. Written to `whitelist.json` only if
that file doesn't already exist, since it's normally managed at
runtime via in-game/console `/whitelist` commands; changes made
this way are not overwritten by later rebuilds.
'';
example = [
{
uuid = "069a79f4-44e9-4726-a5be-fca90e38aaf5";
name = "Notch";
}
];
};
settings = lib.mkOption {
description = ''
Structured configuration written to `pumpkin.toml`, following
[RFC 42](https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md).
Any field not covered by a typed option below can still be set via
this freeform `settings` attrset. See upstream's default generated
`pumpkin.toml` and the `pumpkin-config` crate source for the full
field list.
::: {.warning}
Do not set `networking.rcon.password` or
`networking.proxy.velocity.secret` here — they would end up
world-readable in the Nix store. Use
{option}`services.pumpkin.settings.networking.rcon.passwordFile` and
{option}`services.pumpkin.settings.networking.proxy.velocity.secretFile`
instead; setting either password/secret directly is rejected at
eval time.
:::
'';
default = { };
example = lib.literalExpression ''
{
seed = "1785537519969227430";
server_links.custom.discord = "https://discord.gg/example";
}
'';
type = lib.types.submodule {
freeformType = settingsFormat.type;
options = {
default_difficulty = lib.mkOption {
type = lib.types.enum [
"Peaceful"
"Easy"
"Normal"
"Hard"
];
default = "Normal";
description = "Default game difficulty.";
example = "Hard";
};
op_permission_level = lib.mkOption {
type = lib.types.enum [
0
2
3
4
];
default = 4;
description = ''
Permission level assigned to players by the /op command. Note:
upstream's deserializer currently rejects the value `1` due to a
missing match arm — only 0, 2, 3, and 4 are accepted.
'';
};
allow_nether = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether the Nether dimension is enabled.";
};
allow_end = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether the End dimension is enabled.";
};
hardcore = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether the server runs in hardcore mode.";
example = true;
};
tps = lib.mkOption {
type = lib.types.float;
default = 20.0;
description = "Server ticks per second.";
};
default_gamemode = lib.mkOption {
type = lib.types.enum [
"Survival"
"Creative"
"Adventure"
"Spectator"
];
default = "Survival";
description = "Default gamemode assigned to new players.";
example = "Creative";
};
force_gamemode = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to force the default gamemode on every join.";
example = true;
};
scrub_ips = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to remove IP addresses from logs.";
};
use_favicon = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to serve a favicon to clients.";
};
favicon_path = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Path to an optional server favicon.";
example = "favicon.png";
};
default_level_name = lib.mkOption {
type = lib.types.str;
default = "world";
description = "Name of the default level/world folder.";
};
allow_chat_reports = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether players can send signed chat reports.";
example = true;
};
seed = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Seed string for world generation.";
example = "11238910";
};
white_list = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether the whitelist is active.";
};
enforce_whitelist = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to kick already-connected players who aren't whitelisted.";
};
logging = {
enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether Pumpkin's internal logging is enabled.";
};
threads = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to include thread names in log output.";
};
color = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to colorize log output.";
};
timestamp = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to include timestamps in log output.";
};
file = lib.mkOption {
type = lib.types.str;
default = "latest.log";
description = "Log file name, relative to the state directory.";
example = "pumpkin.log";
};
};
resource_pack = {
java = {
enabled = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to require a Java Edition resource pack.";
example = true;
};
url = lib.mkOption {
type = lib.types.str;
default = "";
description = "URL of the resource pack.";
example = "https://example.com/resourcepack.zip";
};
sha1 = lib.mkOption {
type = lib.types.str;
default = "";
description = "SHA-1 hash of the resource pack.";
example = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
};
prompt_message = lib.mkOption {
type = lib.types.str;
default = "";
description = "Message shown to players when prompted to accept the pack.";
example = "Please accept the resource pack to join.";
};
force = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to disconnect players who decline the pack.";
};
};
bedrock = {
enabled = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to require a Bedrock Edition resource pack.";
example = true;
};
force = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to disconnect players who decline the pack.";
};
packs = lib.mkOption {
type = lib.types.listOf (lib.types.either lib.types.str (lib.types.attrsOf settingsFormat.type));
default = [ ];
description = ''
Array of Bedrock resource pack definitions. Entries may be bare
strings (e.g. a UUID or path) or tables (e.g. attrsets with
name/uuid/version keys), since upstream does not document the
entry shape in more detail.
'';
example = [ "016d3a32-11f0-4a3f-8b52-8f1c3f1e5b0a" ];
};
};
};
world = {
lighting = lib.mkOption {
type = lib.types.enum [
"default"
"full"
"dark"
];
default = "default";
description = "Lighting engine mode.";
example = "full";
};
autosave_ticks = lib.mkOption {
type = lib.types.ints.unsigned;
default = 6000;
description = "Ticks between automatic world saves (0 disables autosave).";
example = 12000;
};
chunk = {
type = lib.mkOption {
type = lib.types.enum [
"anvil"
"linear"
"pump"
];
default = "anvil";
description = ''
Chunk/world storage format. `anvil` is the modern Vanilla format;
`linear` is the more compact third-party format; `pump` is
Pumpkin's own optimized format. Only `anvil` uses
`write_in_place`/`compression` — they're ignored for the other two.
'';
example = "linear";
};
write_in_place = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to write chunk data in place (anvil only).";
};
compression = {
algorithm = lib.mkOption {
type = lib.types.enum [
"GZip"
"ZLib"
"LZ4"
"Custom"
];
default = "LZ4";
description = "Chunk compression algorithm (anvil only).";
example = "ZLib";
};
level = lib.mkOption {
type = lib.types.ints.unsigned;
default = 6;
description = "Chunk compression level (anvil only).";
example = 9;
};
};
};
};
networking = {
query = {
enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to accept GameSpy4 query connections.";
};
address = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0:25565";
description = "Address:port to bind the query listener to.";
};
};
rcon = {
enabled = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to accept RCON connections.";
};
address = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0:25575";
description = "Address:port to bind the RCON listener to.";
};
max_connections = lib.mkOption {
type = lib.types.ints.unsigned;
default = 10;
description = "Maximum number of simultaneous RCON connections.";
example = 20;
};
logging = {
logged_successfully = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to log successful RCON logins.";
};
wrong_password = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to log failed RCON login attempts.";
};
commands = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to log commands run over RCON.";
};
quit = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to log RCON client disconnects.";
};
};
passwordFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
Path to a file containing the RCON password. Loaded securely
at service start via systemd's `LoadCredential` and substituted
into the generated `pumpkin.toml` in place of a placeholder
string, using `replace-secret`; never placed in the Nix store.
Compatible with sops-nix and agenix. Does not enable RCON on
its own — set
{option}`services.pumpkin.settings.networking.rcon.enabled`
as well.
'';
example = "/run/secrets/pumpkin-rcon-password";
};
};
proxy = {
enabled = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to enable proxy (Velocity/BungeeCord) support.";
example = true;
};
velocity = {
enabled = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to enable the Velocity modern forwarding protocol.";
example = true;
};
secretFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
Path to a file containing the Velocity forwarding secret. Loaded
securely at service start via systemd's `LoadCredential` and
substituted into the generated `pumpkin.toml` in place of a
placeholder string, using `replace-secret`; never placed in the
Nix store.
'';
example = "/run/secrets/pumpkin-velocity-secret";
};
};
bungeecord.enabled = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to enable BungeeCord IP forwarding.";
example = true;
};
};
lan_broadcast.enabled = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to broadcast the server on the local network.";
example = true;
};
java = {
enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to accept Java Edition connections.";
};
address = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0:25565";
description = "Address:port to bind the Java listener to.";
};
compression = {
enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to compress packets.";
};
threshold = lib.mkOption {
type = lib.types.ints.unsigned;
default = 256;
description = "Minimum packet size (in bytes) before compression is applied.";
example = 512;
};
level = lib.mkOption {
type = lib.types.ints.unsigned;
default = 4;
description = "Compression level.";
example = 5;
};
};
authentication = {
enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to require Mojang authentication for Java clients.";
};
connect_timeout = lib.mkOption {
type = lib.types.ints.unsigned;
default = 5000;
description = "Timeout (ms) for connecting to the authentication server.";
};
read_timeout = lib.mkOption {
type = lib.types.ints.unsigned;
default = 5000;
description = "Timeout (ms) for reading from the authentication server.";
};
prevent_proxy_connections = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to reject connections proxied through another server.";
};
player_profile = {
allow_banned_players = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to allow players Mojang has banned.";
};
allowed_actions = lib.mkOption {
type = lib.types.listOf (
lib.types.enum [
"FORCED_NAME_CHANGE"
"USING_BANNED_SKIN"
]
);
default = [
"FORCED_NAME_CHANGE"
"USING_BANNED_SKIN"
];
description = "Which flagged-profile actions are still permitted to join.";
};
};
textures = {
enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to fetch player skins/capes/elytras.";
};
allowed_url_schemes = lib.mkOption {
type = lib.types.listOf (
lib.types.enum [
"http"
"https"
]
);
default = [
"http"
"https"
];
description = "URL schemes allowed for texture URLs.";
};
allowed_url_domains = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [
".minecraft.net"
".mojang.com"
];
description = "Domains allowed to serve textures.";
example = [ ".mydomain.example" ];
};
types = {
skin = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to load skin textures.";
};
cape = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to load cape textures.";
};
elytra = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to load elytra textures.";
};
};
};
};
};
bedrock = {
enabled = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to accept Bedrock Edition connections.";
};
address = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0:19132";
description = "Address:port to bind the Bedrock listener to.";
};
compression = {
enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to compress packets.";
};
threshold = lib.mkOption {
type = lib.types.ints.unsigned;
default = 256;
description = "Minimum packet size (in bytes) before compression is applied.";
example = 512;
};
level = lib.mkOption {
type = lib.types.ints.unsigned;
default = 4;
description = "Compression level.";
example = 5;
};
};
authentication = {
enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to require Xbox Live authentication for Bedrock clients.";
};
connect_timeout = lib.mkOption {
type = lib.types.ints.unsigned;
default = 5000;
description = "Timeout (ms) for connecting to the authentication server.";
};
read_timeout = lib.mkOption {
type = lib.types.ints.unsigned;
default = 5000;
description = "Timeout (ms) for reading from the authentication server.";
};
};
};
};
commands = {
use_console = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether the server console accepts commands.";
};
use_tty = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to use a TTY for the console.";
};
log_console = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to log console command usage.";
};
broadcast_console_to_ops = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to broadcast console commands to operators.";
};
default_op_level = lib.mkOption {
type = lib.types.ints.between 0 4;
default = 0;
description = "Default operator permission level assigned via the console.";
example = 4;
};
};
chat.format = lib.mkOption {
type = lib.types.str;
default = "<{DISPLAYNAME}> {MESSAGE}";
description = "Chat message format template.";
example = "[{DISPLAYNAME}]: {MESSAGE}";
};
pvp = {
enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether player-vs-player combat is allowed.";
};
hurt_animation = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to show the hurt animation on PvP damage.";
};
protect_creative = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether creative-mode players are protected from PvP damage.";
};
knockback = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether PvP hits apply knockback.";
};
swing = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to show the attack swing animation.";
};
};
server_links = {
enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to advertise server links to clients.";
};
bug_report = lib.mkOption {
type = lib.types.str;
default = "https://github.com/Pumpkin-MC/Pumpkin/issues";
description = "Bug report link.";
};
support = lib.mkOption {
type = lib.types.str;
default = "";
description = "Support link.";
example = "https://example.com/support";
};
status = lib.mkOption {
type = lib.types.str;
default = "";
description = "Status page link.";
example = "https://status.example.com";
};
feedback = lib.mkOption {
type = lib.types.str;
default = "";
description = "Feedback link.";
example = "https://example.com/feedback";
};
community = lib.mkOption {
type = lib.types.str;
default = "";
description = "Community link.";
example = "https://discord.gg/example";
};
website = lib.mkOption {
type = lib.types.str;
default = "";
description = "Website link.";
example = "https://example.com";
};
forums = lib.mkOption {
type = lib.types.str;
default = "";
description = "Forums link.";
example = "https://forums.example.com";
};
news = lib.mkOption {
type = lib.types.str;
default = "";
description = "News link.";
example = "https://example.com/news";
};
announcements = lib.mkOption {
type = lib.types.str;
default = "";
description = "Announcements link.";
example = "https://example.com/announcements";
};
# server_links.custom is intentionally left to the freeform part
# of `settings`, since its shape is user-defined key/value pairs.
};
player_data = {
save_player_data = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to persist player data.";
};
save_player_cron_interval = lib.mkOption {
type = lib.types.ints.unsigned;
default = 300;
description = "Interval, in seconds, between player data saves.";
example = 600;
};
};
fun.april_fools = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to enable April Fools' Day easter eggs.";
};
recipe.send_recipes = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to send the recipe book to clients.";
};
plugins.blocked_permissions = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "Permissions plugins are blocked from granting.";
example = [ "pumpkin.admin" ];
};
advancement.save_advancements = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to persist player advancement progress.";
};
};
};
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = !(hasSecret [ "networking" "rcon" "password" ] cfg.settings);
message = "services.pumpkin: `settings.networking.rcon.password` is not allowed (world-readable in the Nix store). Use `settings.networking.rcon.passwordFile` instead.";
}
{
assertion = !(hasSecret [ "networking" "proxy" "velocity" "secret" ] cfg.settings);
message = "services.pumpkin: `settings.networking.proxy.velocity.secret` is not allowed (world-readable in the Nix store). Use `settings.networking.proxy.velocity.secretFile` instead.";
}
];
systemd.services.pumpkin = {
description = "Pumpkin Minecraft Server";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
preStart = ''
install -m600 ${configFile} "${cfg.dataDir}/pumpkin.toml"
''
+ lib.optionalString (cfg.settings.networking.rcon.passwordFile != null) ''
${lib.getExe pkgs.replace-secret} '@PUMPKIN_RCON_PASSWORD@' \
"$CREDENTIALS_DIRECTORY/rcon-password" "${cfg.dataDir}/pumpkin.toml"
''
+ lib.optionalString (cfg.settings.networking.proxy.velocity.secretFile != null) ''
${lib.getExe pkgs.replace-secret} '@PUMPKIN_VELOCITY_SECRET@' \
"$CREDENTIALS_DIRECTORY/velocity-secret" "${cfg.dataDir}/pumpkin.toml"
''
+ lib.optionalString (cfg.whitelist.entries != [ ]) ''
if [ ! -e "${cfg.dataDir}/whitelist.json" ]; then
install -m600 ${whitelistFile} "${cfg.dataDir}/whitelist.json"
fi
'';
serviceConfig = lib.mkMerge [
(lib.mkIf (lib.hasPrefix "/var/lib/" cfg.dataDir) {
StateDirectory = lib.last (lib.splitString "/" cfg.dataDir);
})
{
ExecStart = lib.getExe cfg.package;
LoadCredential =
lib.optional (
cfg.settings.networking.rcon.passwordFile != null
) "rcon-password:${cfg.settings.networking.rcon.passwordFile}"
++ lib.optional (
cfg.settings.networking.proxy.velocity.secretFile != null
) "velocity-secret:${cfg.settings.networking.proxy.velocity.secretFile}";
Restart = "on-failure";
RestartSec = 5;
StartLimitIntervalSec = 120;
StartLimitBurst = 5;
TimeoutStopSec = 120;
LimitNOFILE = 65536;
DynamicUser = true;
WorkingDirectory = cfg.dataDir;
NoNewPrivileges = true;
PrivateTmp = true;
ProtectSystem = "strict";
ProtectHome = true;
CapabilityBoundingSet = "";
}
];
};
networking.firewall = lib.mkIf cfg.openFirewall {
allowedTCPPorts =
lib.optional cfg.settings.networking.java.enabled (
lib.toInt (lib.last (lib.splitString ":" cfg.settings.networking.java.address))
)
++ lib.optional (
cfg.settings.networking.rcon.enabled || cfg.settings.networking.rcon.passwordFile != null
) (lib.toInt (lib.last (lib.splitString ":" cfg.settings.networking.rcon.address)));
allowedUDPPorts = lib.optional cfg.settings.networking.bedrock.enabled (
lib.toInt (lib.last (lib.splitString ":" cfg.settings.networking.bedrock.address))
);
};
};
}
|