summary refs log tree commit diff
path: root/nixos/modules/services/games
diff options
context:
space:
mode:
authorRok Garbas <rok@garbas.si>2016-08-07 04:09:52 +0200
committerGitHub <noreply@github.com>2016-08-07 04:09:52 +0200
commita741978f200a6627bfcb6325e340db09464a1af9 (patch)
treecd35a432c7b3e66d20de9c896fe3cbb0caa25b30 /nixos/modules/services/games
parent17e8dda59713e2758928aae63d182961176a212c (diff)
parentd76aa6e7e4ee48832033495df99fa3584adb8029 (diff)
downloadnixpkgs-a741978f200a6627bfcb6325e340db09464a1af9.tar
nixpkgs-a741978f200a6627bfcb6325e340db09464a1af9.tar.gz
nixpkgs-a741978f200a6627bfcb6325e340db09464a1af9.tar.bz2
nixpkgs-a741978f200a6627bfcb6325e340db09464a1af9.tar.lz
nixpkgs-a741978f200a6627bfcb6325e340db09464a1af9.tar.xz
nixpkgs-a741978f200a6627bfcb6325e340db09464a1af9.tar.zst
nixpkgs-a741978f200a6627bfcb6325e340db09464a1af9.zip
Merge pull request #17479 from elitak/factorio
Factorio: 0.13.8 -> 0.13.13, mod support
Diffstat (limited to 'nixos/modules/services/games')
-rw-r--r--nixos/modules/services/games/factorio.nix48
1 files changed, 38 insertions, 10 deletions
diff --git a/nixos/modules/services/games/factorio.nix b/nixos/modules/services/games/factorio.nix
index 90834c5b260..0369752997a 100644
--- a/nixos/modules/services/games/factorio.nix
+++ b/nixos/modules/services/games/factorio.nix
@@ -4,14 +4,17 @@ with lib;
 
 let
   cfg = config.services.factorio;
+  factorio = pkgs.factorio-headless;
   name = "Factorio";
   stateDir = "/var/lib/factorio";
+  mkSavePath = name: "${stateDir}/saves/${name}.zip";
   configFile = pkgs.writeText "factorio.conf" ''
     use-system-read-write-data-directories=true
     [path]
-    read-data=${pkgs.factorio-headless}/share/factorio/data
+    read-data=${factorio}/share/factorio/data
     write-data=${stateDir}
   '';
+  modDir = pkgs.factorio-mkModDirDrv cfg.mods;
 in
 {
   options = {
@@ -32,7 +35,8 @@ in
         description = ''
           The name of the savegame that will be used by the server.
 
-          When not present in ${stateDir}/saves, it will be generated before starting the service.
+          When not present in ${stateDir}/saves, a new map with default
+          settings will be generated before starting the service.
         '';
       };
       # TODO Add more individual settings as nixos-options?
@@ -51,6 +55,26 @@ in
           customizations.
         '';
       };
+      mods = mkOption {
+        type = types.listOf types.package;
+        default = [];
+        description = ''
+          Mods the server should install and activate.
+
+          The derivations in this list must "build" the mod by simply copying
+          the .zip, named correctly, into the output directory. Eventually,
+          there will be a way to pull in the most up-to-date list of
+          derivations via nixos-channel. Until then, this is for experts only.
+        '';
+      };
+      autosave-interval = mkOption {
+        type = types.nullOr types.int;
+        default = null;
+        example = 2;
+        description = ''
+          The time, in minutes, between autosaves.
+        '';
+      };
     };
   };
 
@@ -74,12 +98,14 @@ in
       wantedBy      = [ "multi-user.target" ];
       after         = [ "network.target" ];
 
-      preStart = ''
-          test -e ${stateDir}/saves/${cfg.saveName}.zip || \
-            ${pkgs.factorio-headless}/bin/factorio         \
-              --config=${cfg.configFile}                   \
-              --create=${stateDir}/saves/${cfg.saveName}.zip
-      '';
+      preStart = toString [
+        "test -e ${stateDir}/saves/${cfg.saveName}.zip"
+        "||"
+        "${factorio}/bin/factorio"
+          "--config=${cfg.configFile}"
+          "--create=${mkSavePath cfg.saveName}"
+          (optionalString (cfg.mods != []) "--mod-directory=${modDir}")
+      ];
 
       serviceConfig = {
         User = "factorio";
@@ -90,10 +116,12 @@ in
         PrivateTmp = true;
         UMask = "0007";
         ExecStart = toString [
-          "${pkgs.factorio-headless}/bin/factorio"
+          "${factorio}/bin/factorio"
           "--config=${cfg.configFile}"
           "--port=${toString cfg.port}"
-          "--start-server=${stateDir}/saves/${cfg.saveName}.zip"
+          "--start-server=${mkSavePath cfg.saveName}"
+          (optionalString (cfg.mods != []) "--mod-directory=${modDir}")
+          (optionalString (cfg.autosave-interval != null) "--autosave-interval ${toString cfg.autosave-interval}")
         ];
       };
     };