From ceeec17202bc7e0e0a69737b169a580901b50b70 Mon Sep 17 00:00:00 2001 From: Nico Date: Sat, 3 May 2025 16:16:04 +1000 Subject: [PATCH] minecraft: init --- flake.lock | 102 ++++++++++++++++-- flake.nix | 6 +- modules/games/server/minecraft/building.nix | 29 +++++ modules/games/server/minecraft/default.nix | 15 +++ .../games/server/minecraft/fabric-modless.nix | 37 +++++++ modules/games/server/minecraft/velocity.nix | 89 +++++++++++++++ 6 files changed, 269 insertions(+), 9 deletions(-) create mode 100644 modules/games/server/minecraft/building.nix create mode 100644 modules/games/server/minecraft/default.nix create mode 100644 modules/games/server/minecraft/fabric-modless.nix create mode 100644 modules/games/server/minecraft/velocity.nix diff --git a/flake.lock b/flake.lock index bd259fb..98238b7 100644 --- a/flake.lock +++ b/flake.lock @@ -52,6 +52,22 @@ "type": "github" } }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -73,6 +89,24 @@ "type": "github" } }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ @@ -184,17 +218,37 @@ "type": "github" } }, - "nixpkgs": { + "nix-minecraft": { + "inputs": { + "flake-compat": "flake-compat_2", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, "locked": { - "lastModified": 1744232761, - "narHash": "sha256-gbl9hE39nQRpZaLjhWKmEu5ejtQsgI5TWYrIVVJn30U=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "f675531bc7e6657c10a18b565cfebd8aa9e24c14", + "lastModified": 1744768706, + "narHash": "sha256-7W63qdst98cXE4j/QDF1L3OHz5N5JjcfTVL17a4a3kw=", + "owner": "Infinidoge", + "repo": "nix-minecraft", + "rev": "46be353e058e970480a9c62ee94a0d1ad2f0c569", "type": "github" }, "original": { - "owner": "NixOS", + "owner": "Infinidoge", + "repo": "nix-minecraft", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1742889210, + "narHash": "sha256-hw63HnwnqU3ZQfsMclLhMvOezpM7RSB0dMAtD5/sOiw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "698214a32beb4f4c8e3942372c694f40848b360d", + "type": "github" + }, + "original": { + "owner": "nixos", "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" @@ -216,6 +270,22 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1744232761, + "narHash": "sha256-gbl9hE39nQRpZaLjhWKmEu5ejtQsgI5TWYrIVVJn30U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f675531bc7e6657c10a18b565cfebd8aa9e24c14", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "pre-commit-hooks-nix": { "inputs": { "flake-compat": [ @@ -249,7 +319,8 @@ "jovian": "jovian", "lanzaboote": "lanzaboote", "nix-darwin": "nix-darwin", - "nixpkgs": "nixpkgs" + "nix-minecraft": "nix-minecraft", + "nixpkgs": "nixpkgs_2" } }, "rust-overlay": { @@ -272,6 +343,21 @@ "repo": "rust-overlay", "type": "github" } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 224ad4c..9e441b5 100644 --- a/flake.nix +++ b/flake.nix @@ -12,9 +12,10 @@ disko.inputs.nixpkgs.follows = "nixpkgs"; jovian.url = "github:Jovian-Experiments/Jovian-NixOS"; jovian.inputs.nixpkgs.follows = "nixpkgs"; + nix-minecraft.url = "github:Infinidoge/nix-minecraft"; }; - outputs = { self, nixpkgs, lanzaboote, nix-darwin, disko, jovian, ... }@inputs: { + outputs = { self, nixpkgs, lanzaboote, nix-darwin, disko, jovian, nix-minecraft, ... }@inputs: { nixosConfigurations.pluto = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ @@ -23,6 +24,9 @@ ./modules/nix/linux.nix ./modules/shell.nix + nix-minecraft.nixosModules.minecraft-servers + { nixpkgs.overlays = [ inputs.nix-minecraft.overlay ]; } + ./modules/games/server/minecraft/default.nix ./modules/services/karakeep.nix ./modules/services/uptime-kuma.nix ./modules/services/pocketid.nix diff --git a/modules/games/server/minecraft/building.nix b/modules/games/server/minecraft/building.nix new file mode 100644 index 0000000..db7f6a8 --- /dev/null +++ b/modules/games/server/minecraft/building.nix @@ -0,0 +1,29 @@ +{ config, pkgs, ... }: + +{ + services.minecraft-servers.servers.building = { + enable = true; + package = pkgs.paperServers.paper-1_21_5; + autoStart = true; + jvmOpts = "-Xms4096M -Xmx4096M"; + + serverProperties = { + server-port = 30002; + difficulty = 3; + max-players = 30; + online-mode = false; + gamemode = "creative"; + }; + + symlinks = { + "plugins/Worldedit.jar" = pkgs.fetchurl { url = "https://cdn.modrinth.com/data/1u6JkXh5/versions/NhJaettg/worldedit-bukkit-7.3.12-beta-01.jar"; sha256 = "sha256-NP5ALYQe6DVVAeTeDGxySKZ8sjQnLjQc8PTbDS+Lbd4="; }; + "plugins/EssentialsX.jar" = pkgs.fetchurl { url = "https://cdn.modrinth.com/data/hXiIvTyT/versions/SKQwLLoQ/EssentialsX-2.21.0.jar"; sha256 = "sha256-VwQyKlSDa5hLEQ9+Igi67RiGwu/tREa0l+Z+US/skMU="; }; + }; + }; + + services.minecraft-servers.servers.velocity.symlinks."velocity.toml".value = { + servers = { + building = "127.0.0.1:30002"; + }; + }; +} diff --git a/modules/games/server/minecraft/default.nix b/modules/games/server/minecraft/default.nix new file mode 100644 index 0000000..81e8fee --- /dev/null +++ b/modules/games/server/minecraft/default.nix @@ -0,0 +1,15 @@ +{ config, inputs, ... }: + +{ + imports = [ + ./velocity.nix + ./fabric-modless.nix + ./building.nix + ]; + + services.minecraft-servers = { + enable = true; + eula = true; + dataDir = "/var/lib/minecraft"; + }; +} diff --git a/modules/games/server/minecraft/fabric-modless.nix b/modules/games/server/minecraft/fabric-modless.nix new file mode 100644 index 0000000..1c32ebd --- /dev/null +++ b/modules/games/server/minecraft/fabric-modless.nix @@ -0,0 +1,37 @@ +{ config, pkgs, ... }: + +{ + services.minecraft-servers.servers.fabric-modless = { + enable = true; + package = pkgs.fabricServers.fabric-1_21_5; + autoStart = true; + jvmOpts = "-Xms4096M -Xmx4096M"; + + serverProperties = { + server-port = 30001; + difficulty = 3; + max-players = 30; + }; + + symlinks = { + mods = pkgs.linkFarmFromDrvs "mods" (builtins.attrValues { + FabricAPI = pkgs.fetchurl { url = "https://cdn.modrinth.com/data/P7dR8mSH/versions/FZ4q3wQK/fabric-api-0.119.9%2B1.21.5.jar"; sha512 = "4eec629514cba71e4792c1ebf357e574713e5fdb3c01c6e7d132ed631bdeaab0b38bcab84d4ade14c6966c24f9938026da2e65c25b58cde4ce9710c49d147e87"; }; + Chunky = pkgs.fetchurl { url = "https://cdn.modrinth.com/data/fALzjamp/versions/mhLtMoLk/Chunky-Fabric-1.4.36.jar"; sha512 = "65a201c246c95f6189a16e715d944e4a7ca7f44a8c4a39c8e6523d8c58e331d6611c78deff050cb4a2a2d80c5b8d84e3593a9b8ff961f7aee3d171a4ef7af2c7"; }; + Ferritecore = pkgs.fetchurl { url = "https://cdn.modrinth.com/data/uXXizFIs/versions/CtMpt7Jr/ferritecore-8.0.0-fabric.jar"; sha512 = "131b82d1d366f0966435bfcb38c362d604d68ecf30c106d31a6261bfc868ca3a82425bb3faebaa2e5ea17d8eed5c92843810eb2df4790f2f8b1e6c1bdc9b7745"; }; + NoChatReports = pkgs.fetchurl { url = "https://cdn.modrinth.com/data/qQyHxfxd/versions/CHlHxkvf/NoChatReports-FABRIC-1.21.5-v2.12.0.jar"; sha512 = "c0825db25672cf8b50face51ec8a6bedb4be50b374a2537640a433c98817bc07c177485e93ab8cee9e3f7bfb1d2eb1460309e818b411764c92426b552487a9f7"; }; + FabricProxyLite = pkgs.fetchurl { url = "https://cdn.modrinth.com/data/8dI2tmqs/versions/AQhF7kvw/FabricProxy-Lite-2.9.0.jar"; sha512 = "3044f36df7e83021210a7c318def18a95b5dbf5e3230bb72a3ddb42ebdda33f248c6d12efcee1240ff0c54600d68d147afa105d04ee37a90acb9409619c89848"; }; + }); + }; + }; + + services.minecraft-servers.servers.velocity.symlinks."velocity.toml".value = { + servers = { + fabric-modless = "127.0.0.1:30001"; + + # In what order we should try servers when a player logs in or is kicked from a server. + try = [ + "fabric-modless" + ]; + }; + }; +} diff --git a/modules/games/server/minecraft/velocity.nix b/modules/games/server/minecraft/velocity.nix new file mode 100644 index 0000000..29a2494 --- /dev/null +++ b/modules/games/server/minecraft/velocity.nix @@ -0,0 +1,89 @@ +{ config, pkgs, ... }: + +{ + services.minecraft-servers.servers.velocity = { + enable = true; + package = pkgs.velocityServers.velocity; + autoStart = true; + openFirewall = true; + jvmOpts = "-Xms256M -Xmx1024M"; + symlinks = { + "plugins/Luckperms.jar" = pkgs.fetchurl { url = "https://download.luckperms.net/1575/velocity/LuckPerms-Velocity-5.4.158.jar"; sha512 = "07b649db2d2c9f16791d706621dcb606d05bbc1125fa65765e7d4cf4b45778a84f65ca4ad8e461ff146646805072852322cfbd91d66699af5e895d00b233648f"; }; + "plugins/Velocitab.jar" = pkgs.fetchurl { url = "https://hangarcdn.papermc.io/plugins/William278/Velocitab/versions/1.7.5/VELOCITY/Velocitab-1.7.5.jar"; sha512 = "ExyxRVbkzgVRTOZC9yRrwJbNpRnD1aFZa/QlMmBHAjLMXYmM/Q7lRMGtQs3dyrjBI06Z9e01ZaOmTTa2RbtNew=="; }; + + "plugins/Message.jar" = pkgs.fetchurl { url = "https://hangarcdn.papermc.io/plugins/OskarsMC-Plugins/message/versions/1.4.0/VELOCITY/message-1.4.0-all.jar"; sha512 = "62503339714d7d26d71a98b2036cd04e91c9049567a033441d904a5f3190177bdc41dcd5183e6c51eb083a143edbfaf50642d44c99c1b83e7a3546a3654305c8"; }; + "plugins/Send.jar" = pkgs.fetchurl { url = "https://github.com/OskarsMC-Plugins/send/releases/download/3.0.0/send-3.0.0.jar"; sha512 = "aff03bb13804cd01ecd649d283bfdb0b3411cb4df045670328a43f53a05f7386a76a536c4fcbbd3cdc718aa300f2ab2940c7437a181e31fa9f1c9c0e591896ab"; }; + "plugins/Broadcast.jar" = pkgs.fetchurl { url = "https://github.com/OskarsMC-Plugins/broadcast/releases/download/1.0.0/broadcast-1.0.0.jar"; sha512 = "80911709bb8889a3a338d8430b6305d7a3530ff63640a59edf196344f53aca6a1830a57b38a54e01a31f09758e8d89f6fce65af87f63cd6c3d83a5e5d028f544"; }; + }; + + symlinks."velocity.toml".value = { + # Config version. Do not change this + config-version = "2.7"; + + bind = "0.0.0.0:25565"; + motd = "<#09add3>A Velocity Server"; + show-max-players = 500; # displayed maximum players, not an actual cap + online-mode = true; + force-key-authentication = true; + player-info-forwarding-mode = "modern"; + forwarding-secret-file = "forwarding.secret"; + announce-forge = false; # lets clients know server supports forge mods + kick-existing-players = false; # kick when multiple connections are made from the same account + ping-passthrough = "DISABLED"; + + forced-hosts = { + }; + }; + + files."plugins/velocitab/tab_groups.yml".value = { + groups = [ + { + name = "default"; + headers = [ "" ]; + footers = [ "connected to %server%" ]; + format = "%prefix%%username% %server%"; + nametag.prefix = "%prefix%"; + nametag.suffix = ""; + sorting_placeholders = [ + "%role_weight%" + "%username_lower%" + ]; + only_list_players_in_same_server = false; + } + ]; + }; + + files."plugins/message/config.toml".value = { + plugin = { + enabled = true; + luckperms-integration = true; # If luckperms is found, use luckperms prefixes and suffixes. + miniplaceholders-integration = true; # If miniplaceholders is present, you can use the MiniPlaceholders placeholders in the messages. + allow-self-message-sending = true; # Allow a player to send messages to themselves. + }; + + messages = { + message-sent = " "; + message-received = " "; + message-socialspy = "✉ spy "; + }; + + aliases = { + message = ["msg" "tell"]; + reply = ["r"]; + }; + + error-handlers = { }; + developer-info.config-version = 1.2; + }; + files."plugins/send/config.toml".value = { + plugin.enabled = true; + servers.server-blacklist = false; + developer-info.config-version = 0.2; + + messages = { + send-success-plural="Sent players to ."; + send-success-singular="Sent to ."; + }; + }; + }; +}