summary refs log tree commit diff
path: root/pkgs/tools/misc/pandoc-drawio-filter/default.nix
blob: 1279296143cc9e1a5cb33db3c1b868a25a1478b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{ buildPythonApplication
, drawio
, fetchFromGitHub
, lib
, pandoc
, pandocfilters
, runCommand
, runtimeShell
, texlive
, writeScriptBin
, xvfb-run
}:

let
  version = "1.1";

  src = fetchFromGitHub {
    owner = "tfc";
    repo = "pandoc-drawio-filter";
    rev = version;
    sha256 = "sha256-2XJSAfxqEmmamWIAM3vZqi0mZjUUugmR3zWw8Imjadk=";
  };

  wrappedDrawio = writeScriptBin "drawio" ''
    #!${runtimeShell}

    # Electron really wants a configuration directory to not die with:
    # "Error: Failed to get 'appData' path"
    # so we give it some temp dir as XDG_CONFIG_HOME
    tmpdir=$(mktemp -d)

    function cleanup {
      rm -rf "$tmpdir"
    }
    trap cleanup EXIT

    # Drawio needs to run in a virtual X session, because Electron
    # refuses to work and dies with an unhelpful error message otherwise:
    # "The futex facility returned an unexpected error code."
    XDG_CONFIG_HOME="$tmpdir" ${xvfb-run}/bin/xvfb-run ${drawio}/bin/drawio $@
  '';

  pandoc-drawio-filter = buildPythonApplication {
    pname = "pandoc-drawio-filter";

    inherit src version;

    propagatedBuildInputs = [
      wrappedDrawio
      pandocfilters
    ];

    passthru.tests.example-doc =
      let
        env = {
          nativeBuildInputs = [
            pandoc
            pandoc-drawio-filter
            texlive.combined.scheme-tetex
          ];
        };
      in
      runCommand "$pandoc-drawio-filter-example-doc.pdf" env ''
        cp -r ${src}/example/* .
        pandoc -F pandoc-drawio example.md -T pdf -o $out
      '';

    meta = with lib; {
      homepage = "https://github.com/tfc/pandoc-drawio-filter";
      description = "Pandoc filter which converts draw.io diagrams to PDF";
      license = licenses.mit;
      maintainers = with maintainers; [ tfc ];
    };
  };

in

pandoc-drawio-filter