From 2d6fecf8f6b04e81a2663c323aa6fc7adca119f5 Mon Sep 17 00:00:00 2001 From: Christoph Hollizeck Date: Sat, 20 Apr 2024 12:17:20 +0200 Subject: [PATCH] setup factorio server --- flake.lock | 18 +++++----- .../nixos/apps/factorio-server/default.nix | 36 +++++++++++++++++++ modules/nixos/nix/default.nix | 32 +---------------- systems/x86_64-linux/yggdrasil/default.nix | 1 + 4 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 modules/nixos/apps/factorio-server/default.nix diff --git a/flake.lock b/flake.lock index 55b3777..df7ffb4 100644 --- a/flake.lock +++ b/flake.lock @@ -382,11 +382,11 @@ ] }, "locked": { - "lastModified": 1713077896, - "narHash": "sha256-Noot8H0EZEAFRQWyGxh9ryvhK96xpIqKbh78X447JWs=", + "lastModified": 1713166971, + "narHash": "sha256-t0P/rKlsE5l1O3O2LYtAelLzp7PeoPCSzsIietQ1hSM=", "owner": "nix-community", "repo": "home-manager", - "rev": "630a0992b3627c64e34f179fab68e3d48c6991c0", + "rev": "1c43dcfac48a2d622797f7ab741670fdbcf8f609", "type": "github" }, "original": { @@ -477,11 +477,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1712791164, - "narHash": "sha256-3sbWO1mbpWsLepZGbWaMovSO7ndZeFqDSdX0hZ9nVyw=", + "lastModified": 1713297878, + "narHash": "sha256-hOkzkhLT59wR8VaMbh1ESjtZLbGi+XNaBN6h49SPqEc=", "owner": "nixos", "repo": "nixpkgs", - "rev": "1042fd8b148a9105f3c0aca3a6177fd1d9360ba5", + "rev": "66adc1e47f8784803f2deb6cacd5e07264ec2d5c", "type": "github" }, "original": { @@ -809,11 +809,11 @@ }, "unstable_2": { "locked": { - "lastModified": 1712791164, - "narHash": "sha256-3sbWO1mbpWsLepZGbWaMovSO7ndZeFqDSdX0hZ9nVyw=", + "lastModified": 1712963716, + "narHash": "sha256-WKm9CvgCldeIVvRz87iOMi8CFVB1apJlkUT4GGvA0iM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "1042fd8b148a9105f3c0aca3a6177fd1d9360ba5", + "rev": "cfd6b5fc90b15709b780a5a1619695a88505a176", "type": "github" }, "original": { diff --git a/modules/nixos/apps/factorio-server/default.nix b/modules/nixos/apps/factorio-server/default.nix new file mode 100644 index 0000000..9d19c0f --- /dev/null +++ b/modules/nixos/apps/factorio-server/default.nix @@ -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"; + }; + }; +} diff --git a/modules/nixos/nix/default.nix b/modules/nixos/nix/default.nix index 3f1747f..5b96016 100644 --- a/modules/nixos/nix/default.nix +++ b/modules/nixos/nix/default.nix @@ -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; diff --git a/systems/x86_64-linux/yggdrasil/default.nix b/systems/x86_64-linux/yggdrasil/default.nix index f56262e..94d9072 100644 --- a/systems/x86_64-linux/yggdrasil/default.nix +++ b/systems/x86_64-linux/yggdrasil/default.nix @@ -23,6 +23,7 @@ with lib.wyrdgard; discord = enabled; _1password = enabled; onedrive = enabled; + factorio-server = enabled; }; system = {