1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchYarnDeps,
6 makeDesktopItem,
7 copyDesktopItems,
8 fixup-yarn-lock,
9 makeWrapper,
10 autoSignDarwinBinariesHook,
11 nodejs,
12 yarn,
13 electron,
14}:
15
16stdenv.mkDerivation rec {
17 pname = "drawio";
18 version = "26.1.1";
19
20 src = fetchFromGitHub {
21 owner = "jgraph";
22 repo = "drawio-desktop";
23 rev = "v${version}";
24 fetchSubmodules = true;
25 hash = "sha256-h9APkOtH7s31r89hqqH12zYqkVMrR2ZxMyc+Zwq21+A=";
26 };
27
28 # `@electron/fuses` tries to run `codesign` and fails. Disable and use autoSignDarwinBinariesHook instead
29 postPatch = ''
30 sed -i -e 's/resetAdHocDarwinSignature:.*/resetAdHocDarwinSignature: false,/' build/fuses.cjs
31 '';
32
33 offlineCache = fetchYarnDeps {
34 yarnLock = src + "/yarn.lock";
35 hash = "sha256-kmA0z/vmWH+yD2OQ6VVSE0yPxInTAGjjG+QfcoZHlQ0=";
36 };
37
38 nativeBuildInputs = [
39 fixup-yarn-lock
40 makeWrapper
41 nodejs
42 yarn
43 ]
44 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
45 copyDesktopItems
46 ]
47 ++ lib.optionals stdenv.hostPlatform.isDarwin [
48 autoSignDarwinBinariesHook
49 ];
50
51 ELECTRON_SKIP_BINARY_DOWNLOAD = true;
52
53 configurePhase = ''
54 runHook preConfigure
55
56 export HOME="$TMPDIR"
57 yarn config --offline set yarn-offline-mirror "$offlineCache"
58 fixup-yarn-lock yarn.lock
59 # Ensure that the node_modules folder is created by yarn install.
60 # See https://github.com/yarnpkg/yarn/issues/5500#issuecomment-1221456246
61 echo "nodeLinker: node-modules" > .yarnrc.yml
62 yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
63 patchShebangs node_modules/
64
65 runHook postConfigure
66 '';
67
68 buildPhase = ''
69 runHook preBuild
70
71 ''
72 + lib.optionalString stdenv.hostPlatform.isDarwin ''
73 cp -R ${electron.dist}/Electron.app Electron.app
74 chmod -R u+w Electron.app
75 export CSC_IDENTITY_AUTO_DISCOVERY=false
76 sed -i "/afterSign/d" electron-builder-linux-mac.json
77 ''
78 + ''
79 yarn --offline run electron-builder --dir \
80 ${lib.optionalString stdenv.hostPlatform.isDarwin "--config electron-builder-linux-mac.json"} \
81 -c.electronDist=${if stdenv.hostPlatform.isDarwin then "." else electron.dist} \
82 -c.electronVersion=${electron.version}
83
84 runHook postBuild
85 '';
86
87 installPhase = ''
88 runHook preInstall
89
90 ''
91 + lib.optionalString stdenv.hostPlatform.isDarwin ''
92 mkdir -p $out/{Applications,bin}
93 mv dist/mac*/draw.io.app $out/Applications
94
95 # Symlinking `draw.io` doesn't work; seems to look for files in the wrong place.
96 makeWrapper $out/Applications/draw.io.app/Contents/MacOS/draw.io $out/bin/drawio
97 ''
98 + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
99 mkdir -p "$out/share/lib/drawio"
100 cp -r dist/*-unpacked/{locales,resources{,.pak}} "$out/share/lib/drawio"
101
102 install -Dm644 build/icon.svg "$out/share/icons/hicolor/scalable/apps/drawio.svg"
103
104 makeWrapper '${electron}/bin/electron' "$out/bin/drawio" \
105 --add-flags "$out/share/lib/drawio/resources/app.asar" \
106 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \
107 --inherit-argv0
108 ''
109 + ''
110
111 runHook postInstall
112 '';
113
114 desktopItems = [
115 (makeDesktopItem {
116 name = "drawio";
117 exec = "drawio %U";
118 icon = "drawio";
119 desktopName = "drawio";
120 comment = "draw.io desktop";
121 mimeTypes = [
122 "application/vnd.jgraph.mxfile"
123 "application/vnd.visio"
124 ];
125 categories = [ "Graphics" ];
126 startupWMClass = "draw.io";
127 })
128 ];
129
130 meta = {
131 description = "Desktop version of draw.io for creating diagrams";
132 homepage = "https://about.draw.io/";
133 license = with lib.licenses; [
134 # The LICENSE file of https://github.com/jgraph/drawio claims Apache License Version 2.0 again since https://github.com/jgraph/drawio/commit/5b2e73471e4fea83d681f0cec5d1aaf7c3884996
135 asl20
136 # But the README says:
137 # The minified code authored by us in this repo is licensed under an Apache v2 license, but the sources to build those files are not in this repo. This is not an open source project.
138 unfreeRedistributable
139 ];
140 changelog = "https://github.com/jgraph/drawio-desktop/releases/tag/v${version}";
141 maintainers = with lib.maintainers; [ darkonion0 ];
142 platforms = lib.platforms.darwin ++ lib.platforms.linux;
143 mainProgram = "drawio";
144 };
145}