nixos-config/machines/factorio/factorio.nix

63 lines
1.7 KiB
Nix
Raw Normal View History

2024-11-14 13:13:24 +01:00
{ pkgs, lib, ... }:
let
modDir = ./mods;
modList = lib.pipe modDir [
builtins.readDir
(lib.filterAttrs (_: v: v == "regular"))
(lib.mapAttrsToList (k: _: k))
(builtins.filter (lib.hasSuffix ".zip"))
];
validPath =
modFileName:
builtins.path {
path = "${modDir}/${modFileName}";
name = lib.strings.sanitizeDerivationName modFileName;
};
modToDrv =
modFileName:
pkgs.runCommand "copy-factorio-mods" { } ''
mkdir $out
ln -s '${validPath modFileName}' $out/'${modFileName}'
''
// {
deps = [ ];
};
disableSpaceAge = pkgs.writeShellScript "disable-space-age" ''
space_age_mods=("elevated-rails" "quality" "space-age")
for mod in "''${space_age_mods[@]}"; do
${lib.getExe pkgs.jaq} --arg mod_name "''${mod}" 'if .mods | map(.name) | index($mod_name) then .mods |= map(if .name == $mod_name and .enabled == true then .enabled = false else . end) else .mods += [{"name": $mod_name, "enabled": false}] end' /var/lib/factorio/mod-list.json > /var/lib/factorio/mod-list.json.tmp
mv /var/lib/factorio/mod-list.json.tmp /var/lib/factorio/mod-list.json
done
'';
2024-11-14 13:13:24 +01:00
in
{
services = {
factorio = {
enable = true;
game-name = "stats-export-test";
saveName = "stats-export-test";
mods = builtins.map modToDrv modList;
mods-dat = ./mods/mod-settings.dat;
2024-11-14 13:13:24 +01:00
lan = true;
admins = [ "eboskma" ];
nonBlockingSaving = true;
requireUserVerification = false;
2024-11-14 13:13:24 +01:00
};
};
systemd = {
services = {
factorio.serviceConfig = {
User = "factorio";
ExecStartPre = [
disableSpaceAge
];
};
};
};
2024-11-14 13:13:24 +01:00
}