feat: added another minecraft world

This commit is contained in:
Nick 2025-11-26 21:40:17 -06:00
parent d92743dad4
commit a4e4f75265
5 changed files with 228 additions and 3 deletions

View file

@ -0,0 +1,38 @@
{ moduleFunctions }:
let
inherit (moduleFunctions.instancesFunctions)
varPath
mntPath
secretPath
;
label = "Minecraft";
name = "minecraft";
short = "mine";
secrets = "${secretPath}/${name}";
in
{
label = label;
name = name;
short = short;
ports = {
port0 = 43001;
};
interface = {
id = "vm-${short}";
mac = "02:00:00:00:51:42";
idUser = "vmuser-${short}";
macUser = "02:00:00:00:00:42";
ip = "192.168.50.142";
gate = "192.168.50.1";
ssh = 2402;
};
varPaths = {
path0 = "${varPath}/${name}";
};
mntPaths = {
path0 = "${mntPath}/${name}";
};
secretPaths = {
path0 = secrets;
};
}

View file

@ -5,7 +5,7 @@
let
inherit (flake.config.people) user0;
inherit (flake.config.services) instances;
serviceCfg = instances.minecraft;
serviceCfg = instances.minecraft0;
hostCfg = instances.web;
world = "world0";
in

View file

@ -0,0 +1,186 @@
{
flake,
...
}:
let
inherit (flake.config.people) user0;
inherit (flake.config.services) instances;
serviceCfg = instances.minecraft1;
hostCfg = instances.web;
world = "world1";
in
{
microvm.vms = {
"${serviceCfg.name}-${world}" = {
autostart = true;
restartIfChanged = true;
config = {
system.stateVersion = "24.05";
time.timeZone = "America/Winnipeg";
users.users.root.openssh.authorizedKeys.keys = flake.config.people.users.${user0}.sshKeys;
services = {
minecraft-server = {
enable = true;
eula = true;
openFirewall = true;
declarative = true;
serverProperties = {
"rcon.password" = "/etc/${serviceCfg.name}-secrets/${world}";
allow-flight = false;
allow-nether = true;
difficulty = 2;
enable-command-block = false;
enable-rcon = true;
enable-status = true;
force-gamemode = true;
gamemode = 0;
generate-structures = true;
hardcore = false;
hide-online-players = false;
level-name = "CuddleCubes";
level-seed = "-2332803749585407299";
max-players = 2;
max-world-size = 64000000;
motd = "A cool Minecraft server powered by NixOS";
online-mode = true;
pvp = true;
server-ip = hostCfg.localhost.address1;
server-port = serviceCfg.ports.port0;
spawn-animals = true;
spawn-monsters = true;
spawn-npcs = true;
spawn-protection = 16;
view-distance = 32;
white-list = true;
};
whitelist = {
Hefty_Chungus = "b75a9816-d408-4c54-b226-385b59ea1cb3";
Fallaryn = "d8baa117-ab58-4b07-92a5-48fb1978eb49";
};
};
openssh = {
enable = true;
settings = {
PasswordAuthentication = false;
PermitRootLogin = "prohibit-password";
};
};
};
networking.firewall.allowedTCPPorts = [
22 # SSH
serviceCfg.ports.port0
];
systemd = {
services = {
"${serviceCfg.name}-copy-secrets" = {
description = "Copy secrets from virtiofs to local filesystem";
before = [ "minecraft-server.service" ];
requiredBy = [ "minecraft-server.service" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = ''
mkdir -p /etc/${serviceCfg.name}-secrets
cp /run/secrets/${world} /etc/${serviceCfg.name}-secrets/${world}
chmod 755 /etc/${serviceCfg.name}-secrets
chmod 644 /etc/${serviceCfg.name}-secrets/*
'';
};
};
network = {
enable = true;
networks."20-lan" = {
matchConfig.Name = "enp0s5";
addresses = [
{ Address = "${serviceCfg.interface.ip}/24"; }
];
routes = [
{
Destination = "${hostCfg.localhost.address1}/0";
Gateway = serviceCfg.interface.gate;
}
];
dns = [
"1.1.1.1"
"8.8.8.8"
];
};
};
tmpfiles.rules = [
"Z ${serviceCfg.varPaths.path0} 0755 ${serviceCfg.name} ${serviceCfg.name} -"
];
};
systemd.services.systemd-networkd.wantedBy = [ "multi-user.target" ];
microvm = {
vcpu = 2;
mem = 1024 * 3;
hypervisor = "qemu";
interfaces = [
{
type = "tap";
id = serviceCfg.interface.id;
mac = serviceCfg.interface.mac;
}
{
type = "user";
id = serviceCfg.interface.idUser;
mac = serviceCfg.interface.macUser;
}
];
forwardPorts = [
{
from = "host";
host.port = serviceCfg.interface.ssh;
guest.port = 22;
}
];
shares = [
{
mountPoint = "/nix/.ro-store";
proto = "virtiofs";
source = "/nix/store";
tag = "read_only_nix_store";
}
{
mountPoint = "/var/lib/${serviceCfg.name}";
proto = "virtiofs";
source = serviceCfg.mntPaths.path0;
tag = "${serviceCfg.name}_data";
}
{
mountPoint = "/run/secrets";
proto = "virtiofs";
source = "/run/secrets/${serviceCfg.name}";
tag = "host_secrets";
}
];
};
};
};
};
systemd = {
tmpfiles.rules = [
"d ${serviceCfg.mntPaths.path0} 0751 microvm wheel - -"
];
};
sops.secrets = {
"${serviceCfg.name}/${world}" = {
owner = "root";
mode = "0600";
};
};
networking.firewall.allowedTCPPorts = [ serviceCfg.ports.port0 ];
}