{ 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 ]; }) ]; }