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