1{
2 lib,
3 writeTextFile,
4 runtimeShell,
5 drawio,
6 xvfb-run,
7}:
8
9writeTextFile {
10 name = "${drawio.pname}-headless-${drawio.version}";
11
12 executable = true;
13 destination = "/bin/drawio";
14 text = ''
15 #!${runtimeShell}
16
17 # Electron really wants a configuration directory to not die with:
18 # "Error: Failed to get 'appData' path"
19 # so we give it some temp dir as XDG_CONFIG_HOME
20 tmpdir=$(mktemp -d)
21
22 function cleanup {
23 rm -rf "$tmpdir"
24 }
25 trap cleanup EXIT
26
27 # Drawio needs to run in a virtual X session, because Electron
28 # refuses to work and dies with an unhelpful error message otherwise:
29 # "The futex facility returned an unexpected error code."
30 XDG_CONFIG_HOME="$tmpdir" ${xvfb-run}/bin/xvfb-run --auto-display ${drawio}/bin/drawio $@
31 '';
32
33 meta = with lib; {
34 description = "xvfb wrapper around drawio";
35 longDescription = ''
36 A wrapper around drawio (draw.io) for running in headless environments.
37 Runs drawio under xvfb-run, with configuration going to a temporary
38 directory.
39 '';
40 maintainers = with maintainers; [
41 qyliss
42 tfc
43 ];
44 mainProgram = "drawio";
45 };
46}