about summary refs log tree commit diff
path: root/pkgs/applications/misc/inochi2d/generic.nix
blob: 769b44204420cd9aa8038fb5a3f723bcff7d7d0d (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
  lib,
  buildDubPackage,
  fetchFromGitHub,
  writeShellScriptBin,

  cmake,
  gettext,
  copyDesktopItems,
  makeDesktopItem,
  makeWrapper,

  dbus,
  freetype,
  SDL2,
  zenity,

  builderArgs,
}:

let
  cimgui-src = fetchFromGitHub {
    owner = "Inochi2D";
    repo = "cimgui";
    rev = "49bb5ce65f7d5eeab7861d8ffd5aa2a58ca8f08c";
    hash = "sha256-XcnZbIjwq7vmYBnMAs+cEpJL8HB8wrL098FXGxC+diA=";
    fetchSubmodules = true;
  };

  inherit (builderArgs)
    pname
    appname
    version
    dubLock
    meta
    ;
in
buildDubPackage (
  builderArgs
  // {
    nativeBuildInputs = [
      cmake # used for building `i2d-imgui`
      gettext # used when generating translations
      copyDesktopItems
      makeWrapper

      # A fake git implementation to be used by the `gitver` package
      # It is a dependency of the main packages and the `inochi2d` dub dependency
      # A side effect of this script is that `inochi2d` will have the same version listed as the main package
      (writeShellScriptBin "git" "echo v${version}")
    ];

    buildInputs = [
      dbus
      freetype
      SDL2
    ];

    dontUseCmakeConfigure = true;

    # these deps are not listed inside `dub.sdl`, so they didn't get auto-generated
    # these are used for generating version info when building
    dubLock = lib.recursiveUpdate (lib.importJSON dubLock) {
      dependencies = {
        gitver = {
          version = "1.6.1";
          sha256 = "sha256-NCyFik4FbD7yMLd5zwf/w4cHwhzLhIRSVw1bWo/CZB4=";
        };
        semver = {
          version = "0.3.2";
          sha256 = "sha256-l6c9hniUd5xNsJepq8x30e0JTjmXs4pYUmv4ws+Nrn4=";
        };
      };
    };

    postConfigure = ''
      cimgui_dir=("$DUB_HOME"/packages/i2d-imgui/*/i2d-imgui)

      # `i2d-imgui` isn't able to find SDL2 by default due to it being written in lower case
      # this is only an issue when compiling statically (session)
      substituteInPlace "$cimgui_dir/dub.json" \
          --replace-fail '"sdl2"' '"SDL2"'

      # The `i2d-cimgui` dub dependency fetched inside the auto-generated `*-deps.nix` file
      # which doesn't know that it's actually a git repo, so it doesn't fetch its submodules.
      # Upstream uses a cmake script to fetch the `cimgui` submodule anyway, which we can't do
      # We get around this by manually pre-fetching the submodule and copying it into the right place
      cp -r --no-preserve=all ${cimgui-src}/* "$cimgui_dir/deps/cimgui"

      # Disable the original cmake fetcher script
      substituteInPlace "$cimgui_dir/deps/CMakeLists.txt" \
          --replace-fail "PullSubmodules(" "# PullSubmodules(" \
          --replace-fail  "\''${cimgui_SUBMOD_DIR}" "cimgui"
    '';

    preBuild = ''
      # Generate translations (if possible)
      . gentl.sh

      # Use the fake git to generate version info
      dub build --skip-registry=all --compiler=ldc2 --build=release --config=meta
    '';

    # Use the "barebones" configuration so that we don't include the mascot and icon files in out build
    dubFlags = [ "--config=barebones" ];

    installPhase = ''
      runHook preInstall

      mkdir -p $out/share/${pname}
      cp -r out/* $out/share/${pname}

      runHook postInstall
    '';

    desktopItems = [
      (makeDesktopItem {
        name = pname;
        desktopName = appname;
        exec = pname;
        comment = meta.description;
        categories = [ "Utility" ];
      })
    ];

    postFixup = ''
      # Add support for `open file` dialog
      makeWrapper $out/share/${pname}/${pname} $out/bin/${pname} \
          --prefix PATH : ${lib.makeBinPath [ zenity ]}
    '';

    meta = {
      homepage = "https://inochi2d.com/";
      license = lib.licenses.bsd2;
      mainProgram = pname;
      maintainers = with lib.maintainers; [ tomasajt ];
    } // meta;
  }
)