Factorio: Difference between revisions

From NixOS Wiki
Klinger (talk | contribs)
Overhaul page per the MoS.
Line 1: Line 1:
[https://en.wikipedia.org/wiki/Factorio Factorio] is a video game created by Wube Software. Factorio has a multiplayer mode that requires a dedicated server, which is what this guide is about. If you have tips for installing the Factorio client, please feel free to expand this wiki page.
<strong>[https://www.factorio.com Factorio]</strong> is a video game created by [https://www.factorio.com/game/about Wube Software]. Factorio has a multiplayer mode that requires a dedicated server, which is available on Nixpkgs and can be installed on NixOS.


For more specific information about Factorio multiplayer, see: https://wiki.factorio.com/Multiplayer
== Installation ==


== Default Server Installation ==
{{Unfree}}


To install the Factorio server, add "factorio-headless" to your "systemPackages" in your NixOS configuration:  
To install the Factorio server, add the following to your [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration|NixOS configuration]]:


<syntaxhighlight lang=nix>
{{file|configuration.nix|nix|
environment.systemPackages = with pkgs; [
<nowiki>
  factorio-headless
{
];
  environment.systemPackages = [ pkgs.factorio-headless ];
# Also enable non-free packages or else the factorio download will fail:
  nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
nixpkgs.config.allowUnfree = true;
    "factorio-headless"
</syntaxhighlight>
  ];
}
</nowiki>
}}
{{Evaluate}}


It's important to only install "factorio-headless" instead of "factorio" because the headless version is a free download that does not require login credentials.
It is important to only install <code>factorio-headless</code> instead of <code>factorio</code> because the headless version is a redistributable download that does not require login credentials.


== Configuration ==
== Configuration ==


Here is a minimum viable configuration for the Factorio server (add this to your NixOS configuration):
Here is a minimum viable configuration for the Factorio server:


<syntaxhighlight lang=nix>
{{file|configuration.nix|nix|
services.factorio = {
<nowiki>
  enable = true;
{
  openFirewall = true;
  services.factorio = {
};
    enable = true;
</syntaxhighlight>
    openFirewall = true;
  };
}
</nowiki>
}}


This will run a non-password-protected server that binds to "0.0.0.0" and uses the default UDP port of 34197, with an auto-generated save file. Factorio servers support IPv6 by setting <code>bind = "[::]";</code>. All default settings can be seen here: https://search.nixos.org/options?&query=factorio
This will run a unprotected server that binds to the <code>0.0.0.0</code> local IP address and uses the default UDP port of <code>34197</code>, with an auto-generated save file. Factorio servers support IPv6 by setting <code>bind = "[::]";</code>. All default settings can be seen here: {{nixos:option|services.factorio.*}}


== Mods ==
=== Mods ===


The NixOS module for Factorio supports [https://wiki.factorio.com/Modding Factorio mods], which are just zip files. While technically you can create a full derivation for mods, in practice this can get complicated, especially since authentication is required to download mods from the official mod site.
The NixOS module for Factorio supports [https://wiki.factorio.com/Modding Factorio third-party modifications], or <i>mods</i>, which are just zip files with extra game content. While technically you can create a full derivation for mods, in practice this can get complicated, especially since authentication is required to download mods from the official mod site.


Instead, you can download the mods you need separately from https://mods.factorio.com/, place them in a folder such as <code>/home/username/factorio-mods</code>, and put this code in your configuration.nix (credit to [https://github.com/nicball/nuc-nixos-configuration/blob/f70f2c4d8da1f2648b5e595d9058e0f105409fd7/factorio.nix#L16 nicball]):
Instead, you can download the mods you need separately from https://mods.factorio.com/, place them in a folder such as <code>/home/username/factorio-mods</code>, and put this code in your [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration|NixOS configuration]]. (credit to [https://github.com/nicball/nuc-nixos-configuration/blob/f70f2c4d8da1f2648b5e595d9058e0f105409fd7/factorio.nix#L16 nicball]):


<syntaxhighlight lang=nix>
{{file|configuration.nix|nix|
services.factorio = {
<nowiki>
  # --omitted--
{
  mods =
  services.factorio.mods =
     let
     let
       inherit (pkgs) lib;
       inherit (pkgs) lib;
Line 54: Line 62:
           cp ${modDir + "/${modFileName}"} $out/${modFileName}
           cp ${modDir + "/${modFileName}"} $out/${modFileName}
         ''
         ''
        // { deps = []; };
      // { deps = []; };
    in
  in
      builtins.map modToDrv modList;
    builtins.map modToDrv modList;
};
}
</syntaxhighlight>
</nowiki>
}}


Note that any changes to the list of mods in the "factorio-mods" folder require running <code>nixos-rebuild switch</code>.
== See also ==
 
* [https://wiki.factorio.com/Multiplayer The Factorio wiki page on Multiplayer]


[[Category:Gaming]]
[[Category:Gaming]]
[[Category:Server]]
[[Category:Server]]

Revision as of 14:32, 30 October 2024

Factorio is a video game created by Wube Software. Factorio has a multiplayer mode that requires a dedicated server, which is available on Nixpkgs and can be installed on NixOS.

Installation

Note: This package is unfree and requires extra steps to install.

To install the Factorio server, add the following to your NixOS configuration:

configuration.nix
{
  environment.systemPackages = [ pkgs.factorio-headless ];
  nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
    "factorio-headless"
  ];
}

It is important to only install factorio-headless instead of factorio because the headless version is a redistributable download that does not require login credentials.

Configuration

Here is a minimum viable configuration for the Factorio server:

configuration.nix
{
  services.factorio = {
    enable = true;
    openFirewall = true;
  };
}

This will run a unprotected server that binds to the 0.0.0.0 local IP address and uses the default UDP port of 34197, with an auto-generated save file. Factorio servers support IPv6 by setting bind = "[::]";. All default settings can be seen here: services.factorio.*

Mods

The NixOS module for Factorio supports Factorio third-party modifications, or mods, which are just zip files with extra game content. While technically you can create a full derivation for mods, in practice this can get complicated, especially since authentication is required to download mods from the official mod site.

Instead, you can download the mods you need separately from https://mods.factorio.com/, place them in a folder such as /home/username/factorio-mods, and put this code in your NixOS configuration. (credit to nicball):

configuration.nix
{
  services.factorio.mods =
    let
      inherit (pkgs) lib;
      modDir = /home/username/factorio-mods;
      modList = lib.pipe modDir [
        builtins.readDir
        (lib.filterAttrs (k: v: v == "regular"))
        (lib.mapAttrsToList (k: v: k))
        (builtins.filter (lib.hasSuffix ".zip"))
      ];
      modToDrv = modFileName:
        pkgs.runCommand "copy-factorio-mods" {} ''
          mkdir $out
          cp ${modDir + "/${modFileName}"} $out/${modFileName}
        ''
      // { deps = []; };
  in
    builtins.map modToDrv modList;
}

See also