about summary refs log tree commit diff
path: root/modules/nixos/games/minecraft.nix
blob: 2242df488f9d6e24df35744ad38d51e1d9b45212 (plain) (blame)
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
{
  config,
  inputs,
  lib,
  pkgs,
  ...
}:
with lib; let
  cfg = config.nixfiles.modules.games.minecraft;
in {
  imports = [inputs.nix-minecraft.nixosModules.minecraft-servers];

  options.nixfiles.modules.games.minecraft = {
    client.enable = mkEnableOption "Minecraft client";
    server = {
      enable = mkEnableOption "Minecraft server";

      port = mkOption {
        description = "OpenSSH server port.";
        type = types.port;
        default = 50505; # Keeping 25565 as the default is a big security risk.
      };

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

  config = mkMerge [
    (mkIf cfg.client.enable {
      hm.home.packages = [pkgs.prismlauncher];
    })
    (mkIf cfg.server.enable {
      nixfiles.modules.common.nix.allowedUnfreePackages = ["minecraft-server"];

      ark.directories = [config.services.minecraft-servers.dataDir];

      services.minecraft-servers = {
        enable = true;
        eula = true;

        openFirewall = true;

        servers.default = {
          enable = true;
          autoStart = true;

          package = pkgs.paperServers.paper-1_19_3;

          serverProperties = {
            # motd = "";
            # white-list = true;
            allow-flight = true;
            difficulty = "hard";
            enable-command-block = true;
            enforce-secure-profile = false;
            enforce-whitelist = true;
            gamemode = "survival";
            level-name = "default";
            max-players = 8;
            online-mode = false;
            previews-chat = false;
            pvp = false;
            server-port = cfg.server.port;
            snooper-enabled = false;
          };

          whitelist = {}; # TODO Fill this.

          jvmOpts =
            (concatStringsSep " " [
              "-Xms${cfg.server.memory}"
              "-Xmx${cfg.server.memory}"
              "--add-modules=jdk.incubator.vector" # Required by some plugins.
            ])
            + " ";
        };
      };

      nixpkgs.overlays = [inputs.nix-minecraft.overlay];

      my.extraGroups = [config.services.minecraft-servers.group];
    })
  ];
}

Consider giving Nix/NixOS a try! <3