summary refs log tree commit diff
path: root/pkgs/games/factorio
diff options
context:
space:
mode:
authorSvein Ove Aas <sveina@gmail.com>2016-01-22 23:54:49 +0000
committerSvein Ove Aas <sveina@gmail.com>2016-01-23 13:15:18 +0000
commitef582b2805fca03c7f4aa9848cf7935407295139 (patch)
tree04ddb415dc7779500f586f2b90894edad89e653c /pkgs/games/factorio
parentecc48af0ce20e24a7e4d56e663f5752d69384644 (diff)
downloadnixpkgs-ef582b2805fca03c7f4aa9848cf7935407295139.tar
nixpkgs-ef582b2805fca03c7f4aa9848cf7935407295139.tar.gz
nixpkgs-ef582b2805fca03c7f4aa9848cf7935407295139.tar.bz2
nixpkgs-ef582b2805fca03c7f4aa9848cf7935407295139.tar.lz
nixpkgs-ef582b2805fca03c7f4aa9848cf7935407295139.tar.xz
nixpkgs-ef582b2805fca03c7f4aa9848cf7935407295139.tar.zst
nixpkgs-ef582b2805fca03c7f4aa9848cf7935407295139.zip
factorio: init at 0.12.20
Diffstat (limited to 'pkgs/games/factorio')
-rw-r--r--pkgs/games/factorio/default.nix100
-rw-r--r--pkgs/games/factorio/fetch.nix33
-rw-r--r--pkgs/games/factorio/fetch.sh44
3 files changed, 177 insertions, 0 deletions
diff --git a/pkgs/games/factorio/default.nix b/pkgs/games/factorio/default.nix
new file mode 100644
index 00000000000..b08f977cda6
--- /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 <<EOF
+use-system-read-write-data-directories=false
+[path]
+read-data=$out/share/factorio/data/
+EOF
+
+    cat > $out/share/factorio/update-config.sh <<EOF
+if [[ -e ~/.factorio/config.cfg ]]; then
+  # Config file exists, but may have wrong path.
+  # Try to edit it. I'm sure this is perfectly safe and will never go wrong.
+  sed -i 's|^read-data=.*|read-data=$out/share/factorio/data/|' ~/.factorio/config.cfg
+else
+  # Config file does not exist. Phew.
+  install -D $out/share/factorio/config-base.cfg ~/.factorio/config.cfg
+fi
+EOF
+    chmod a+x $out/share/factorio/update-config.sh
+
+    patchelf \
+      --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
+      $out/bin/factorio.${arch}
+
+    makeWrapper $out/bin/factorio.${arch} $out/bin/factorio \
+      --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib:$libPath \
+      --run "$out/share/factorio/update-config.sh" \
+      --add-flags "-c \$HOME/.factorio/config.cfg"
+  '';
+
+  meta = {
+    description = "A game in which you build and maintain factories.";
+    longDescription = ''
+      Factorio is a game in which you build and maintain factories.
+
+      You will be mining resources, researching technologies, building
+      infrastructure, automating production and fighting enemies. Use your
+      imagination to design your factory, combine simple elements into
+      ingenious structures, apply management skills to keep it working and
+      finally protect it from the creatures who don't really like you.
+
+      Factorio has been in development since spring of 2012 and it is
+      currently in late alpha.
+    '';
+    homepage = https://www.factorio.com/;
+    license = stdenv.lib.licenses.unfree;
+    maintainers = [ stdenv.lib.maintainers.Baughn ];
+    platforms = [ "i686-linux" "x86_64-linux" ];
+  };
+}
diff --git a/pkgs/games/factorio/fetch.nix b/pkgs/games/factorio/fetch.nix
new file mode 100644
index 00000000000..03dc786492a
--- /dev/null
+++ b/pkgs/games/factorio/fetch.nix
@@ -0,0 +1,33 @@
+{ stdenv, curl
+# Begin download parameters
+, username ? ""
+, password ? ""
+}:
+
+{
+  # URL to fetch.
+  url ? ""
+
+  # Login URL.
+, loginUrl ? "https://www.factorio.com/login"
+
+  # SHA256 of the fetched URL.
+, sha256 ? ""
+}:
+
+stdenv.mkDerivation {
+  name = "factorio.tar.gz";
+
+  buildInputs = [ curl ];
+
+  inherit url loginUrl username password;
+
+  builder = ./fetch.sh;
+
+  outputHashAlgo = "sha256";
+  outputHash = sha256;
+  outputHashMode = "flat";
+
+  # There's no point in downloading remotely, we'd just slow things down.
+  preferLocalBuild = true;
+}
diff --git a/pkgs/games/factorio/fetch.sh b/pkgs/games/factorio/fetch.sh
new file mode 100644
index 00000000000..ad976673686
--- /dev/null
+++ b/pkgs/games/factorio/fetch.sh
@@ -0,0 +1,44 @@
+source $stdenv/setup
+
+# Curl flags to increase reliability a bit.
+#
+# Can't use fetchurl, for several reasons. One is that we definitely
+# don't want --insecure for the login, though we need it for the
+# download as their download cert isn't in the standard linux bundle.
+curl="curl \
+ --max-redirs 20 \
+ --retry 3 \
+ --cacert /etc/ssl/certs/ca-bundle.crt \
+ $curlOpts \
+ $NIX_CURL_FLAGS"
+
+# We don't want the password to be on any program's argv, as it may be
+# visible in /proc. Writing it to file with echo should be safe, since
+# it's a shell builtin.
+echo "password=$password" > 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 = "<username or email address>";'
+    echo '      password = "<password>";'
+    echo '    };'
+    echo '  };'
+    echo '}'
+
+    exit 1
+fi