+/garnix-minecraft

git clone https://git.julia.blue/+/garnix-minecraft

Julia RyanAdd nix-minecraft95bf3c2

main
2.9 KiB87 linesraw
1{
2  description = "garnix minecraft server";
3  inputs = {
4          nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-24.05";
5       garnix-lib.url = "github:garnix-io/garnix-lib";
6      packwiz2nix.url = "github:getchoo/packwiz2nix";
7    nix-minecraft.url = "github:Infinidoge/nix-minecraft";
8  };
9  outputs = inputs: {
10    nixosConfigurations.server = inputs.nixpkgs.lib.nixosSystem {
11      modules = [
12        inputs.garnix-lib.nixosModules.garnix
13        ( { pkgs, nix-minecraft, ... }: {
14
15          # TODO: does persistence.name need to be unique per user?
16          garnix.server = { enable = true; persistence = { enable = true; name = "minecraft"; }; };
17
18          users.users.me = {
19            isNormalUser = true;
20            extraGroups = [ "wheel" "systemd-journal" ];
21            openssh.authorizedKeys.keys = [
22              "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPCatP3klEjfQPSiJNUc3FRDdz927BG1IzektpouzOZR"
23            ];
24          };
25
26          services = {
27            minecraft-server = {
28              enable = true;
29              eula = true;
30              openFirewall = true;
31              enableReload = true;
32              declarative = true;
33
34              serverProperties = {
35                gamemode = 1; # survival
36                difficulty = 3; # hard
37                motd = "minecraft server on garnix.io";
38
39                # white-list = true;
40              };
41
42              # whitelist = {
43              #   "username" = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
44              # };
45
46              package = pkgs.fabricServers.fabric-1_21_1;
47
48              # see hotspot docs for more info:
49              # https://docs.oracle.com/en/java/javase/11/gctuning/garbage-first-garbage-collector-tuning.html
50              jvmOpts = builtins.concatStringsSep " " [
51                "-Xms2G" "-Xmx3G"
52                "-XX:+CMSIncrementalPacing" "-XX:+CMSClassUnloadingEnabled"
53                "-XX:+ParallelRefProcEnabled" "-XX:+DisableExplicitGC"
54              ];
55            };
56
57            # TODO: add some mods using moderinth fetcher fixed output derivations (or packwiz)
58            # including carpet, any datapack/texturepack, and this prometheus exporter:
59            # https://github.com/cpburnz/minecraft-prometheus-exporter
60
61            # TODO: declaratively set up a grafana dashboard using:
62            # https://grafana.com/grafana/dashboards/16508-minecraft-server-stats/
63            # also try to add chat/map/online players
64
65            openssh.enable = true;
66          };
67
68          environment = {
69            enableAllTerminfo = true;
70            systemPackages = [
71              pkgs.htop
72            ];
73          };
74
75          security.sudo.wheelNeedsPassword = false;
76
77          nixpkgs = {
78            hostPlatform = "x86_64-linux";
79            config.allowUnfree = true;
80            overlays = [ nix-minecraft.overlay ];
81          };
82          system.stateVersion = "24.05";
83        })
84      ];
85    };
86  };
87}