hoarder: 0.21.0 -> 0.22.0
[NixPkgs.git] / pkgs / applications / misc / inochi2d / generic.nix
blob0a08ebbaae73df32f810a5d3aaae53632e9b69d3
2   lib,
3   buildDubPackage,
4   fetchFromGitHub,
5   writeShellScriptBin,
7   cmake,
8   gettext,
9   copyDesktopItems,
10   makeDesktopItem,
11   makeWrapper,
13   dbus,
14   freetype,
15   SDL2,
16   zenity,
17   luajit_2_1,
18   libGL,
20   builderArgs,
23 let
24   cimgui-src = fetchFromGitHub {
25     owner = "Inochi2D";
26     repo = "cimgui";
27     rev = "49bb5ce65f7d5eeab7861d8ffd5aa2a58ca8f08c";
28     hash = "sha256-XcnZbIjwq7vmYBnMAs+cEpJL8HB8wrL098FXGxC+diA=";
29     fetchSubmodules = true;
30   };
32   inherit (builderArgs)
33     pname
34     appname
35     version
36     dubLock
37     meta
38     ;
40 buildDubPackage (
41   builderArgs
42   // {
43     nativeBuildInputs = [
44       cmake # used for building `i2d-imgui`
45       gettext # used when generating translations
46       copyDesktopItems
47       makeWrapper
49       # A fake git implementation to be used by the `gitver` package
50       # It is a dependency of the main packages and the `inochi2d` dub dependency
51       # A side effect of this script is that `inochi2d` will have the same version listed as the main package
52       (writeShellScriptBin "git" "echo v${version}")
53     ];
55     buildInputs = [
56       dbus
57       freetype
58       SDL2
59     ];
61     dontUseCmakeConfigure = true;
63     # these deps are not listed inside `dub.sdl`, so they didn't get auto-generated
64     # these are used for generating version info when building
65     dubLock = lib.recursiveUpdate (lib.importJSON dubLock) {
66       dependencies = {
67         gitver = {
68           version = "1.6.1";
69           sha256 = "sha256-NCyFik4FbD7yMLd5zwf/w4cHwhzLhIRSVw1bWo/CZB4=";
70         };
71         semver = {
72           version = "0.3.2";
73           sha256 = "sha256-l6c9hniUd5xNsJepq8x30e0JTjmXs4pYUmv4ws+Nrn4=";
74         };
75       };
76     };
78     postConfigure = ''
79       cimgui_dir=("$DUB_HOME"/packages/i2d-imgui/*/i2d-imgui)
81       # `i2d-imgui` isn't able to find SDL2 by default due to it being written in lower case
82       # this is only an issue when compiling statically (session)
83       substituteInPlace "$cimgui_dir/dub.json" \
84           --replace-fail '"sdl2"' '"SDL2"'
86       # The `i2d-cimgui` dub dependency fetched inside the auto-generated `*-deps.nix` file
87       # which doesn't know that it's actually a git repo, so it doesn't fetch its submodules.
88       # Upstream uses a cmake script to fetch the `cimgui` submodule anyway, which we can't do
89       # We get around this by manually pre-fetching the submodule and copying it into the right place
90       cp -r --no-preserve=all ${cimgui-src}/* "$cimgui_dir/deps/cimgui"
92       # Disable the original cmake fetcher script
93       substituteInPlace "$cimgui_dir/deps/CMakeLists.txt" \
94           --replace-fail "PullSubmodules(" "# PullSubmodules(" \
95           --replace-fail  "\''${cimgui_SUBMOD_DIR}" "cimgui"
96     '';
98     preBuild = ''
99       # Generate translations (if possible)
100       . gentl.sh
102       # Use the fake git to generate version info
103       dub build --skip-registry=all --compiler=ldc2 --build=release --config=update-version
104     '';
106     # Use the "barebones" configuration so that we don't include the mascot and icon files in out build
107     dubFlags = [ "--config=barebones" ];
109     installPhase = ''
110       runHook preInstall
112       mkdir -p $out/share/${pname}
113       cp -r out/* $out/share/${pname}
115       runHook postInstall
116     '';
118     desktopItems = [
119       (makeDesktopItem {
120         name = pname;
121         desktopName = appname;
122         exec = pname;
123         comment = meta.description;
124         categories = [ "Utility" ];
125       })
126     ];
128     postFixup = ''
129       # Add support for `open file` dialog
130       makeWrapper $out/share/${pname}/${pname} $out/bin/${pname} \
131           --prefix PATH : ${lib.makeBinPath [ zenity ]} \
132           --prefix LD_LIBRARY_PATH : ${
133             lib.makeLibraryPath [
134               libGL
135               luajit_2_1
136             ]
137           }
138     '';
140     meta = {
141       homepage = "https://inochi2d.com/";
142       license = lib.licenses.bsd2;
143       mainProgram = pname;
144       maintainers = with lib.maintainers; [ tomasajt ];
145     } // meta;
146   }