2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-03-29 10:48:33 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2014-03-29 10:48:33 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.minecraft-server;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.minecraft-server = {
|
2015-04-07 14:05:03 +02:00
|
|
|
|
2014-03-29 10:48:33 +01:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If enabled, start a Minecraft Server. The listening port for
|
|
|
|
the server is always <literal>25565</literal>. The server
|
|
|
|
data will be loaded from and saved to
|
2015-04-07 14:05:03 +02:00
|
|
|
<literal>${cfg.dataDir}</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
2014-03-29 10:48:33 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
jvmOpts = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "-Xmx2048M -Xms2048M";
|
|
|
|
description = "JVM options for the Minecraft Service.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users.minecraft = {
|
2014-03-29 10:48:33 +01:00
|
|
|
description = "Minecraft Server Service user";
|
2015-04-07 14:05:03 +02:00
|
|
|
home = cfg.dataDir;
|
2014-03-29 10:48:33 +01:00
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.minecraft;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.minecraft-server = {
|
|
|
|
description = "Minecraft Server Service";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
|
|
|
serviceConfig.Restart = "always";
|
|
|
|
serviceConfig.User = "minecraft";
|
|
|
|
script = ''
|
2015-04-07 14:05:03 +02:00
|
|
|
cd ${cfg.dataDir}
|
2014-03-29 10:48:33 +01:00
|
|
|
exec ${pkgs.minecraft-server}/bin/minecraft-server ${cfg.jvmOpts}
|
|
|
|
'';
|
|
|
|
};
|
2015-04-07 14:05:03 +02:00
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedUDPPorts = [ 25565 ];
|
|
|
|
allowedTCPPorts = [ 25565 ];
|
|
|
|
};
|
2014-03-29 10:48:33 +01:00
|
|
|
};
|
|
|
|
}
|