about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/misc/plantuml/plantuml-c4.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-06-16 06:56:35 +0000
committerAlyssa Ross <hi@alyssa.is>2023-06-16 06:56:35 +0000
commit99fcaeccb89621dd492203ce1f2d551c06f228ed (patch)
tree41cb730ae07383004789779b0f6e11cb3f4642a3 /nixpkgs/pkgs/tools/misc/plantuml/plantuml-c4.nix
parent59c5f5ac8682acc13bb22bc29c7cf02f7d75f01f (diff)
parent75a5ebf473cd60148ba9aec0d219f72e5cf52519 (diff)
downloadnixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.gz
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.bz2
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.lz
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.xz
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.zst
nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.zip
Merge branch 'nixos-unstable' of https://github.com/NixOS/nixpkgs
Conflicts:
	nixpkgs/nixos/modules/config/console.nix
	nixpkgs/nixos/modules/services/mail/mailman.nix
	nixpkgs/nixos/modules/services/mail/public-inbox.nix
	nixpkgs/nixos/modules/services/mail/rss2email.nix
	nixpkgs/nixos/modules/services/networking/ssh/sshd.nix
	nixpkgs/pkgs/applications/networking/instant-messengers/dino/default.nix
	nixpkgs/pkgs/applications/networking/irc/weechat/default.nix
	nixpkgs/pkgs/applications/window-managers/sway/default.nix
	nixpkgs/pkgs/build-support/go/module.nix
	nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix
	nixpkgs/pkgs/development/interpreters/python/default.nix
	nixpkgs/pkgs/development/node-packages/overrides.nix
	nixpkgs/pkgs/development/tools/b4/default.nix
	nixpkgs/pkgs/servers/dict/dictd-db.nix
	nixpkgs/pkgs/servers/mail/public-inbox/default.nix
	nixpkgs/pkgs/tools/security/pinentry/default.nix
	nixpkgs/pkgs/tools/text/unoconv/default.nix
	nixpkgs/pkgs/top-level/all-packages.nix
Diffstat (limited to 'nixpkgs/pkgs/tools/misc/plantuml/plantuml-c4.nix')
-rw-r--r--nixpkgs/pkgs/tools/misc/plantuml/plantuml-c4.nix73
1 files changed, 73 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/tools/misc/plantuml/plantuml-c4.nix b/nixpkgs/pkgs/tools/misc/plantuml/plantuml-c4.nix
new file mode 100644
index 000000000000..a8d0001054fd
--- /dev/null
+++ b/nixpkgs/pkgs/tools/misc/plantuml/plantuml-c4.nix
@@ -0,0 +1,73 @@
+{ lib, stdenv, makeWrapper, fetchzip, runCommand, plantuml, plantuml-c4, jre }:
+
+# The C4-PlantUML docs say that it suffices to run plantuml with the
+# -DRELATIVE_INCLUDE="..." arg to make plantuml find the C4 templates
+# when included like "!include C4_Container.puml".
+# Unfortunately, this is not sufficient in practise, when the path is not ".".
+# What helps is setting -Dplantuml.include.path="..." *before* the jar
+# parameter.
+# The -DRELATIVE_INCLUDE param then *still* needs to be set (*after* the jar
+# argument), because the C4 template vars check for existence of this variable
+# and if it is not set, reference paths in the internet.
+
+let
+  c4-lib = fetchzip {
+    url = "https://github.com/plantuml-stdlib/C4-PlantUML/archive/88a3f99150c6ff7953c4a99b184d03412ffdedb1.zip";
+    sha256 = "sha256-vk4YWdGb47OsI9mApGTQ7OfELRZdBouzKfUZq3kchcM=";
+  };
+
+  sprites = fetchzip {
+    url = "https://github.com/tupadr3/plantuml-icon-font-sprites/archive/fa3f885dbd45c9cd0cdf6c0e5e4fb51ec8b76582.zip";
+    sha256 = "sha256-lt9+NNMIaZSkKNsGyHoqXUCTlKmZFGfNYYGjer6X0Xc=";
+  };
+
+  # In order to pre-fix the plantuml.jar parameter with the argument
+  # -Dplantuml.include.path=..., we post-fix the java command using a wrapper.
+  # This way the plantuml derivation can remain unchanged.
+  plantumlWithExtraPath =
+    let
+      plantumlIncludePath = lib.concatStringsSep ":" [ c4-lib sprites ];
+      includeFlag = "-Dplantuml.include.path=${lib.escapeShellArg plantumlIncludePath}";
+      postFixedJre =
+        runCommand "jre-postfixed" { nativeBuildInputs = [ makeWrapper ]; } ''
+          mkdir -p $out/bin
+
+          makeWrapper ${jre}/bin/java $out/bin/java \
+            --add-flags ${lib.escapeShellArg includeFlag}
+        '';
+    in
+    plantuml.override { jre = postFixedJre; };
+in
+
+stdenv.mkDerivation rec {
+  pname = "plantuml-c4";
+  version = "unstable-2022-08-21";
+
+  nativeBuildInputs = [ makeWrapper ];
+
+  buildCommand = ''
+    mkdir -p $out/bin
+
+    makeWrapper ${plantumlWithExtraPath}/bin/plantuml $out/bin/plantuml \
+      --add-flags "-DRELATIVE_INCLUDE=\"${c4-lib}\""
+
+    $out/bin/plantuml -help
+  '';
+
+  passthru.tests.example-c4-diagram =
+    runCommand "c4-plantuml-sample.png" { nativeBuildInputs = [ plantuml-c4 ]; } ''
+      sed 's/https:.*\///' "${c4-lib}/samples/C4_Context Diagram Sample - enterprise.puml" > sample.puml
+      plantuml sample.puml -o $out
+
+      sed 's/!include ..\//!include /' ${sprites}/examples/complex-example.puml > sprites.puml
+      plantuml sprites.puml -o $out
+    '';
+
+  meta = with lib; {
+    description = "PlantUML bundled with C4-Plantuml and plantuml sprites library";
+    homepage = "https://github.com/plantuml-stdlib/C4-PlantUML";
+    license = licenses.mit;
+    maintainers = with maintainers; [ tfc ];
+    platforms = platforms.unix;
+  };
+}