/
factorio.nix
52 lines (50 loc) · 1.72 KB
/
factorio.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{ config, pkgs, ... }:
{
services.factorio = {
enable = true;
admins = [ "nicball" ];
description = "Nicball's Factorio Server";
game-name = "MidyMidyFactorio";
game-password = pkgs.lib.removeSuffix "\n" (builtins.readFile ./private/factorio-password);
saveName = "server";
lan = true;
openFirewall = true;
autosave-interval = 60;
requireUserVerification = false;
extraSettings = { auto_pause = false; };
mods =
let
inherit (pkgs) lib;
modDir = ./factorio-mods;
modList = lib.pipe modDir [
builtins.readDir
(lib.filterAttrs (k: v: v == "regular"))
(lib.mapAttrsToList (k: v: k))
(builtins.filter (lib.hasSuffix ".zip"))
];
modToDrv = modFileName:
pkgs.runCommand "copy-factorio-mods" {} ''
mkdir $out
cp ${modDir + "/${modFileName}"} $out/${modFileName}
''
// { deps = []; };
in
builtins.map modToDrv modList;
package = pkgs.factorio-headless.overrideAttrs (self: super: {
installPhase = super.installPhase + ''
wrapProgram $out/bin/factorio --add-flags "--rcon-bind localhost:9790 --rcon-password 233"
'';
nativeBuildInputs = (super.nativeBuildInputs or []) ++ [ pkgs.makeWrapper ];
});
};
systemd.services.factorio-bot = {
description = "Factorio Telegram Bridge";
wantedBy = [ "factorio.service" ];
after = [ "factorio.service" ];
partOf = [ "factorio.service" ];
serviceConfig = {
Restart = "always";
ExecStart = "${pkgs.jre}/bin/java -Dhttp.proxyHost=localhost -Dhttp.proxyPort=7890 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=7890 -jar " + ./private/factorio-bot.jar;
};
};
}