Factorio

From NixOS Wiki
Jump to: navigation, search

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.

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

Default Server Installation

To install the Factorio server, add "factorio-headless" to your "systemPackages" in your NixOS configuration:

environment.systemPackages = with pkgs; [
  factorio-headless
];
# Also enable non-free packages or else the factorio download will fail:
nixpkgs.config.allowUnfree = true;

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.

Configuration

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

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

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 bind = "[::]";. All default settings can be seen here: https://search.nixos.org/options?&query=factorio

Mods

The NixOS module for Factorio supports 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.

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 configuration.nix (credit to nicball):

services.factorio = {
  # --omitted--
  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;
};

Note that any changes to the list of mods in the "factorio-mods" folder require running nixos-rebuild switch.