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"
'';
})
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"; }'
Code: Select all
nix-env -i /nix/store/6i11cryni94n16zfi6kx6z6alkhflbjj-factorio-0.12.6