setup factorio server

This commit is contained in:
Christoph Hollizeck 2024-04-20 12:17:20 +02:00
parent d7b0c7cdee
commit 50677dc441
Signed by: Daholli
GPG key ID: 249300664F2AF2C7
4 changed files with 47 additions and 40 deletions

View file

@ -0,0 +1,36 @@
{
lib,
config,
pkgs,
...
}:
with lib;
with lib.wyrdgard;
let
cfg = config.wyrdgard.apps.factorio-server;
inherit (config.wyrdgard.user) name;
in
{
options.wyrdgard.apps.factorio-server = with types; {
enable = mkEnableOption "Enable Factorio Headless Server";
};
config = mkIf cfg.enable {
environment.systemPackages = with pkgs; [ factorio-headless-experimental ];
services.factorio = {
enable = true;
openFirewall = true;
public = true;
lan = true;
bind = "[::]";
nonBlockingSaving = true;
autosave-interval = 5;
loadLatestSave = true;
username = "DaHolli";
token = "4d4624ca9a23396e1955c1b4b364ff";
game-name = "Alles Nix!";
game-password = "1234";
};
};
}

View file

@ -10,37 +10,14 @@ with lib;
with lib.wyrdgard;
let
cfg = config.wyrdgard.nix;
substituters-submodule = types.submodule (
{ name, ... }:
{
options = with types; {
key = mkOpt (nullOr str) null "The trusted public key for this substituter.";
};
}
);
in
{
options.wyrdgard.nix = with types; {
enable = mkBoolOpt true "Whether or not to manage nix configuration.";
package = mkOpt package pkgs.nixUnstable "Which nix package to use.";
default-substituter = {
url = mkOpt str "https://cache.nixos.org" "The url for the substituter.";
key =
mkOpt str "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"The trusted public key for the substituter.";
};
extra-substituters = mkOpt (attrsOf substituters-submodule) { } "Extra substituters to configure.";
};
config = mkIf cfg.enable {
assertions = mapAttrsToList (name: value: {
assertion = value.key != null;
message = "wyrdgard.nix.extra-substituters.${name}.key must be set";
}) cfg.extra-substituters;
environment.systemPackages = with pkgs; [
snowfallorg.flake
nixfmt
@ -53,7 +30,7 @@ in
users = [
"root"
config.wyrdgard.user.name
] ++ optional config.services.hydra.enable "hydra";
];
in
{
package = cfg.package;
@ -68,13 +45,6 @@ in
auto-optimise-store = true;
trusted-users = users;
allowed-users = users;
substituters = [
cfg.default-substituter.url
] ++ (mapAttrsToList (name: value: name) cfg.extra-substituters);
trusted-public-keys = [
cfg.default-substituter.key
] ++ (mapAttrsToList (name: value: value.key) cfg.extra-substituters);
}
// (lib.optionalAttrs config.wyrdgard.tools.direnv.enable {
keep-outputs = true;