diff --git a/pkgs/games/factorio/default.nix b/pkgs/games/factorio/default.nix new file mode 100644 index 000000000000..b08f977cda6b --- /dev/null +++ b/pkgs/games/factorio/default.nix @@ -0,0 +1,100 @@ +{ stdenv, callPackage, fetchurl, makeWrapper +# Begin libraries +, alsaLib, libX11, libXcursor, libXinerama, libXrandr, libXi +# Begin download parameters +, username ? "" +, password ? "" +}: + +let + version = "0.12.20"; + + fetch = callPackage ./fetch.nix { username = username; password = password; }; + arch = if stdenv.system == "x86_64-linux" then "x64" + else if stdenv.system == "i686-linux" then "x32" + else abort "Unsupported platform"; + + variants = { + x64 = { + url = "https://www.factorio.com/get-download/${version}/alpha/linux64"; + sha256 = "1xpzrx3q678519qgjl92fxn3qv55hd188x9jp6dcfk2ljhi1gmqk"; + }; + + x32 = { + url = "https://www.factorio.com/get-download/${version}/alpha/linux32"; + sha256 = "1dl1dsp4nni5nda437ckyw1ss6w168g19v51h7cdvb3cgsdb7sab"; + }; + }; +in + +stdenv.mkDerivation rec { + name = "factorio-${version}"; + + src = fetch variants.${arch}; + + libPath = stdenv.lib.makeLibraryPath [ + alsaLib + libX11 + libXcursor + libXinerama + libXrandr + libXi + ]; + + buildInputs = [ makeWrapper ]; + + installPhase = '' + mkdir -p $out/{bin,share/factorio} + cp -a bin/${arch}/factorio $out/bin/factorio.${arch} + cp -a doc-html data $out/share/factorio/ + + # Fortunately, Factorio already supports system-wide installs. + # Unfortunately it's a bit inconvenient to set the paths. + cat > $out/share/factorio/config-base.cfg < $out/share/factorio/update-config.sh < password +# Might as well hide the username as well. +echo "username-or-email=$username" > username + +# Log in. We don't especially care about the result, but let's check if login failed. +$curl -c cookies -d @username -d @password $loginUrl -D headers > /dev/null + +if grep -q 'Location: /' headers; then + # Now download. We need --insecure for this, but the sha256 should cover us. + $curl -b cookies --insecure --location $url > $out +else + echo 'Login failed' + echo 'Please set username and password with config.nix,' + echo 'or /etc/nix/nixpkgs-config.nix if on NixOS.' + echo + echo 'Example:' + echo '{' + echo ' packageOverrides = pkgs: rec {' + echo ' factorio = pkgs.factorio.override {' + echo ' username = "";' + echo ' password = "";' + echo ' };' + echo ' };' + echo '}' + + exit 1 +fi diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index a8f01dda21f0..24e9808654d8 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14110,6 +14110,8 @@ let exult = callPackage ../games/exult { }; + factorio = callPackage ../games/factorio {}; + fairymax = callPackage ../games/fairymax {}; fish-fillets-ng = callPackage ../games/fish-fillets-ng {};