@ -4,14 +4,13 @@ with lib;
let
cfg = config . services . factorio ;
factorio = pkgs . factorio-headless ;
name = " F a c t o r i o " ;
stateDir = " / v a r / l i b / ${ cfg . stateDirName } " ;
mkSavePath = name : " ${ stateDir } / s a v e s / ${ name } . z i p " ;
configFile = pkgs . writeText " f a c t o r i o . c o n f " ''
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 " s e r v e r - s e t t i n g s . j s o n " ( 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 = [ " u s e r n a m e " ] ; } ;
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 = " p k g s . f a c t o r i o - h e a d l e s s " ;
example = " p k g s . f a c t o r i o - h e a d l e s s - e x p e r i m e n t a l " ;
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 [
" t e s t - e ${ stateDir } / s a v e s / ${ cfg . saveName } . z i p "
" | | "
" ${ factorio } / b i n / f a c t o r i o "
" ${ cfg . package } / b i n / f a c t o r i o "
" - - c o n f i g = ${ cfg . configFile } "
" - - c r e a t e = ${ mkSavePath cfg . saveName } "
( optionalString ( cfg . mods != [ ] ) " - - m o d - d i r e c t o r y = ${ modDir } " )
@ -197,7 +213,7 @@ in
StateDirectory = cfg . stateDirName ;
UMask = " 0 0 0 7 " ;
ExecStart = toString [
" ${ factorio } / b i n / f a c t o r i o "
" ${ cfg . package } / b i n / f a c t o r i o "
" - - c o n f i g = ${ cfg . configFile } "
" - - p o r t = ${ toString cfg . port } "
" - - s t a r t - s e r v e r = ${ mkSavePath cfg . saveName } "