summaryrefslogtreecommitdiff
path: root/modules/nixos/minecraft-server.nix
blob: f2e45fc386544865d75d6d36dec1995d25624112 (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
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
{ 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;
  jre21 = pkgs.temurin-bin-21;

  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;
    max-players = 10;
  };

  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
    # inputs.nix-minecraft.nixosModules.minecraft-servers
  ];
  # services.minecraft-servers = {
  #   enable = true;
  #   eula = true;
  #   openFirewall = true;
  #   servers.deceasedcraft-beta = {
  #     enable = true;
  #     package = pkgs.neoforgeServers.neoforge-1_20_1;
  #     serverProperties = defaults // {
  #       server-port = 25567;
  #       rcon-port = 25568;
  #       motd = "Welcome to DeceasedCraft Beta";
  #       allow-nether = false;
  #       spawn-protection = 12;
  #     };
  #     symlinks = {
  #       "mods" = /var/lib/mc-deceasedcraft-beta/mods;
  #       # "mods" = pkgs.linkFarmFromDrvs "mods" builtins.attrValues {
  #       #   DeceasedCraftBeta = fetchurl { url = "https://mediafilez.forgecdn.net/files/7623/211/DeceasedCraft_Beta-5.10.16.zip"};
  #       # };
  #     };
  #   };
  # };
  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";
        allow-nether = false;
        spawn-protection=12;
      };
    };
    instances.deceasedcraft-beta = {
      enable = true;
      inherit rsyncSSHKeys jvmOpts;
      jvmPackage = jre21;

      serverConfig = defaults // {
        server-port = 25567;
        rcon-port = 25568;
        motd = "Welcome to DeceasedCraft Beta";
        allow-nether = false;
        spawn-protection = 12;
      };
    };
  };
}