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

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

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

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

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

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

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

        openFirewall = true;

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

          # https://api.papermc.io/v2/projects/paper
          # https://github.com/Infinidoge/nix-minecraft/blob/master/pkgs/paper-servers/lock.json
          package = pkgs.minecraftServers.paper-1_21_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 =
            (lib.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