factorio server
This commit is contained in:
parent
00b7254d12
commit
47a4f3f9a7
10 changed files with 174 additions and 52 deletions
|
|
@ -6,6 +6,8 @@ _: {
|
|||
./forgejo.nix
|
||||
./obsidian-sync.nix
|
||||
|
||||
./factorio.nix
|
||||
|
||||
./media
|
||||
./websites
|
||||
./auth
|
||||
|
|
|
|||
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;
|
||||
};
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
{ flakes, ... }:
|
||||
{ config
|
||||
, flakes
|
||||
, pkgs
|
||||
, ...
|
||||
}:
|
||||
{
|
||||
# imports = [
|
||||
# flakes.mapf.nixosModules.default
|
||||
# ];
|
||||
|
||||
sops.secrets.mapf = {
|
||||
sopsFile = ../../../secrets/mapf-prod.env;
|
||||
};
|
||||
|
|
@ -20,11 +20,30 @@
|
|||
};
|
||||
};
|
||||
|
||||
# donsz.services.mapf = {
|
||||
# enable = true;
|
||||
# envfile = "/run/secrets/sops/mapf";
|
||||
# db_name = "mapfprod";
|
||||
# db_user = "mapfprod";
|
||||
# db_password = "";
|
||||
# };
|
||||
systemd.services.mapf-server =
|
||||
let
|
||||
package = flakes.mapf.packages.${pkgs.system}.default;
|
||||
in
|
||||
{
|
||||
description = "mapf-server";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
DynamicUser = "yes";
|
||||
ExecStart = "${package}/mapf_server_bin";
|
||||
Restart = "on-failure";
|
||||
RestartSec = "5s";
|
||||
EnvironmentFile = config.sops.secrets.mapf.path;
|
||||
WorkingDirectory = "${package}";
|
||||
};
|
||||
|
||||
environment = {
|
||||
MAPF_TEMPLATEFOLDER = "${package}/templates";
|
||||
MAPF_DBUSER = "mapfprod";
|
||||
MAPF_DBPASSWORD = "";
|
||||
MAPF_DBPORT = "3306";
|
||||
MAPF_DBHOST = "localhost";
|
||||
MAPF_DBDATABASE = "mapfprod";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue