about summary refs log tree commit diff
path: root/pkgs/games/build-support/build-unity.nix
blob: dfd69bba48d2303c457cb2333d69c5b27b6aba8f (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
{ stdenv, makeWrapper, mesa, xorg, libpulseaudio, libudev }:

{ name, version, fullName, buildPhase ? "", rpath ? [], ... }@attrs:

let
  arch = if stdenv.system == "x86_64-linux" then "x86_64" else "x86";
  executable = "${fullName}.${arch}";
  dataDir = "${fullName}_Data";

in stdenv.mkDerivation ({
  name = "${name}-${version}";
  inherit fullName version arch executable dataDir;
  slugName = name;

  nativeBuildInputs = [ makeWrapper ];

  buildPhase = let
    mainRpath = stdenv.lib.makeLibraryPath ([
      stdenv.cc.cc mesa xorg.libX11 xorg.libXcursor xorg.libXrandr
      libpulseaudio libudev
    ] ++ rpath);
  in ''
    runHook preBuild

    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      --set-rpath ${stdenv.lib.escapeShellArg mainRpath} "$executable"

    ${buildPhase}

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    install -vD "$executable" "$out/libexec/$slugName/$slugName"
    ln -s "$out/share/$slugName" "$out/libexec/$slugName/Data"

    mkdir -p "$out/bin"
    makeWrapper "$out/libexec/$slugName/$slugName" "$out/bin/$slugName"

    iconpath="$out/share/$slugName/Resources/UnityPlayer.png"
    mkdir -p "$out/share/applications"
    cat > "$out/share/applications/$slugName.desktop" <<EOF
    [Desktop Entry]
    Name=$fullName
    Type=Application
    Version=1.1
    Exec=$out/bin/$slugName
    Icon=$iconpath
    Categories=Game
    StartupNotify=true
    EOF

    cp -vRd "$dataDir" "$out/share/$slugName"

    if [ ! -e "$iconpath" ]; then
      echo "Desktop icon not found at $iconpath." >&2
      exit 1
    fi

    runHook postInstall
  '';

  dontStrip = true;
  dontPatchELF = true;
} // removeAttrs attrs [ "name" "version" "fullName" "buildPhase" "rpath" ])