1{ lib
2, stdenv
3, fetchFromGitHub
4, fetchpatch
5, fetchurl
6, bzip2
7, cmake
8, pkg-config
9, gettext
10, libsodium
11, SDL2
12, SDL_audiolib
13, SDL2_image
14, fmt
15, libpng
16, smpq
17}:
18
19let
20 # TODO: submit a PR upstream to allow system copies of these libraries where possible
21
22 # fork with patches, far behind upstream
23 asio = fetchurl {
24 url = "https://github.com/diasurgical/asio/archive/ebeff99f539da23d27c2e8d4bdbc1ee011968644.tar.gz";
25 sha256 = "0vhb4cig40mm0a98i74grpmfkcmby8zxg6vqa38dpryxpgvp5fw8";
26 };
27
28 # fork with patches, upstream seems to be dead
29 libmpq = fetchurl {
30 url = "https://github.com/diasurgical/libmpq/archive/0f10bd1600f406b13932bf5351ba713361262184.tar.gz";
31 sha256 = "sha256-7hc/Xtsg8WJIJljLydS7hLZA9lEEHWhsCteyrxK68qE=";
32 };
33
34 # not "real" package with pkg-config or cmake file, just collection of source files
35 libsmackerdec = fetchurl {
36 url = "https://github.com/diasurgical/libsmackerdec/archive/2997ee0e41e91bb723003bc09234be553b190e38.tar.gz";
37 sha256 = "sha256-QMDcIZQ94i4VPVanmSxiGkKgxWx82DP4uE+Q5I2nU+o=";
38 };
39
40 # fork with patches, far behind upstream
41 libzt = fetchFromGitHub {
42 owner = "diasurgical";
43 repo = "libzt";
44 fetchSubmodules = true;
45 rev = "a34ba7f1cc2e41b05badd25d1b01fdc5fd2f4e02";
46 sha256 = "sha256-tyIPt+7OTi5W+5X/ixQP1puOKdhrqRZtpwXlWFBFpc8=";
47 };
48
49 # missing pkg-config and/or cmake file
50 simpleini = fetchurl {
51 url = "https://github.com/brofield/simpleini/archive/9b3ed7ec815997bc8c5b9edf140d6bde653e1458.tar.gz";
52 sha256 = "sha256-93kuyp8/ew7okW/6ThJMtLMZsR1YSeFcXu9Y65ELBFE==";
53 };
54in
55
56stdenv.mkDerivation rec {
57 pname = "devilutionx";
58 version = "1.4.0";
59
60 src = fetchFromGitHub {
61 owner = "diasurgical";
62 repo = "devilutionX";
63 rev = version;
64 sha256 = "sha256-uuIPTdgGpHA8j1M8b+kfnBuiJ5mdS9rckvEfn2h7lmo=";
65 };
66
67 patches = [
68 (fetchpatch {
69 url = "https://github.com/diasurgical/devilutionX/commit/03b22352fc9e1ecb88b20a053c90c04a50717267.patch";
70 sha256 = "sha256-5aAwi1NV8P+nLLbEEnlwLGNQCQBb0nQkIVe5tR5Shsw=";
71 })
72 ];
73
74 postPatch = ''
75 substituteInPlace Source/init.cpp --replace "/usr/share/diasurgical/devilutionx/" "${placeholder "out"}/share/diasurgical/devilutionx/"
76
77 # download dependencies ahead of time
78 substituteInPlace 3rdParty/asio/CMakeLists.txt --replace "${asio.url}" "${asio}"
79 substituteInPlace 3rdParty/libmpq/CMakeLists.txt --replace "${libmpq.url}" "${libmpq}"
80 substituteInPlace 3rdParty/libsmackerdec/CMakeLists.txt --replace "${libsmackerdec.url}" "${libsmackerdec}"
81 substituteInPlace 3rdParty/libzt/CMakeLists.txt \
82 --replace "GIT_REPOSITORY https://github.com/diasurgical/libzt.git" "" \
83 --replace "GIT_TAG ${libzt.rev}" "SOURCE_DIR ${libzt}"
84 substituteInPlace 3rdParty/simpleini/CMakeLists.txt --replace "${simpleini.url}" "${simpleini}"
85 '';
86
87 cmakeFlags = [
88 "-DBINARY_RELEASE=ON"
89 "-DVERSION_NUM=${version}"
90 ];
91
92 nativeBuildInputs = [
93 cmake
94 pkg-config
95 gettext
96 smpq # used to build devilutionx.mpq
97 ];
98
99 buildInputs = [
100 bzip2
101 fmt
102 libpng
103 libsodium
104 SDL2
105 SDL_audiolib
106 SDL2_image
107 ];
108
109 installPhase = ''
110 runHook preInstall
111
112 '' + (if stdenv.isDarwin then ''
113 mkdir -p $out/Applications
114 mv devilutionx.app $out/Applications
115 '' else ''
116 install -Dm755 -t $out/bin devilutionx
117 install -Dm755 -t $out/share/diasurgical/devilutionx devilutionx.mpq
118 install -Dm755 -t $out/share/applications ../Packaging/nix/devilutionx-hellfire.desktop ../Packaging/nix/devilutionx.desktop
119 install -Dm755 ../Packaging/resources/icon.png $out/share/icons/hicolor/512x512/apps/devilutionx.png
120 install -Dm755 ../Packaging/resources/hellfire.png $out/share/icons/hicolor/512x512/apps/devilutionx-hellfire.png
121 install -Dm755 ../Packaging/resources/icon_32.png $out/share/icons/hicolor/32x32/apps/devilutionx.png
122 install -Dm755 ../Packaging/resources/hellfire_32.png $out/share/icons/hicolor/32x32/apps/devilutionx-hellfire.png
123 '') + ''
124
125 runHook postInstall
126 '';
127
128 meta = with lib; {
129 homepage = "https://github.com/diasurgical/devilutionX";
130 description = "Diablo build for modern operating systems";
131 longDescription = "In order to play this game a copy of diabdat.mpq is required. Place a copy of diabdat.mpq in ~/.local/share/diasurgical/devilution before executing the game.";
132 license = licenses.unlicense;
133 maintainers = with maintainers; [ karolchmist aanderse ];
134 platforms = platforms.linux ++ platforms.windows;
135 };
136}