summary refs log tree commit diff
path: root/pkgs/games/freeorion
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2016-04-18 16:48:38 +0300
committerRicardo Ardissone <ricardo.ardissone@gmail.com>2016-04-18 16:20:46 -0300
commitd8eec18ce20ae7b0dde087937d4daf78b9619748 (patch)
tree7f2fc5ef93dfb872d363a224b7ba73c2cb1f34a3 /pkgs/games/freeorion
parent756a83191c1ce3597e9d903e2bd7a89932420e53 (diff)
downloadnixpkgs-d8eec18ce20ae7b0dde087937d4daf78b9619748.tar
nixpkgs-d8eec18ce20ae7b0dde087937d4daf78b9619748.tar.gz
nixpkgs-d8eec18ce20ae7b0dde087937d4daf78b9619748.tar.bz2
nixpkgs-d8eec18ce20ae7b0dde087937d4daf78b9619748.tar.lz
nixpkgs-d8eec18ce20ae7b0dde087937d4daf78b9619748.tar.xz
nixpkgs-d8eec18ce20ae7b0dde087937d4daf78b9619748.tar.zst
nixpkgs-d8eec18ce20ae7b0dde087937d4daf78b9619748.zip
freeorion: fix paths in configuration file before start
Diffstat (limited to 'pkgs/games/freeorion')
-rw-r--r--pkgs/games/freeorion/default.nix20
-rw-r--r--pkgs/games/freeorion/fix-paths.sh6
-rw-r--r--pkgs/games/freeorion/fix-paths.xslt13
3 files changed, 37 insertions, 2 deletions
diff --git a/pkgs/games/freeorion/default.nix b/pkgs/games/freeorion/default.nix
index 8c3921c1236..e143b6ebcf3 100644
--- a/pkgs/games/freeorion/default.nix
+++ b/pkgs/games/freeorion/default.nix
@@ -1,4 +1,5 @@
-{ stdenv, fetchurl, cmake, boost, SDL2, python2, freetype, openal, libogg, libvorbis, zlib, libpng, libtiff, libjpeg, mesa, glew, doxygen }:
+{ stdenv, fetchurl, cmake, boost, SDL2, python2, freetype, openal, libogg, libvorbis, zlib, libpng, libtiff, libjpeg, mesa, glew, doxygen
+, libxslt, makeWrapper }:
 
 stdenv.mkDerivation rec {
   version = "0.4.5";
@@ -9,13 +10,28 @@ stdenv.mkDerivation rec {
     sha256 = "3b99b92eeac72bd059566dbabfab54368989ba83f72e769bc94eb8dd4fe414c0";
   };
 
-  buildInputs = [ cmake boost SDL2 python2 freetype openal libogg libvorbis zlib libpng libtiff libjpeg mesa glew doxygen ];
+  buildInputs = [ cmake boost SDL2 python2 freetype openal libogg libvorbis zlib libpng libtiff libjpeg mesa glew doxygen makeWrapper ];
 
   # cherry pick for acceptable performance https://github.com/freeorion/freeorion/commit/92455f97c28055e296718230d2e3744eccd738ec
   patches = [ ./92455f9.patch ];
 
   enableParallelBuilding = true;
 
+  postInstall = ''
+    mkdir -p $out/fixpaths
+    # We need final slashes for XSLT replace to work properly
+    substitute ${./fix-paths.xslt} $out/fixpaths/fix-paths.xslt \
+      --subst-var-by nixStore "$NIX_STORE/" \
+      --subst-var-by out "$out/"
+    substitute ${./fix-paths.sh} $out/fixpaths/fix-paths \
+      --subst-var-by libxsltBin ${libxslt.bin} \
+      --subst-var out
+    chmod +x $out/fixpaths/fix-paths
+
+    wrapProgram $out/bin/freeorion \
+      --run $out/fixpaths/fix-paths
+  '';
+
   meta = with stdenv.lib; {
     description = "A free, open source, turn-based space empire and galactic conquest (4X) computer game";
     homepage = "http://www.freeorion.org";
diff --git a/pkgs/games/freeorion/fix-paths.sh b/pkgs/games/freeorion/fix-paths.sh
new file mode 100644
index 00000000000..cd6f381de25
--- /dev/null
+++ b/pkgs/games/freeorion/fix-paths.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+if [ -e ~/.freeorion/config.xml ]; then
+  @libxsltBin@/bin/xsltproc -o ~/.freeorion/config.xml @out@/fixpaths/fix-paths.xslt ~/.freeorion/config.xml
+fi
+exit 0
diff --git a/pkgs/games/freeorion/fix-paths.xslt b/pkgs/games/freeorion/fix-paths.xslt
new file mode 100644
index 00000000000..f0db646b81a
--- /dev/null
+++ b/pkgs/games/freeorion/fix-paths.xslt
@@ -0,0 +1,13 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+  <xsl:output method="xml" omit-xml-declaration="no" indent="yes" />
+
+  <xsl:template match='node() | @*'>
+    <xsl:copy>
+      <xsl:apply-templates select='node() | @*'/>
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match='//text()[starts-with(., "@nixStore@")]'>
+    <xsl:value-of select='concat("@out@", substring-after(substring-after(., "@nixStore@"), "/"))'/>
+  </xsl:template>
+</xsl:stylesheet>