summaryrefslogtreecommitdiff
path: root/nixos/stardew-valley.nix
blob: ef2bb5527ff53573d5abe0ff3576a1b5ecb4dbd1 (plain)
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
{stdenv, glibc, coreutils, patchelf, requireFile, unzip, xorg, makeWrapper, libpulseaudio }:

with stdenv.lib;

stdenv.mkDerivation rec {
  name = "stardew-valley-${version}";
  version = "2.3.0.4";
  src = requireFile {
    name = "gog_stardew_valley_${version}.sh";
    sha256 = "88e1fae7226c7bfa91cb28c137c24867e12b1a0b6e824e6ffe73e1eefc166aac";
    url = "https://gog.com";
  };

  buildInputs = [ coreutils unzip makeWrapper ];

  unpackPhase = ''
    mkdir src
    cd src
    unzip $src || true
    # offset=$(${stdenv.shell} -c "$(grep -axm1 -e 'offset=.*' $src); echo \$offset" $src)
    # dd if="$src" ibs=$offset skip=1 | gzip -cd | tar xvf - || true
  '';

  libPath = stdenv.lib.makeLibraryPath [ glibc xorg.libX11 xorg.libXext libpulseaudio ];

  buildPhase = ''
    patchelf \
      --set-rpath "${stdenv.lib.makeLibraryPath [ xorg.libX11 ]}" \
      --set-interpreter "$(cat ${stdenv.cc}/nix-support/dynamic-linker)" \
      ./data/noarch/game/mcs.bin.x86_64
    patchelf \
      --set-rpath "${stdenv.lib.makeLibraryPath [ xorg.libX11 ]}" \
      --set-interpreter "$(cat ${stdenv.cc}/nix-support/dynamic-linker)" \
      ./data/noarch/game/StardewValley.bin.x86_64
  '';

  installPhase = ''
    mkdir $out
    cp -r * $out/
    makeWrapper \
      "$out/data/noarch/start.sh" \
      "$out/bin/stardew-valley" \
      --prefix LD_LIBRARY_PATH : "${libPath}"
  '';
}