Jump to content

Factorio: Difference between revisions

From NixOS Wiki
Mods: : Update snippet, now MIT-licensed!
DoggoBit (talk | contribs)
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{tip/unfree}}
<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.
<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.


== Installation ==
== Installation ==
{{Unfree}}


To install the Factorio server, add the following to your [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration|NixOS configuration]]:
To install the Factorio server, add the following to your [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration|NixOS configuration]]:
Line 74: Line 74:
</nowiki>
</nowiki>
}}
}}
This code was developed by [https://github.com/nicball/nuc-nixos-configuration/blob/f70f2c4d8da1f2648b5e595d9058e0f105409fd7/factorio.nix#L16 nicball], and is licensed under the MIT License.
This code was developed by [https://github.com/nicball/nuc-nixos-configuration/blob/fccfa8441cba60c835aa2eb4238ae6f53bb781bb/factorio.nix#L16-L37 nicball].


== See also ==
== See also ==

Latest revision as of 20:07, 5 June 2025

🟆︎
Tip: This package is unfree, and will require extra steps to install. You can read more about allowing unfree software in the Nixpkgs Manual.

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

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"
  ];
}
🟆︎
Tip: In order to affect your NixOS system by your nix-language-specific changes you must first evaluate it:
$ nixos-rebuild switch --sudo


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 third-party modifications, or mods, which are just compressed archives 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 imperatively from https://mods.factorio.com/, place them in a folder such as /etc/nixos/factorio-mods, and put this code in your NixOS configuration:

❄︎ configuration.nix
{
  services.factorio = {
    mods =
      let
        modDir = ./factorio-mods;
        modList = lib.pipe modDir [
          builtins.readDir
          (lib.filterAttrs (k: v: v == "regular"))
          (lib.mapAttrsToList (k: v: k))
          (builtins.filter (lib.hasSuffix ".zip"))
        ];
        validPath = modFileName:
          builtins.path {
            path = modDir + "/${modFileName}";
            name = lib.strings.sanitizeDerivationName modFileName;
          };
        modToDrv = modFileName:
          pkgs.runCommand "copy-factorio-mods" {} ''
            mkdir $out
            ln -s '${validPath modFileName}' $out/'${modFileName}'
          ''
          // { deps = []; };
      in
        builtins.map modToDrv modList;
  };
}

This code was developed by nicball.

See also