about summary refs log tree commit diff
path: root/pkgs/games/build-support/build-unity.nix
blob: 4169870c3540393b2a84b441ba7704fabd93df96 (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
{ stdenv, lib, buildGame, makeWrapper, gtk2-x11, gdk_pixbuf, glib
, libGL, xorg, libpulseaudio, libudev, zlib
}:

{ name, version, fullName
, saveDir ? null
, nativeBuildInputs ? []
, buildInputs ? []
, runtimeDependencies ? []
, sandbox ? {}
, ...
}@attrs:

let
  arch = if stdenv.system == "x86_64-linux" then "x86_64" else "x86";
  executable = "${fullName}.${arch}";
  dataDir = "${fullName}_Data";
  maybeSavedir = lib.optionalString (saveDir != null) "/${saveDir}";

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

  nativeBuildInputs = [ makeWrapper ] ++ nativeBuildInputs;

  buildInputs = [ gtk2-x11 gdk_pixbuf glib ] ++ buildInputs;

  runtimeDependencies = [
    libGL xorg.libX11 xorg.libXcursor xorg.libXrandr libudev zlib
  ] ++ runtimeDependencies;

  sandbox = sandbox // {
    paths = (sandbox.paths or {}) // {
      required = (sandbox.paths.required or []) ++ [
        "$XDG_CONFIG_HOME/unity3d${maybeSavedir}"
      ];
    };
  };

  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" \
      --run "cd '$out/share/$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 [ -d "$fullName.app" ]; then
      cp -vRd -t "$out/share/$slugName" "$fullName.app"
    fi

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

    runHook postInstall
  '';
} // removeAttrs attrs [
  "name" "version" "fullName" "nativeBuildInputs" "buildInputs"
  "runtimeDependencies" "sandbox"
])