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

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

      port = mkOption {
        description = "Server port.";
        type = types.port;
        default = 25565;
      };

      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;
          };

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

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

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

Consider giving Nix/NixOS a try! <3