drawio: build from source

This allows using drawio on other architectures, and on Darwin.
The implementation is adapted from the podman-desktop package.
This commit is contained in:
Alyssa Ross 2023-04-29 11:46:11 +00:00
parent 4cf4f33e33
commit 007907fc50

View file

@ -1,104 +1,103 @@
{ stdenv, lib, fetchurl, rpmextract, autoPatchelfHook, wrapGAppsHook { lib
, stdenv
# Dynamic libraries , fetchFromGitHub
, alsa-lib, atk, at-spi2-atk, at-spi2-core, cairo, dbus, cups, expat , fetchYarnDeps
, gdk-pixbuf, glib, gtk3, libX11, libXScrnSaver, libXcomposite, libXcursor , makeDesktopItem
, libXdamage, libXext, libXfixes, libXi, libXrandr, libXrender, libXtst , copyDesktopItems
, libxcb, libuuid, libxshmfence, nspr, nss, pango, mesa , desktopToDarwinBundle
, fixup_yarn_lock
, systemd , makeWrapper
, nodejs
, yarn
, electron
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "drawio"; pname = "drawio";
version = "21.2.1"; version = "21.2.1";
src = fetchurl { src = fetchFromGitHub {
url = "https://github.com/jgraph/drawio-desktop/releases/download/v${version}/drawio-x86_64-${version}.rpm"; owner = "jgraph";
sha256 = "sha256-269kMXKGlGig4Dt7cvCTRDGFsBZE5RBoi1ajqT3rIVc="; repo = "drawio-desktop";
rev = "v${version}";
fetchSubmodules = true;
hash = "sha256-sjJZwVQdFAMWdaGUyQbv1qfdJWE2tN90z7eFYyAW9ko=";
};
offlineCache = fetchYarnDeps {
yarnLock = src + "/yarn.lock";
hash = "sha256-YlJ84psoEgeDnCX+O8TvwqhTthm5voJ6dfTvTiZlkuk=";
}; };
nativeBuildInputs = [ nativeBuildInputs = [
autoPatchelfHook copyDesktopItems
rpmextract fixup_yarn_lock
wrapGAppsHook makeWrapper
]; nodejs
yarn
] ++ lib.optional stdenv.isDarwin desktopToDarwinBundle;
buildInputs = [ ELECTRON_SKIP_BINARY_DOWNLOAD = true;
alsa-lib
atk
at-spi2-atk
at-spi2-core
cairo
cups
dbus
expat
gdk-pixbuf
glib
gtk3
libX11
libXScrnSaver
libXcomposite
libXcursor
libXdamage
libXext
libXfixes
libXi
libXrandr
libXrender
libxshmfence
libXtst
libxcb
libuuid
mesa # for libgbm
nspr
nss
pango
systemd
];
runtimeDependencies = [ configurePhase = ''
(lib.getLib systemd) runHook preConfigure
];
dontBuild = true; export HOME="$TMPDIR"
dontConfigure = true; yarn config --offline set yarn-offline-mirror "$offlineCache"
fixup_yarn_lock yarn.lock
yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
patchShebangs node_modules/
unpackPhase = "rpmextract ${src}"; runHook postConfigure
'';
buildPhase = ''
runHook preBuild
yarn --offline run electron-builder --dir \
--config electron-builder-linux-mac.json \
-c.electronDist=${electron}/lib/electron \
-c.electronVersion=${electron.version}
runHook postBuild
'';
installPhase = '' installPhase = ''
mkdir -p $out/share runHook preInstall
cp -r opt/drawio $out/share/
# Application icon mkdir -p "$out/share/lib/drawio"
mkdir -p $out/share/icons/hicolor cp -r dist/*-unpacked/{locales,resources{,.pak}} "$out/share/lib/drawio"
cp -r usr/share/icons/hicolor/* $out/share/icons/hicolor/
# XDG desktop item install -Dm644 build/icon.svg "$out/share/icons/hicolor/scalable/apps/drawio.svg"
cp -r usr/share/applications $out/share/applications
# Symlink wrapper makeWrapper '${electron}/bin/electron' "$out/bin/drawio" \
mkdir -p $out/bin --add-flags "$out/share/lib/drawio/resources/app.asar" \
ln -s $out/share/drawio/drawio $out/bin/drawio --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
--inherit-argv0
# Update binary path runHook postInstall
substituteInPlace $out/share/applications/drawio.desktop \
--replace /opt/drawio/drawio $out/bin/drawio
''; '';
doInstallCheckPhase = true; desktopItems = [
(makeDesktopItem {
installCheckPhase = '' name = "drawio";
$out/bin/drawio --help > /dev/null exec = "drawio %U";
''; icon = "drawio";
desktopName = "drawio";
comment = "draw.io desktop";
mimeTypes = [ "application/vnd.jgraph.mxfile" "application/vnd.visio" ];
categories = [ "Graphics" ];
startupWMClass = "drawio";
})
];
meta = with lib; { meta = with lib; {
description = "A desktop application for creating diagrams"; description = "A desktop application for creating diagrams";
homepage = "https://about.draw.io/"; homepage = "https://about.draw.io/";
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
license = licenses.asl20; license = licenses.asl20;
changelog = "https://github.com/jgraph/drawio-desktop/releases/tag/v${version}"; changelog = "https://github.com/jgraph/drawio-desktop/releases/tag/v${version}";
maintainers = with maintainers; [ darkonion0 ]; maintainers = with maintainers; [ qyliss darkonion0 ];
platforms = [ "x86_64-linux" ]; platforms = platforms.darwin ++ platforms.linux;
broken = stdenv.isDarwin;
}; };
} }