about summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorArtemis Tosini <me@artem.ist>2020-01-09 15:07:50 +0000
committerArtemis Tosini <me@artem.ist>2020-01-10 23:36:14 +0000
commit637d7a5db9927a78c3b9e57ea3b2b22b27d8caa9 (patch)
tree1681890039e150a080d3f2fdef48906b91ae385b /nixos/modules
parent59c4035e58e0ff224bee2f20c0f6811a71a7806f (diff)
downloadnixlib-637d7a5db9927a78c3b9e57ea3b2b22b27d8caa9.tar
nixlib-637d7a5db9927a78c3b9e57ea3b2b22b27d8caa9.tar.gz
nixlib-637d7a5db9927a78c3b9e57ea3b2b22b27d8caa9.tar.bz2
nixlib-637d7a5db9927a78c3b9e57ea3b2b22b27d8caa9.tar.lz
nixlib-637d7a5db9927a78c3b9e57ea3b2b22b27d8caa9.tar.xz
nixlib-637d7a5db9927a78c3b9e57ea3b2b22b27d8caa9.tar.zst
nixlib-637d7a5db9927a78c3b9e57ea3b2b22b27d8caa9.zip
nixos/factorio: add extraSettings and package options
Currently there is no way to set game settings, such as administrators.
extraSettings allows users to override default game settings without
adding many more settings.

The package option allows users to use the experimental version, or
override to a specific version with their own modified package.
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/services/games/factorio.nix26
1 files changed, 21 insertions, 5 deletions
diff --git a/nixos/modules/services/games/factorio.nix b/nixos/modules/services/games/factorio.nix
index f3831156f453..4b2e1a3c07f0 100644
--- a/nixos/modules/services/games/factorio.nix
+++ b/nixos/modules/services/games/factorio.nix
@@ -4,14 +4,13 @@ with lib;
 
 let
   cfg = config.services.factorio;
-  factorio = pkgs.factorio-headless;
   name = "Factorio";
   stateDir = "/var/lib/${cfg.stateDirName}";
   mkSavePath = name: "${stateDir}/saves/${name}.zip";
   configFile = pkgs.writeText "factorio.conf" ''
     use-system-read-write-data-directories=true
     [path]
-    read-data=${factorio}/share/factorio/data
+    read-data=${cfg.package}/share/factorio/data
     write-data=${stateDir}
   '';
   serverSettings = {
@@ -37,7 +36,7 @@ let
     only_admins_can_pause_the_game = true;
     autosave_only_on_server = true;
     admins = [];
-  };
+  } // cfg.extraSettings;
   serverSettingsFile = pkgs.writeText "server-settings.json" (builtins.toJSON (filterAttrsRecursive (n: v: v != null) serverSettings));
   modDir = pkgs.factorio-utils.mkModDirDrv cfg.mods;
 in
@@ -115,6 +114,14 @@ in
           Description of the game that will appear in the listing.
         '';
       };
+      extraSettings = mkOption {
+        type = types.attrs;
+        default = {};
+        example = { admins = [ "username" ];};
+        description = ''
+          Extra game configuration that will go into server-settings.json
+        '';
+      };
       public = mkOption {
         type = types.bool;
         default = false;
@@ -136,6 +143,15 @@ in
           Your factorio.com login credentials. Required for games with visibility public.
         '';
       };
+      package = mkOption {
+        type = types.package;
+        default = pkgs.factorio-headless;
+        defaultText = "pkgs.factorio-headless";
+        example = "pkgs.factorio-headless-experimental";
+        description = ''
+          Factorio version to use. This defaults to the stable channel.
+        '';
+      };
       password = mkOption {
         type = types.nullOr types.str;
         default = null;
@@ -184,7 +200,7 @@ in
       preStart = toString [
         "test -e ${stateDir}/saves/${cfg.saveName}.zip"
         "||"
-        "${factorio}/bin/factorio"
+        "${cfg.package}/bin/factorio"
           "--config=${cfg.configFile}"
           "--create=${mkSavePath cfg.saveName}"
           (optionalString (cfg.mods != []) "--mod-directory=${modDir}")
@@ -197,7 +213,7 @@ in
         StateDirectory = cfg.stateDirName;
         UMask = "0007";
         ExecStart = toString [
-          "${factorio}/bin/factorio"
+          "${cfg.package}/bin/factorio"
           "--config=${cfg.configFile}"
           "--port=${toString cfg.port}"
           "--start-server=${mkSavePath cfg.saveName}"