Factorio: Difference between revisions

Overhaul page per the MoS.
DoggoBit (talk | contribs)
No edit summary
 
(4 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 40: Line 40:
=== Mods ===
=== Mods ===


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.
The NixOS module for Factorio supports [https://wiki.factorio.com/Modding third-party modifications], or <i>mods</i>, 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 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]):
Instead, you can download the mods you need imperatively from https://mods.factorio.com/, place them in a folder such as <code>/etc/nixos/factorio-mods</code>, and put this code in your [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration|NixOS configuration]]:


{{file|configuration.nix|nix|
{{file|configuration.nix|nix|
<nowiki>
<nowiki>
{
{
   services.factorio.mods =
   services.factorio = {
     let
     mods =
       inherit (pkgs) lib;
       let
      modDir = /home/username/factorio-mods;
        modDir = ./factorio-mods;
      modList = lib.pipe modDir [
        modList = lib.pipe modDir [
        builtins.readDir
          builtins.readDir
        (lib.filterAttrs (k: v: v == "regular"))
          (lib.filterAttrs (k: v: v == "regular"))
        (lib.mapAttrsToList (k: v: k))
          (lib.mapAttrsToList (k: v: k))
        (builtins.filter (lib.hasSuffix ".zip"))
          (builtins.filter (lib.hasSuffix ".zip"))
      ];
        ];
      modToDrv = modFileName:
        validPath = modFileName:
        pkgs.runCommand "copy-factorio-mods" {} ''
          builtins.path {
          mkdir $out
            path = modDir + "/${modFileName}";
          cp ${modDir + "/${modFileName}"} $out/${modFileName}
            name = lib.strings.sanitizeDerivationName modFileName;
        ''
          };
      // { deps = []; };
        modToDrv = modFileName:
  in
          pkgs.runCommand "copy-factorio-mods" {} ''
    builtins.map modToDrv modList;
            mkdir $out
            ln -s '${validPath modFileName}' $out/'${modFileName}'
          ''
          // { deps = []; };
      in
        builtins.map modToDrv modList;
  };
}
}
</nowiki>
</nowiki>
}}
}}
This code was developed by [https://github.com/nicball/nuc-nixos-configuration/blob/fccfa8441cba60c835aa2eb4238ae6f53bb781bb/factorio.nix#L16-L37 nicball].


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