From 09179b603f49fed432297b63e3c10aeccbcf64ae Mon Sep 17 00:00:00 2001 From: Oliver Matthews Date: Tue, 7 Apr 2015 12:05:03 +0000 Subject: [PATCH] allow changing minecraft data dir + allow opening firewall --- .../services/games/minecraft-server.nix | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/games/minecraft-server.nix b/nixos/modules/services/games/minecraft-server.nix index 4c734aefa469..d2c8af6de0c5 100644 --- a/nixos/modules/services/games/minecraft-server.nix +++ b/nixos/modules/services/games/minecraft-server.nix @@ -8,6 +8,7 @@ in { options = { services.minecraft-server = { + enable = mkOption { type = types.bool; default = false; @@ -15,7 +16,23 @@ in If enabled, start a Minecraft Server. The listening port for the server is always 25565. The server data will be loaded from and saved to - /var/lib/minecraft. + ${cfg.dataDir}. + ''; + }; + + dataDir = mkOption { + type = types.path; + default = "/var/lib/minecraft"; + description = '' + Directory to store minecraft database and other state/data files. + ''; + }; + + openFirewall = mkOption { + type = types.bool; + default = false; + description = '' + Whether to open ports in the firewall (if enabled) for the server. ''; }; @@ -30,7 +47,7 @@ in config = mkIf cfg.enable { users.extraUsers.minecraft = { description = "Minecraft Server Service user"; - home = "/var/lib/minecraft"; + home = cfg.dataDir; createHome = true; uid = config.ids.uids.minecraft; }; @@ -43,9 +60,14 @@ in serviceConfig.Restart = "always"; serviceConfig.User = "minecraft"; script = '' - cd /var/lib/minecraft + cd ${cfg.dataDir} exec ${pkgs.minecraft-server}/bin/minecraft-server ${cfg.jvmOpts} ''; }; + + networking.firewall = mkIf cfg.openFirewall { + allowedUDPPorts = [ 25565 ]; + allowedTCPPorts = [ 25565 ]; + }; }; }