commit 2c1bf5444eaa935d5f0cc1d4043b21cb107cb960 Author: Dmitriy Pleshevskiy Date: Mon Dec 12 14:32:40 2022 +0300 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a479d7c --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# direnv +.envrc +.direnv + +# test d2 +*.d2 + +# generated by d2 +*.svg + +# built +result/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..00a4423 --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# *W*rapped _d2_ + +A wrapper over [d2] which allows to use \`layout\`, \`theme\`, \`pad\` +attributes from d2 file. All arguments will be passed to the d2 cli, but these +additional configs overwrite cli arguments with the same name. + +[d2]: https://github.com/terrastruct/d2 + +# Install + +## Nix Flake + +This repo is also packaged via Nix flakes, the language server binary package is +available through the default flake output `github:pleshevskiy/wd2` with the +path `bin/wd2`. + +You can enable flakes support in your nix configuration, and then run nix +profile install `github:pleshevskiy/wd2` to get `wd2` installed. You can also +use this repository as a flake input and add its output to your own +flake-managed systemwide or home configuration. + +## Other + +Copy `wd2` script to `/usr/local/bin` folder. + +# Usage + +Create a d2 file with additional configs at the top. + +```d2 +# layout: elk +# theme: 101 +# pad: 5 + +x -> y -> z +``` + +Then run the `wd2` script + +```sh +wd2 -w path/to/your/file.d2 +``` diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..caeb73f --- /dev/null +++ b/flake.lock @@ -0,0 +1,90 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1670827406, + "narHash": "sha256-nLNk7uiLbhbvb4TVz67XK7+Ezr1zcWYDWmNrWGmEUqA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ffca9ffaaafb38c8979068cee98b2644bd3f14cb", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1669261230, + "narHash": "sha256-AjddxRPd5y5jge77281P3O8+Cnafj842Xg59rwV4x+0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8e8b5f3b1e899bf5d250279578c0283705b8cdb4", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "tools": "tools" + } + }, + "tools": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1670842919, + "narHash": "sha256-4SpFhzzGGg7yppVCZvx0rDdVScXc/m6rZe4BYnNoOQ4=", + "ref": "refs/heads/main", + "rev": "79301872e58bf199118ba163d95f54e6fbefcd75", + "revCount": 11, + "type": "git", + "url": "https://git.pleshevski.ru/mynix/tools" + }, + "original": { + "type": "git", + "url": "https://git.pleshevski.ru/mynix/tools" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..4db28f1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,47 @@ +{ + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + tools.url = "git+https://git.pleshevski.ru/mynix/tools"; + }; + + outputs = { self, nixpkgs, flake-utils, tools, ... }: + let + inherit (builtins) readFile; + + mkWd2 = { writeShellApplication, symlinkJoin, d2, ... }: + writeShellApplication { + name = "wd2"; + runtimeInputs = [ d2 ]; + text = (readFile ./wd2); + }; + in + { + overlays = { + default = final: prev: { + wd2 = prev.callPackage mkWd2 { }; + }; + }; + } // + flake-utils.lib.eachDefaultSystem (system: + let + inherit (builtins) mapAttrs; + pkgs = import nixpkgs { inherit system; }; + + wd2 = pkgs.callPackage mkWd2 { + d2 = tools.packages.${system}.d2; + }; + + mkApp = drv: flake-utils.lib.mkApp { inherit drv; }; + packages = { + inherit wd2; + default = wd2; + }; + in + { + check = packages; + + inherit packages; + + apps = mapAttrs (name: mkApp) packages; + }); +} diff --git a/result b/result new file mode 120000 index 0000000..ccb5057 --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/paxh7dav8nq2s5lvijq192kz3p7jhgas-wd2 \ No newline at end of file diff --git a/wd2 b/wd2 new file mode 100755 index 0000000..c7a2965 --- /dev/null +++ b/wd2 @@ -0,0 +1,69 @@ +#! /usr/bin/env bash + +d2_args=( ) +d2_input_file= + +function print_help() { + cat <