summaryrefslogtreecommitdiff
path: root/modules/nixos/minecraft-server.nix
blob: 6ade951407bde7adb09cc3e829fcfa7d55f32fd2 (plain)
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
{ pkgs, lib, config, inputs, ... } :
let
  inherit (lib) concatStringsSep;
  # Keys that can access the state of each instance (read/write!) over an rsync module
  # Leave empty to disable
  rsyncSSHKeys = config.users.users.defin.openssh.authorizedKeys.keys;
  jre17 = pkgs.temurin-bin-17;

  defaults = {
    # 5 minutes tick timeout, for heavy packs
    max-tick-time = 5 * 60 * 1000;
    # It just ain't modded minecraft without flying around
    allow-flight = true;
  };

  jvmOpts = concatStringsSep " " [
    ""
    # "-XX:+UseG1GC"
    # "-XX:+ParallelRefProcEnabled"
    # "-XX:MaxGCPauseMillis=200"
    # "-XX:+UnlockExperimentalVMOptions"
    # "-XX:+DisableExplicitGC"
    # "-XX:+AlwaysPreTouch"
    # "-XX:G1NewSizePercent=40"
    # "-XX:G1MaxNewSizePercent=50"
    # "-XX:G1HeapRegionSize=16M"
    # "-XX:G1ReservePercent=15"
    # "-XX:G1HeapWastePercent=5"
    # "-XX:G1MixedGCCountTarget=4"
    # "-XX:InitiatingHeapOccupancyPercent=20"
    # "-XX:G1MixedGCLiveThresholdPercent=90"
    # "-XX:G1RSetUpdatingPauseTimePercent=5"
    # "-XX:SurvivorRatio=32"
    # "-XX:+PerfDisableSharedMem"
    # "-XX:MaxTenuringThreshold=1"
  ];

in {
  # minecraft server is closed source
  # nixpkgs.config.allowUnfree = true;

  imports = [ inputs.modded-minecraft-servers.module ];
  services.modded-minecraft-servers = {
    # This is mandatory for legal reasons.
    eula = true;

    # the name will be used for the state folder and system user.
    # in this case, the folder is '/var/lib/mc-deceasedcraft'
    # and the user is 'mc-deceasedcraft'

    instances.deceasedcraft = {
      enable = true;
      inherit rsyncSSHKeys jvmOpts;
      # jvmOpts = jvmOpts + " " + (concatStringsSep " " [
      #   "@libraries/net/minecraftforge/forge/1.18.2-40.2.4/unix_args.txt"
      # ]);
      jvmMaxAllocation = "1024m";
      jvmInitialAllocation = "512m";
      jvmPackage = jre17;

      # I believe these options match services.minecraft-server.serverProperties options
      serverConfig = defaults // {
        # Port must be unique
        server-port = 25565;
        rcon-port = 25566;
        motd = "Welcome to DeceasedCraft";
        max-players = 10;
        allow-nether = false;
        spawn-protection=12;
        max-tick-time=600000;
      };
    };
  };
}