Compare commits
2 Commits
7a23f36b7d
...
097ea51d2d
Author | SHA1 | Date | |
---|---|---|---|
097ea51d2d | |||
765eaf332d |
@ -28,16 +28,11 @@ in {
|
||||
networking.defaultGateway6 = { address = "2001:638:904:ffcb::1"; interface = "ens18"; };
|
||||
networking.nameservers = [ "2001:638:904:ffcc::3" "2001:638:904:ffcc::4" "141.24.40.3" "141.24.40.4" ];
|
||||
|
||||
services.minecraft-server = {
|
||||
enable = true;
|
||||
eula = true;
|
||||
dataDir = "/var/lib/minecraft-server";
|
||||
package = pkgs.papermc;
|
||||
jvmOpts = "-Xmx4G -Xms1G";
|
||||
};
|
||||
clerie.minecraft-server.servers.aerilon.enable = true; # port 25565
|
||||
clerie.minecraft-server.servers.riese.enable = true; # port 25566
|
||||
clerie.minecraft-server.servers.chaos.enable = true; # port 25568
|
||||
|
||||
networking.firewall.allowedUDPPorts = [ 25565 ];
|
||||
networking.firewall.allowedTCPPorts = [ 25565 ];
|
||||
networking.firewall.allowedTCPPorts = [ 25565 25566 25568 ];
|
||||
|
||||
system.stateVersion = "21.03";
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
./anycast_healthchecker
|
||||
./gitea
|
||||
./gre-tunnel
|
||||
./minecraft-server
|
||||
./nginx-port-forward
|
||||
];
|
||||
}
|
||||
|
84
modules/minecraft-server/default.nix
Normal file
84
modules/minecraft-server/default.nix
Normal file
@ -0,0 +1,84 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.clerie.minecraft-server;
|
||||
|
||||
# We don't allow eula=false anyways
|
||||
eulaFile = builtins.toFile "eula.txt" ''
|
||||
# eula.txt managed by NixOS Configuration
|
||||
eula=true
|
||||
'';
|
||||
|
||||
generateServerUnit = name: server: (
|
||||
nameValuePair "minecraft-server-${name}" (mkIf server.enable {
|
||||
|
||||
description = "Minecraft Server ${name}";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = "${server.package}/bin/minecraft-server ${server.jvmOpts}";
|
||||
Restart = "always";
|
||||
WorkingDirectory = if server.dataDir != null then server.dataDir else "/var/lib/minecraft-server-${name}";
|
||||
StateDirectory = "minecraft-server-${name}";
|
||||
DynamicUser = true;
|
||||
};
|
||||
|
||||
preStart = ''
|
||||
ln -sf ${eulaFile} eula.txt
|
||||
'';
|
||||
})
|
||||
);
|
||||
|
||||
serverOpts = { config, ... }@moduleAttrs: {
|
||||
options = {
|
||||
|
||||
enable = mkEnableOption "A shared minecraft hosting service.";
|
||||
|
||||
dataDir = mkOption {
|
||||
type = with types; nullOr path;
|
||||
default = null;
|
||||
description = ''
|
||||
Directory to store Minecraft database and other state/data files.
|
||||
When null defaulting to /var/lib/minecraft-server-${name}
|
||||
'';
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.papermc;
|
||||
defaultText = "pkgs.papermc";
|
||||
example = literalExample "pkgs.minecraft-server_1_12_2";
|
||||
description = "Version of minecraft-server to run.";
|
||||
};
|
||||
|
||||
jvmOpts = mkOption {
|
||||
type = types.separatedString " ";
|
||||
default = "-Xmx2G -Xms1G";
|
||||
# Example options from https://minecraft.gamepedia.com/Tutorials/Server_startup_script
|
||||
example = "-Xmx2048M -Xms4092M -XX:+UseG1GC -XX:+CMSIncrementalPacing "
|
||||
+ "-XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 "
|
||||
+ "-XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10";
|
||||
description = "JVM options for the Minecraft server.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
in {
|
||||
options = {
|
||||
clerie.minecraft-server = {
|
||||
|
||||
servers = mkOption {
|
||||
type = with types; attrsOf (submodule serverOpts);
|
||||
default = {};
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
systemd.services = (mapAttrs' generateServerUnit cfg.servers);
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user