add d2plugin-tala

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-13 14:18:53 +03:00
parent f53eabdbf6
commit 95f061b96b
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
4 changed files with 162 additions and 26 deletions

View file

@ -1,2 +1,80 @@
# tools
This repository contains latest version of useful utilities with patches that
not included in official repositories.
# Usage
## As package
```sh
nix build git+https://git.pleshevski.ru/mynix/tools#<name>
```
## As one-time executable application
```sh
nix run git+https://git.pleshevski.ru/mynix/tools#<name>
```
## Using nix-profile
```sh
nix profile install git+https://git.pleshevski.ru/mynix/tools#<name>
```
## As overlay for your flake
```
{
inputs.tools.url = "git+https://git.pleshevski.ru/mynix/tools";
outputs = { nixpkgs, tools }:
let
system = builtins.currentSystem;
overlays = [ tools.overlays.all ];
pkgs = import nixpkgs { inherit system overlays; };
in
{
devShells = {
default = pkgs.mkShell {
# now you can use any tools
packages = with pkgs; [ d2 ];
};
};
};
}
```
> **Note**: For short this url (`git+https://git.pleshevski.ru/mynix/tools`)
will be truncated to `.` in the document.
# d2
_D2 is a modern diagram scripting language that turns text to diagrams._
References:
- [https://d2lang.com](https://d2lang.com)
- [https://github.com/terrastruct/d2](https://github.com/terrastruct/d2)
**d2**: Base d2 cli tool
```
nix run .#d2 -- --help
```
**[UNFREE]** **d2full**: Full d2 cli tool with d2plugin-tala
```
NIXPKGS_ALLOW_UNFREE=1 nix run --impure .#d2full -- --help
```
**[UNFREE]** **d2plugin-tala**: A diagram layout engine designed specifically for software
architecture diagrams
```
NIXPKGS_ALLOW_UNFREE=1 nix run --impure .#d2full -- --help
```

View file

@ -7,13 +7,17 @@
let
inherit (builtins) listToAttrs mapAttrs;
mkPackage = pkgs: name: pkgs.callPackage ./pkgs/${name}.nix { };
mkPackage = pkgs': name:
pkgs'.callPackage ./pkgs/${name}.nix (
if name == "d2" then { d2plugin-tala = mkPackage pkgs' "d2plugin-tala"; }
else { }
);
mkApp = drv: flake-utils.lib.mkApp { inherit drv; };
mkOverlay = name:
final: prev:
final.setAttrByPath [ name ] (mkPackage name prev);
allPackageNames = [ "d2" ];
allPackageNames = [ "d2" "d2plugin-tala" ];
mkAllPackages = pkgs':
listToAttrs
(map
@ -33,7 +37,10 @@
// flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
packages = mkAllPackages pkgs;
basePackages = mkAllPackages pkgs;
packages = with basePackages; {
d2full = d2.override { withTala = true; };
} // basePackages;
in
{
check = packages;

View file

@ -1,37 +1,52 @@
{ lib
, buildGoModule
, makeWrapper
, symlinkJoin
, fetchFromGitHub
, installShellFiles
, d2plugin-tala
, withTala ? false
}:
let version = "2022-12-12"; in
let
version = "2022-12-12";
d2 = buildGoModule
{
pname = "d2";
inherit version;
buildGoModule {
pname = "d2";
inherit version;
src = fetchFromGitHub {
owner = "terrastruct";
repo = "d2";
rev = "a557d1a6edeb18d692c1e1c20c3c0f0cffc2ed21";
sha256 = "sha256-EzaBURGLnxSX+1FjYQLP7oxov7dGk7xhAnpV8DPzW/g=";
};
src = fetchFromGitHub {
owner = "terrastruct";
repo = "d2";
rev = "a557d1a6edeb18d692c1e1c20c3c0f0cffc2ed21";
sha256 = "sha256-EzaBURGLnxSX+1FjYQLP7oxov7dGk7xhAnpV8DPzW/g=";
};
vendorSha256 = "sha256-p0os+ap2k5nYWI4+Hf4pwJfHTXaPJldJmf6nznhuRFA=";
vendorSha256 = "sha256-p0os+ap2k5nYWI4+Hf4pwJfHTXaPJldJmf6nznhuRFA=";
ldflags = [
"-s"
"-w"
"-X oss.terrastruct.com/d2/lib/version.Version=${version}"
];
ldflags = [
"-s"
"-w"
"-X oss.terrastruct.com/d2/lib/version.Version=${version}"
];
nativeBuildInputs = [ installShellFiles ];
nativeBuildInputs = [ installShellFiles ];
patches = [
../patches/d2/402_preserve_leading_comment_spacing.patch
];
patches = [
../patches/d2/402_preserve_leading_comment_spacing.patch
];
postInstall = "installManPage ci/release/template/man/d2.1";
postInstall = "installManPage ci/release/template/man/d2.1";
subPackages = [ "." ];
subPackages = [ "." ];
};
in
symlinkJoin {
name = "d2";
paths = [ d2 ] ++ lib.optional withTala [ d2plugin-tala ];
buildInputs = [ makeWrapper ];
postBuild = ''
wrapProgram $out/bin/d2 \
--prefix PATH : "$out/bin"
'';
}

36
pkgs/d2plugin-tala.nix Normal file
View file

@ -0,0 +1,36 @@
{ system, stdenv, lib, fetchurl, installShellFiles }:
let
platform = if stdenv.isLinux then "linux" else "darwin";
arch = if lib.hasPrefix "x86_" system then "amd64" else "arm64";
version = "0.2.7";
fileName = "tala-v${version}-${platform}-${arch}.tar.gz";
in
stdenv.mkDerivation {
pname = "d2plugin-tala";
inherit version;
src = fetchurl {
url = "https://github.com/terrastruct/TALA/releases/download/v${version}/${fileName}";
sha256 = "sha256-p6nXOcveZ28Q1ODpbV9dVrGTtoXgxkFdsiXY61BK0dA=";
};
nativeBuildInputs = [ installShellFiles ];
phases = [ "unpackPhase" "installPhase" ];
unpackPhase = "tar --strip-component=1 -xf $src";
installPhase = ''
mkdir -p $out/bin
cp bin/d2plugin-tala $out/bin
installManPage man/d2plugin-tala.1
installManPage man/tala.1
'';
meta = with lib; {
description = "A diagram layout engine designed specifically for software architecture diagrams";
homepage = "https://terrastruct.com/tala";
license = licenses.unfree;
};
}