{ 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 ''; 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; lan = true; admins = [ "eboskma" ]; nonBlockingSaving = true; requireUserVerification = false; }; }; systemd = { services = { factorio.serviceConfig = { User = "factorio"; ExecStartPre = [ disableSpaceAge ]; }; }; }; }