From d33540734ffd5da87fc01fdc959463b77fc267bf Mon Sep 17 00:00:00 2001 From: Eric Litak Date: Wed, 3 Aug 2016 06:44:15 -0700 Subject: factorio: rudimentary mod support for factorio's nixos module --- nixos/modules/services/games/factorio.nix | 48 ++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'nixos/modules/services/games') diff --git a/nixos/modules/services/games/factorio.nix b/nixos/modules/services/games/factorio.nix index 90834c5b2605..0369752997a7 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}") ]; }; }; -- cgit 1.4.1