dotfiles/nixos/systems/heater/arma3.nix

183 lines
4.6 KiB
Nix
Raw Normal View History

{
inputs',
pkgs,
lib,
...
}: let
mods = [
{
id = "463939057";
name = "ACE";
}
{
id = "2867537125";
name = "Antistasi";
}
{
id = "450814997";
name = "CBA_A3";
}
{
id = "843425103";
name = "RHSAFRF";
}
{
id = "843593391";
name = "RHSGREF";
}
{
id = "843632231";
name = "RHSSAF";
}
{
id = "843577117";
name = "RHSUSAF";
}
];
inherit
(lib)
getExe
getExe'
concatMapStringsSep
;
in {
networking.nat.internalInterfaces = [
"arma3"
];
networking.nat = {
forwardPorts =
map (port: {
destination = "10.99.99.2:${toString port}";
proto = "udp";
sourcePort = port;
})
[
2302
2303
2304
];
};
ucontainers."arma3" = {
network = [
{
hostAddress = "10.99.99.1/24";
guestAddress = "10.99.99.2/24";
hostInterface = "arma3";
guestInterface = "eth0";
}
];
settings = {
ephemeral = true;
bind = [
"/etc/resolv.conf"
"/var/lib/arma3/steam_library:/home/steam/Steam"
"/var/lib/arma3/steam:/home/steam/.local/share/Steam"
"/var/lib/arma3/game:/var/lib/game"
"/var/lib/arma3/secret:/secret"
"/var/lib/arma3/arma3:/home/steam/.local/share/Arma 3/"
"/var/lib/arma3/arma3_other_profiles:/home/steam/.local/share/Arma 3 - Other Profiles/"
];
};
path =
(inputs'.nixng.nglib.makeSystem {
inherit (pkgs.stdenv) system;
inherit (inputs') nixpkgs;
name = "arma3";
config = {
dumb-init = {
enable = true;
type.services = {};
};
nixpkgs.pkgs = pkgs;
init.services.network = {
enabled = true;
script = pkgs.writeShellScript "network-start" ''
ip addr add "10.99.99.2/24" dev "eth0"
ip link set "eth0" up
ip route add "10.99.99.0/24" dev "eth0"
ip route add default via "10.99.99.1" dev "eth0"
touch /etc/hosts
exec sleep infinity
'';
};
users.users."steam" = {
uid = 1001;
home = "/home/steam";
group = "steam";
};
users.groups."steam" = {
gid = 1001;
};
## Steam doesn't allow me to download the mods as that account doesn't own Arma 3...
# ${concatMapStringsSep "\n" (mod: ''
# HOME=/home/steam USER=steam chpst -U steam:steam -u steam:steam ${getExe' pkgs.steamcmd "steamcmd"} \
# +login "$(cat /secret/user | tr -d '\n ')" "$(cat /secret/password | tr -d '\n ')" \
# +"workshop_download_item 107410 ${mod.id}" validate \
# +quit
# ln -sf /home/steam/Steam/steamapps/workshop/content/107410/${mod.id} /var/lib/game/mods/@${mod.name}
# '')
# mods}
init.services.steam-login = {
enabled = true;
script = pkgs.writeShellScript "steam-login-start" ''
set -e -o pipefail
mkdir -p /home/steam
chown steam:steam -R /home/steam
chown steam:steam -R /var/lib/game
HOME=/home/steam USER=steam chpst -U steam:steam -u steam:steam ${getExe' pkgs.steamcmd "steamcmd"} \
+force_install_dir /var/lib/game \
+login "$(cat /secret/user | tr -d '\n ')" "$(cat /secret/password | tr -d '\n ')" \
+app_update 233780 validate \
+quit
${concatMapStringsSep "\n" (
mod: ''
ln -sf /var/lib/game/mods/${mod.id} /var/lib/game/mods/@${mod.name}
''
)
mods}
sv start arma3
exec sleep infinity
'';
};
init.services.arma3 = {
dependencies = [
"steam-login"
];
enabled = false;
script = pkgs.writeShellScript "arma3-start" ''
cd /var/lib/game
PATH=${pkgs.coreutils}/bin:$PATH LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib:$PWD exec \
chpst -u steam:steam \
${getExe' pkgs.glibc "ld.so"} ./arma3server_x64 \
-config=./server.cfg \
${concatMapStringsSep " \\\n" (
mod: "-mod=./mods/${mod.id}"
)
mods}
'';
};
};
})
.config
.system
.build
.toplevel;
};
}