summary refs log tree commit diff
path: root/pkgs/games/dwarf-fortress/default.nix
blob: 9d363851148ddb5f2363eb3114be7b7ace7198d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{stdenv, fetchurl, SDL, SDL_image, SDL_ttf, gnomegtk, glib, mesa, openal, glibc, libsndfile}:

assert stdenv.system == "i686-linux";

stdenv.mkDerivation rec {
  name = "dwarf-fortress-0.31.25";

  src = fetchurl {
    url = "http://www.bay12games.com/dwarves/df_31_25_linux.tar.bz2";
    sha256 = "0d3klvf5n99j38pdhx9mak78px65aw47smck82jb92la97drmcg3";
  };

  phases = "unpackPhase patchPhase installPhase";

  /* :TODO: Game options should be configurable by patching the default configuration files */

  permission = ./df_permission;

  installPhase = ''
    set -x
    mkdir -p $out/bin
    mkdir -p $out/share/df_linux
    cp -r * $out/share/df_linux
    cp $permission $out/share/df_linux/nix_permission
 
    patchelf --set-interpreter ${glibc}/lib/ld-linux.so.2 $out/share/df_linux/libs/Dwarf_Fortress
    ln -s ${libsndfile}/lib/libsndfile.so $out/share/df_linux/libs/
          
    cat > $out/bin/dwarf-fortress << EOF
    #!${stdenv.shell}
    export DF_DIR="\$HOME/.config/df_linux"
    if [ -n "\$XDG_DATA_HOME" ]
     then export DF_DIR="\$XDG_DATA_HOME/df_linux"
    fi

    # Recreate a directory sturctor reflecting the original distribution in the user directory

    # Link in the static stuff
    mkdir -p \$DF_DIR
    ln -sf $out/share/df_linux/libs \$DF_DIR/
    ln -sf $out/share/df_linux/raw \$DF_DIR/
    ln -sf $out/share/df_linux/df \$DF_DIR/

    # Delete old data directory
    rm -rf \$DF_DIR/data
    
    # Link in the static data directory
    mkdir \$DF_DIR/data
    for i in $out/share/df_linux/data/*
    do
     ln -s \$i \$DF_DIR/data/
    done

    # index initial_movies, announcement, dipscript and help files are as of 0.31.16 opened in read/write mode instead of read-only mode
    # this is a hack to work around this
    # Should I just apply this to the whole data directory?
    for i in index initial_movies announcement dipscript help
    do
     rm \$DF_DIR/data/\$i
     cp -rf $out/share/df_linux/data/\$i \$DF_DIR/data/
     chmod -R u+w \$DF_DIR/data/\$i
    done

    # link in persistant data
    mkdir -p \$DF_DIR/save
    ln -s \$DF_DIR/save \$DF_DIR/data/

    # now run Dwarf Fortress! 
    export LD_LIBRARY_PATH=\$DF_DIR/df_linux/libs/:${SDL}/lib:${SDL_image}/lib/:${SDL_ttf}/lib/:${gnomegtk}/lib/:${glib}/lib/:${mesa}/lib/:${openal}/lib/
    \$DF_DIR/df "\$@"
    EOF

    chmod +x $out/bin/dwarf-fortress
  '';

  meta = {
      description = "control a dwarven outpost or an adventurer in a randomly generated, persistent world";
      homepage = http://www.bay12games.com/dwarves;
      license = "unfree-redistributable";
      maintainers = [stdenv.lib.maintainers.roconnor];
  };
}