Factorio on Nix(OS)

Enhance your gameplay with these tools. This category is also the right place for tools useful for modders.
Mod databases, calculators, cheatsheets, multiplayer, scripts, libs and other useful stuff that is not strictly in-game mods.
loocuuwo
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Sep 08, 2015 6:01 pm
Contact:

Factorio on Nix(OS)

Post by loocuuwo »

I hacked together a nix expression (http://nixos.org/nix/) for "building" factorio:

Code: Select all

{ stdenv
, pkgs
, lib
, makeWrapper
, path
, version
}:

let
  libmapper = val: (map (x: x + "/lib") val ++ map (x: x + "/lib64") val); 
  lib_help = if stdenv.system == "x86_64-linux" then "lib64" else "lib";
in
assert (path != null);
assert (version != null);
stdenv.mkDerivation (rec {
  inherit version;
  name = "factorio-${version}";
  src = path;
  phases = [ "unpackPhase" "installPhase" ];
  buildInputs = [ makeWrapper ];
  libs = with pkgs; [ alsaLib xlibs.libX11 xlibs.libXcursor xlibs.libXinerama
                      xlibs.libXrandr xlibs.libXi
                    ];
  configPath = builtins.toFile "config-path.cfg" ''
    config-path=__PATH__executable__/../../config
    use-system-read-write-data-directories=true
  '';
  installPhase = ''
    mkdir -p "$out/opt/factorio/chroot/usr/share"
    cp -r bin "$out/opt/factorio/chroot"
    cp ${configPath} "$out/opt/factorio/chroot/config-path.cfg"
    chmod +x "$out/opt/factorio/chroot/bin/x64/factorio"

    interpreter=$(echo ${stdenv.glibc}/${lib_help}/ld-linux*.so.2)
    patchelf --set-interpreter $interpreter \
      "$out/opt/factorio/chroot/bin/x64/factorio"

    cp -r data "$out/opt/factorio/chroot/usr/share/factorio"

    mkdir "$out/bin"
    makeWrapper "${pkgs.fakechroot}/bin/fakechroot -- chroot $out/opt/factorio/chroot/ /bin/x64/factorio" "$out/bin/factorio" \
      --prefix FAKECHROOT_EXCLUDE_PATH : "\$HOME:/nix:/dev:/proc:/sys" \
      --prefix LD_LIBRARY_PATH : "${lib.concatStringsSep ":" (libmapper libs)}" \
      --add-flags "--config" --add-flags "\$HOME/.factorio/config.ini"
  '';
})
Use it like this:

Code: Select all

nix-build -E 'with import <nixpkgs> {}; callPackage ./default.nix { path = ./factorio_alpha_x64_0.12.6.tar.gz; version = "0.12.6"; }'
You can register the result in your user profile by calling something to the effect of:

Code: Select all

nix-env -i /nix/store/6i11cryni94n16zfi6kx6z6alkhflbjj-factorio-0.12.6
(I realise that this will probably of use to no one — it is however nice to have it written down somewhere should I ever lose my local copy)

azriphale
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sat Nov 07, 2015 3:43 pm
Contact:

Re: Factorio on Nix(OS)

Post by azriphale »

Thanks for the starting point, but it didn't work for me with some X11 errors:

Code: Select all

Major opcode of failed request 154 (GLX)
Minor opcode of failed request 24 (X_GLXCreateNewContext)
I used the above as a starting point for a more elaborate solution based on buildFHSUserEnv (used by the Steam derivation).

So far, my only test has been to launch it; I haven't played or tested that audio works.

After deploying the below files (and downloading factorio to ~/.nixpkgs/factorio/), install and run with:

Code: Select all

nix-env -iA nixos.factorio
factorio
In ~/.nixpgs/factorio/default.nix (based on the above post):

Code: Select all

{ stdenv
, pkgs
, lib
, makeWrapper
, path
, version
}:

let
  libmapper = val: (map (x: x + "/lib") val ++ map (x: x + "/lib64") val);
  lib_help = if stdenv.system == "x86_64-linux" then "lib64" else "lib";
in
assert (path != null);
assert (version != null);
stdenv.mkDerivation (rec {
  inherit version;
  name = "factorio-original-${version}";
  src = path;
  phases = [ "unpackPhase" "installPhase" ];
  buildInputs = [ makeWrapper ];
  libs = with pkgs; [ alsaLib xlibs.libX11 xlibs.libXcursor xlibs.libXinerama
                      xlibs.libXrandr xlibs.libXi mesa
                    ];
  configPath = builtins.toFile "config-path.cfg" ''
    config-path=__PATH__executable__/../../config
    use-system-read-write-data-directories=true
  '';
  installPhase = ''
    mkdir -p "$out/share"
    cp -r bin "$out/"
    cp ${configPath} "$out/config-path.cfg"
    chmod +x "$out/bin/x64/factorio"

    cp -r data "$out/share/factorio"

    cd "$out/bin"
    ln -s ./x64/factorio
  '';
})
In ~/.nixpgs/factorio/default.nix (based on the steam derivation):

Code: Select all

{ lib, buildFHSUserEnv, config }:

buildFHSUserEnv {
  name = "factorio";

  targetPkgs = pkgs:
    [ pkgs.factorio-original ];

  multiPkgs = pkgs:
    [
      pkgs.xlibs.libX11
      pkgs.xlibs.libXcursor
      pkgs.xlibs.libXi
      pkgs.xlibs.libXinerama
      pkgs.xlibs.libXrandr
      pkgs.mesa
      pkgs.alsaLib
    ];

  runScript = "factorio";
}
In ~/.nixpgs/config.nix:

Code: Select all

{
  allowUnfree = true;
  packageOverrides = pkgs_: with pkgs_; {
    factorio-original = callPackage ./factorio/default.nix {
      path = ./factorio/factorio_alpha_x64_0.12.16.tar.gz;
      version = "0.12.16";
    };
    factorio = callPackage ./factorio/chrootenv.nix {};
  };
}

Moonheart08
Inserter
Inserter
Posts: 27
Joined: Wed Jun 01, 2016 8:15 am
Contact:

Re: Factorio on Nix(OS)

Post by Moonheart08 »

Neato, i might go on bug patrol for fun
EDIT: realized this is not from ASM to executable.

Post Reply

Return to “Tools”