From 17d2ff414d83095361c2070f1cdaf57c016af9c7 Mon Sep 17 00:00:00 2001
From: Yuri Aisaka <yuriaisaka@users.noreply.github.com>
Date: Fri, 5 May 2017 15:00:38 +0900
Subject: [PATCH] imagej: init at 150 (#25249)

* imagej: init at 150

* correcting for PR comments
---
 lib/maintainers.nix                           |  1 +
 pkgs/applications/graphics/imagej/default.nix | 48 +++++++++++++++++++
 pkgs/top-level/all-packages.nix               |  2 +
 3 files changed, 51 insertions(+)
 create mode 100644 pkgs/applications/graphics/imagej/default.nix

diff --git a/lib/maintainers.nix b/lib/maintainers.nix
index aca69cc85f2f..a477fb46b86a 100644
--- a/lib/maintainers.nix
+++ b/lib/maintainers.nix
@@ -575,6 +575,7 @@
   yarr = "Dmitry V. <savraz@gmail.com>";
   yochai = "Yochai <yochai@titat.info>";
   yorickvp = "Yorick van Pelt <yorickvanpelt@gmail.com>";
+  yuriaisaka = "Yuri Aisaka <yuri.aisaka+nix@gmail.com>";
   yurrriq = "Eric Bailey <eric@ericb.me>";
   z77z = "Marco Maggesi <maggesi@math.unifi.it>";
   zagy = "Christian Zagrodnick <cz@flyingcircus.io>";
diff --git a/pkgs/applications/graphics/imagej/default.nix b/pkgs/applications/graphics/imagej/default.nix
new file mode 100644
index 000000000000..673361c734e1
--- /dev/null
+++ b/pkgs/applications/graphics/imagej/default.nix
@@ -0,0 +1,48 @@
+{ stdenv, fetchurl, jre, unzip, makeWrapper }:
+
+# Note:
+# - User config dir is hard coded by upstream to $HOME/.imagej on linux systems
+#   and to $HOME/Library/Preferences on macOS.
+#  (The current trend appears to be to use $HOME/.config/imagej
+#    on linux systems, but we here do not attempt to fix it.)
+
+let
+  imagej150 = stdenv.mkDerivation rec {
+    name = "imagej-${version}";
+    version = "150";
+
+    src = fetchurl {
+      url = "http://wsr.imagej.net/distros/cross-platform/ij150.zip";
+      sha256 = "97aba6fc5eb908f5160243aebcdc4965726693cb1353d9c0d71b8f5dd832cb7b";
+    };
+    buildInputs = [ unzip makeWrapper ];
+    inherit jre;
+
+    # JAR files that are intended to be used by other packages
+    # should go to $out/share/java.
+    # (Some uses ij.jar as a library not as a standalone program.)
+    installPhase = ''
+      mkdir -p $out/share/java
+      # Read permisssion suffices for the jar and others.
+      # Simple cp shall clear suid bits, if any.
+      cp ij.jar $out/share/java
+      cp -dR luts macros plugins $out/share
+      mkdir $out/bin
+      makeWrapper ${jre}/bin/java $out/bin/imagej \
+        --add-flags "-jar $out/share/java/ij.jar -ijpath $out/share"
+    '';
+    meta = with stdenv.lib; {
+      homepage = https://imagej.nih.gov/ij/;
+      description = "Image processing and analysis in Java";
+      longDescription = ''
+        ImageJ is a public domain Java image processing program
+        inspired by NIH Image for the Macintosh.
+        It runs on any computer with a Java 1.4 or later virtual machine.
+      '';
+      license = licenses.publicDomain;
+      platforms = with platforms; linux ++ darwin;
+      maintainers = with maintainers; [ yuriaisaka ];
+    };
+  };
+in
+  imagej150
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 5b5af2587d26..de8d9fd05cba 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -14284,6 +14284,8 @@ with pkgs;
     inherit (perlPackages.override { pkgs = pkgs // { imagemagick = imagemagickBig;}; }) PerlMagick;
   };
 
+  imagej = callPackage ../applications/graphics/imagej { };
+
   imagemagick_light = imagemagick.override {
     bzip2 = null;
     zlib = null;