about summary refs log tree commit diff
path: root/nixpkgs/pkgs/games/principia/default.nix
blob: 3cf98dada02759738e488499fbf296bda80ff3d6 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{ lib
, stdenv
, fetchFromGitHub
, autoreconfHook
, pkg-config

, curl
, freetype
, glew
, gtk2
, libGL
, libjpeg
, libpng
, SDL2
, SDL2_gfx
, SDL2_image
, SDL2_mixer
, SDL2_ttf
}:

stdenv.mkDerivation {
  pname = "principia";
  version = "unstable-2023-03-21";

  src = fetchFromGitHub {
    owner = "Bithack";
    repo = "principia";
    rev = "af2cfda21b6ce4c0725700e2a01b0597a97dbeff";
    hash = "sha256-jBWdXzbPpk23elHcs5sWkxXfkekj+aa24VvEHzid8KE=";
  };

  nativeBuildInputs = [
    autoreconfHook
    pkg-config
  ];

  buildInputs = [
    curl
    freetype
    glew
    gtk2
    libGL
    libjpeg
    libpng
    SDL2
    SDL2_gfx
    SDL2_image
    SDL2_mixer
    SDL2_ttf
  ];

  preAutoreconf = ''
    cd build-linux
  '';

  # Since we bypass the "build-linux/go" wrapper script so we can use nixpkgs'
  # autotools/make integration, set the release flags manually.
  # https://github.com/Bithack/principia/issues/98
  preBuild = ''
    RELEASE_SHARED="-ffast-math -DNDEBUG=1 -s -fomit-frame-pointer -fvisibility=hidden -fdata-sections -ffunction-sections"
    makeFlagsArray+=(
      CFLAGS="$RELEASE_SHARED -O1"
      CXXFLAGS="$RELEASE_SHARED -O2 -fvisibility-inlines-hidden -fno-rtti"
      LDFLAGS="-Wl,-O,-s,--gc-sections"
    )
  '';

  # `make install` only installs the binary, and the binary looks for data
  # files in its same directory, so we override installPhase, install the
  # binary in $out/share, and link to it from $out/bin
  installPhase = ''
    runHook preInstall

    mkdir -p $out/bin
    mkdir -p $out/share/principia
    install -Dm755 principia $out/share/principia/principia
    ln -s $out/share/principia/principia $out/bin/principia

    cp -r --dereference data-pc data-shared $out/share/principia/
    install -Dm644 principia.desktop $out/share/applications/principia.desktop
    install -Dm644 principia-url-handler.desktop $out/share/applications/principia-url-handler.desktop
    install -Dm644 principia.png $out/share/pixmaps/principia.png

    runHook postInstall
  '';

  # The actual binary is here, see comment above installPhase
  stripDebugList = [ "share/principia" ];

  meta = with lib; {
    description = "Physics-based sandbox game";
    homepage = "https://principia-web.se/";
    downloadPage = "https://principia-web.se/download";
    license = licenses.bsd3;
    maintainers = [ maintainers.fgaz ];
    platforms = platforms.linux;
  };
}