feat(nixos): run Valheim in a guest

This commit is contained in:
2026-09-10 09:18:45 -04:00
parent 5758a781d8
commit eea7dbef40
2 changed files with 120 additions and 11 deletions

View File

@@ -0,0 +1,104 @@
{
config,
lib,
...
}:
let
cfg = config.guests.valheim;
steamDir = "/data/steamcmd";
installDir = "/data/server";
stateDir = "/data/state";
in
{
options.guests.valheim = {
steamPath = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "/srv/steamcmd";
description = "Host path bind-mounted as SteamCMD's metadata directory.";
};
installPath = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "/srv/valheim/server";
description = "Host path bind-mounted as Valheim's server install directory.";
};
statePath = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "/srv/valheim/state";
description = "Host path bind-mounted as Valheim's world state directory.";
};
serverName = lib.mkOption {
type = lib.types.str;
default = "valheim";
description = "Name shown for the Valheim server.";
};
port = lib.mkOption {
type = lib.types.port;
default = 2456;
description = "Base UDP port for the Valheim server.";
};
password = lib.mkOption {
type = lib.types.str;
description = "Valheim server password.";
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.steamPath != null;
message = "guests.valheim.steamPath must point at the host directory that stores SteamCMD metadata.";
}
{
assertion = cfg.installPath != null;
message = "guests.valheim.installPath must point at the host directory that stores Valheim server files.";
}
{
assertion = cfg.statePath != null;
message = "guests.valheim.statePath must point at the host directory that stores Valheim world state.";
}
];
guests.valheim = {
interior.modules.services.games.valheim = {
enable = true;
inherit (cfg) serverName port password;
inherit steamDir installDir stateDir;
};
mounts = {
${steamDir} = {
directory = cfg.steamPath;
owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd;
group = "storage";
mode = "0770";
};
${installDir} = {
directory = cfg.installPath;
owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd;
group = "storage";
mode = "0770";
};
${stateDir} = {
directory = cfg.statePath;
owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd;
group = "storage";
mode = "0770";
};
};
limits = {
memory = lib.mkDefault "4G";
cpu = lib.mkDefault "400%";
tasksMax = lib.mkDefault 1024;
};
};
};
}

View File

@@ -65,21 +65,26 @@
}; };
registry.address.pikachu.self = "10.23.10.102"; registry.address.pikachu.self = "10.23.10.102";
registry.route.pikachu.self = {
domain = "valheim.alexion.dev";
udp.ports = [
config.modules.services.games.valheim.port
(config.modules.services.games.valheim.port + 1)
];
};
modules.services.games.valheim = { guests.valheim = {
enable = true; enable = true;
steamDir = "/pikachu/data/steamcmd"; vlan = 20;
installDir = "/pikachu/data/servers/valheim/main"; address = "10.23.20.197";
stateDir = "/pikachu/media/games/servers/valheim/main"; steamPath = "/pikachu/data/steamcmd";
installPath = "/pikachu/data/servers/valheim/main";
statePath = "/pikachu/media/games/servers/valheim/main";
serverName = "main"; serverName = "main";
password = "foobarbaz"; password = "foobarbaz";
reverseProxy = {
enable = true;
route = {
domain = "valheim.alexion.dev";
udp.ports = [
config.guests.valheim.port
(config.guests.valheim.port + 1)
];
};
};
}; };
guests.actualbudget = { guests.actualbudget = {