summaryrefslogtreecommitdiff
path: root/modules/nixfiles/games/minecraft.nix
blob: e53f9eb86282ef0511b0b614be22f2c7f607344c (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
{
  config,
  lib,
  pkgs,
  ...
}:
with lib; let
  cfg = config.nixfiles.modules.games.minecraft;
in {
  options.nixfiles.modules.games.minecraft = {
    client.enable = mkEnableOption "Minecraft client";
    server = {
      enable = mkEnableOption "Minecraft server";

      memory = mkOption {
        description = "Amount of RAM to allocate.";
        type = types.str;
        default = "2G";
      };
    };
  };

  config = mkMerge [
    (mkIf cfg.client.enable {
      hm.home.packages = with pkgs; [pollymc];
    })
    (mkIf cfg.server.enable {
      # Configurations, opslist, whitelist and plugins are managed imperatively.
      # TODO Make it declarative.
      services.minecraft-server = {
        enable = true;
        eula = true;

        package = pkgs.minecraftServers.purpur_1_19_2;

        # TODO Make a PR fixing trailing whitespace on this.
        jvmOpts =
          (concatStringsSep " " [
            "-Xmx${cfg.server.memory}"
            "-Xms${cfg.server.memory}"
            "--add-modules=jdk.incubator.vector"
          ])
          + " ";
      };

      # Defined in /var/lib/minecraft/server.properties.
      networking.firewall.allowedTCPPorts = [55565];
    })
  ];
}