Nixpkgs: Package request: Mermaid and mmdc

Created on 22 Apr 2019  路  7Comments  路  Source: NixOS/nixpkgs

Mermaid generates diagrams and flowcharts from text in a similar manner as markdown. Typically the required component is mmdc, which is the binary that generates images from the markup representation.

GitLab natively generates Mermaid diagrams. Emacs has a mode for it that supports local rendering. Support for GitHub does not exist yet but is highly demanded and is seeing some upstream support. Being able to install it on NixOS would be useful.

nodejs

Most helpful comment

Took another shot to include it in nixpkgs here: #87766. It works well on MacOS with the test file I used.

All 7 comments

I'd be tempted to add it to nodePackages (see https://www.npmjs.com/package/mermaid), but my last attempted contribution has been stuck in purgatory for _four months_, so I'm not exactly eager to try it until that one is resolved.

@matthew-piziak I became interested in having mermaid as well

@matthew-piziak I was able to build mermaid.cli off-tree.

Create a node-packages.json (do that preferably in separate directory called mermaid):

[
    "mermaid",
    "mermaid.cli"
]

Run nix-shell -p nodePackages.node2nix --nodejs10 -i node-packages.json to generate default.nix, node-packages.nix and node-env.nix.

Then create a wrapper package:

  nixpkgs = ...;
  mermaidCli = (import ./mermaid/default.nix { pkgs = nixpkgs; })."mermaid.cli";
in mermaidCli.overrideAttrs (sup: {
            nativeBuildInputs = sup.nativeBuildInputs or [] ++ [
                nixpkgs.makeWrapper nixpkgs.which
            ];

            PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = 1;

            nixpkgsChromePuppeteerConfig = nixpkgs.writeText "puppeteerConfig.json" ''
                { "executablePath": "${nixpkgs.chromium}/bin/chromium" }
            '';

            postInstall = sup.postInstall or "" + ''
                mv $out/bin/mmdc $out/bin/mmdc-script
                NODE=$(readlink -f $(which node))
                cat > $out/bin/mmdc <<EOF
                #!/usr/bin/env bash
                exec $NODE $out/bin/mmdc-script -p $nixpkgsChromePuppeteerConfig "\$@"
                EOF
                chmod +x $out/bin/mmdc
            '';
});

This was enough to work with asciidoctor-diagrams.

Hm. I get error: attribute 'nodejs-8_x' missing in mermaid/default.nix when I try this. That's despite passing --nodejs10. But manually changing 8 to 10 makes it work; I have mmdc now. Thank you!

This started failing for me with request to http://www.example.com/chalk failed, reason: getaddrinfo ENOTFOUND www.example.com www.example.com:80 so I removed it from my config.

Took another shot to include it in nixpkgs here: #87766. It works well on MacOS with the test file I used.

Resolved via #87766.

Was this page helpful?
0 / 5 - 0 ratings