factorio server
This commit is contained in:
parent
00b7254d12
commit
47a4f3f9a7
10 changed files with 174 additions and 52 deletions
104
fili/services/factorio.nix
Normal file
104
fili/services/factorio.nix
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
{lib, pkgs, config, ...}: let
|
||||
factorioVersion = version: sha: pkgs.factorio-headless.overrideAttrs (_: {
|
||||
inherit version;
|
||||
src = pkgs.fetchurl {
|
||||
url = "https://factorio.com/get-download/${version}/headless/linux64";
|
||||
name = "factorio-headless-${version}.tar.xz";
|
||||
sha256 = sha;
|
||||
};
|
||||
});
|
||||
getMods = modDir: let
|
||||
modList = lib.pipe modDir [
|
||||
builtins.readDir
|
||||
(lib.filterAttrs (k: v: v == "regular"))
|
||||
(lib.mapAttrsToList (k: v: 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 = []; };
|
||||
in
|
||||
builtins.map modToDrv modList;
|
||||
factorioContainer = name: factorio-config: {
|
||||
"factorio-${name}" = {
|
||||
autoStart = true;
|
||||
bindMounts = {
|
||||
"/var/lib/factorio" = {
|
||||
hostPath = "/factorio/${name}";
|
||||
isReadOnly = false;
|
||||
};
|
||||
"/run/secrets" = {
|
||||
hostPath = "/run/secrets";
|
||||
isReadOnly = true;
|
||||
};
|
||||
"/etc/resolv.conf" = {
|
||||
hostPath = "/etc/resolv.conf";
|
||||
isReadOnly = true;
|
||||
};
|
||||
};
|
||||
privateUsers = "no";
|
||||
|
||||
config = { config, pkgs, lib, ... }: {
|
||||
systemd.services.factorio.serviceConfig.User = "factorio";
|
||||
services.factorio = factorio-config // {
|
||||
enable = true;
|
||||
openFirewall = true;
|
||||
|
||||
game-name = name;
|
||||
saveName = name;
|
||||
stateDirName = "factorio";
|
||||
};
|
||||
|
||||
nixpkgs.config = {
|
||||
allowUnfree = true;
|
||||
};
|
||||
|
||||
system.stateVersion = "23.11";
|
||||
|
||||
networking = {
|
||||
firewall.enable = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
users.groups.factorio = { };
|
||||
users.users.factorio = {
|
||||
isSystemUser = true;
|
||||
group = "factorio";
|
||||
extraGroups = [ "storage" ];
|
||||
};
|
||||
|
||||
sops.secrets.factorio = {
|
||||
sopsFile = ../../secrets/factorio.json;
|
||||
format = "json";
|
||||
key = "";
|
||||
owner = "factorio";
|
||||
};
|
||||
|
||||
containers = factorioContainer "tawney" {
|
||||
autosave-interval = 20;
|
||||
admins = [ "jonay2000" "computerdruid" "pineapple" ];
|
||||
extraSettingsFile = config.sops.secrets.factorio.path;
|
||||
# mods = getMods ../../factorio-mods/tawney;
|
||||
package = factorioVersion "2.0.66" "sha256-8bOXbqzE4jOADTmdkABsNW+jZvXWQ0HFBMlcDLoyHAY=";
|
||||
port = 20001;
|
||||
}
|
||||
// factorioContainer "snek" {
|
||||
autosave-interval = 20;
|
||||
admins = [ "jonay2000" "computerdruid" "pineapple" ];
|
||||
extraSettingsFile = config.sops.secrets.factorio.path;
|
||||
mods = getMods ../../factorio-mods/snek;
|
||||
package = factorioVersion "2.0.66" "sha256-8bOXbqzE4jOADTmdkABsNW+jZvXWQ0HFBMlcDLoyHAY=";
|
||||
port = 20002;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue