From 09b7444b82827acbd89970997ebc11b5e59558e6 Mon Sep 17 00:00:00 2001 From: Rocky Breslow <1774125+rbreslow@users.noreply.github.com> Date: Wed, 23 Mar 2022 13:38:03 -0400 Subject: [PATCH 1/3] dcm2niix: add support for configuring optional compile-time modules Right now, the dcm2niix package produces a single binary without support for dcm2niibatch, JPEG-LS, OpenJPEG, or an alternative zlib library. The official build process for dcm2niix configures all these options (minus batch support). I was motivated to make these changes so my organization could process JPEG 2000 imagery using the Nix binary. --- .../science/biology/dcm2niix/default.nix | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/science/biology/dcm2niix/default.nix b/pkgs/applications/science/biology/dcm2niix/default.nix index 36dddad5db5a..663e438d93f3 100644 --- a/pkgs/applications/science/biology/dcm2niix/default.nix +++ b/pkgs/applications/science/biology/dcm2niix/default.nix @@ -1,8 +1,15 @@ -{ lib, stdenv +{ lib +, stdenv , fetchFromGitHub , cmake -, libyamlcpp , git +, openjpeg +, libyamlcpp +, zlib +, batchVersion ? false +, withJpegLs ? true +, withOpenJpeg ? true +, withSystemZlib ? true }: stdenv.mkDerivation rec { @@ -17,7 +24,21 @@ stdenv.mkDerivation rec { }; nativeBuildInputs = [ cmake git ]; - buildInputs = [ libyamlcpp ]; + buildInputs = lib.optionals batchVersion [ libyamlcpp ] + ++ lib.optionals withOpenJpeg [ openjpeg openjpeg.dev ] + ++ lib.optionals withSystemZlib [ zlib ]; + + cmakeFlags = lib.optionals batchVersion [ + "-DBATCH_VERSION=ON" + "-DYAML-CPP_DIR=${libyamlcpp}/lib/cmake/yaml-cpp" + ] ++ lib.optionals withJpegLs [ + "-DUSE_JPEGLS=ON" + ] ++ lib.optionals withOpenJpeg [ + "-DUSE_OPENJPEG=ON" + "-DOpenJPEG_DIR=${openjpeg}/lib/${openjpeg.pname}-${lib.versions.majorMinor openjpeg.version}" + ] ++ lib.optionals withSystemZlib [ + "-DZLIB_IMPLEMENTATION=System" + ]; meta = with lib; { description = "DICOM to NIfTI converter"; From 9019ce010601fcd8dff20b1e996a19eccc7b60ec Mon Sep 17 00:00:00 2001 From: Rocky Breslow <1774125+rbreslow@users.noreply.github.com> Date: Mon, 4 Apr 2022 11:10:38 -0400 Subject: [PATCH 2/3] dcm2niix: add maintainer Also, fix grammatical error in long description. --- pkgs/applications/science/biology/dcm2niix/default.nix | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/science/biology/dcm2niix/default.nix b/pkgs/applications/science/biology/dcm2niix/default.nix index 663e438d93f3..ed8d17086af4 100644 --- a/pkgs/applications/science/biology/dcm2niix/default.nix +++ b/pkgs/applications/science/biology/dcm2niix/default.nix @@ -43,12 +43,11 @@ stdenv.mkDerivation rec { meta = with lib; { description = "DICOM to NIfTI converter"; longDescription = '' - dcm2niix is a designed to convert neuroimaging data from the - DICOM format to the NIfTI format. + dcm2niix is designed to convert neuroimaging data from the DICOM format to the NIfTI format. ''; homepage = "https://www.nitrc.org/projects/dcm2nii"; license = licenses.bsd3; - maintainers = [ maintainers.ashgillman ]; + maintainers = with maintainers; [ ashgillman rbreslow ]; platforms = platforms.all; }; } From d1c3fea7ecbed758168787fe4e4a3157e52bc808 Mon Sep 17 00:00:00 2001 From: Rocky Breslow <1774125+rbreslow@users.noreply.github.com> Date: Mon, 4 Apr 2022 10:40:40 -0400 Subject: [PATCH 3/3] dcm2niix: support usage of suggested Cloudflare zlib --- .../science/biology/dcm2niix/default.nix | 47 ++++++++++++------- .../dcm2niix/dont-fetch-external-libs.patch | 36 ++++++++++++++ 2 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 pkgs/applications/science/biology/dcm2niix/dont-fetch-external-libs.patch diff --git a/pkgs/applications/science/biology/dcm2niix/default.nix b/pkgs/applications/science/biology/dcm2niix/default.nix index ed8d17086af4..90eef027a842 100644 --- a/pkgs/applications/science/biology/dcm2niix/default.nix +++ b/pkgs/applications/science/biology/dcm2niix/default.nix @@ -1,17 +1,26 @@ { lib , stdenv , fetchFromGitHub +, substituteAll , cmake -, git , openjpeg , libyamlcpp -, zlib , batchVersion ? false , withJpegLs ? true , withOpenJpeg ? true -, withSystemZlib ? true +, withCloudflareZlib ? true }: +let + cloudflareZlib = fetchFromGitHub { + owner = "ningfei"; + repo = "zlib"; + # HEAD revision of the gcc.amd64 branch on 2022-04-14. Reminder to update + # whenever bumping package version. + rev = "fda61188d1d4dcd21545c34c2a2f5cc9b0f5db4b"; + sha256 = "sha256-qySFwY0VI2BQLO2XoCZeYshXEDnHh6SmJ3MvcBUROWU="; + }; +in stdenv.mkDerivation rec { version = "1.0.20211006"; pname = "dcm2niix"; @@ -23,22 +32,28 @@ stdenv.mkDerivation rec { sha256 = "sha256-fQAVOzynMdSLDfhcYWcaXkFW/mnv4zySGLVJNE7ql/c="; }; - nativeBuildInputs = [ cmake git ]; + patches = lib.optionals withCloudflareZlib [ + (substituteAll { + src = ./dont-fetch-external-libs.patch; + inherit cloudflareZlib; + }) + ]; + + nativeBuildInputs = [ cmake ]; buildInputs = lib.optionals batchVersion [ libyamlcpp ] - ++ lib.optionals withOpenJpeg [ openjpeg openjpeg.dev ] - ++ lib.optionals withSystemZlib [ zlib ]; + ++ lib.optionals withOpenJpeg [ openjpeg openjpeg.dev ]; cmakeFlags = lib.optionals batchVersion [ - "-DBATCH_VERSION=ON" - "-DYAML-CPP_DIR=${libyamlcpp}/lib/cmake/yaml-cpp" - ] ++ lib.optionals withJpegLs [ - "-DUSE_JPEGLS=ON" - ] ++ lib.optionals withOpenJpeg [ - "-DUSE_OPENJPEG=ON" - "-DOpenJPEG_DIR=${openjpeg}/lib/${openjpeg.pname}-${lib.versions.majorMinor openjpeg.version}" - ] ++ lib.optionals withSystemZlib [ - "-DZLIB_IMPLEMENTATION=System" - ]; + "-DBATCH_VERSION=ON" + "-DYAML-CPP_DIR=${libyamlcpp}/lib/cmake/yaml-cpp" + ] ++ lib.optionals withJpegLs [ + "-DUSE_JPEGLS=ON" + ] ++ lib.optionals withOpenJpeg [ + "-DUSE_OPENJPEG=ON" + "-DOpenJPEG_DIR=${openjpeg}/lib/${openjpeg.pname}-${lib.versions.majorMinor openjpeg.version}" + ] ++ lib.optionals withCloudflareZlib [ + "-DZLIB_IMPLEMENTATION=Cloudflare" + ]; meta = with lib; { description = "DICOM to NIfTI converter"; diff --git a/pkgs/applications/science/biology/dcm2niix/dont-fetch-external-libs.patch b/pkgs/applications/science/biology/dcm2niix/dont-fetch-external-libs.patch new file mode 100644 index 000000000000..493f0fb11f46 --- /dev/null +++ b/pkgs/applications/science/biology/dcm2niix/dont-fetch-external-libs.patch @@ -0,0 +1,36 @@ +diff --git a/SuperBuild/External-CLOUDFLARE-ZLIB.cmake b/SuperBuild/External-CLOUDFLARE-ZLIB.cmake +index 9f064eb..fe74df5 100644 +--- a/SuperBuild/External-CLOUDFLARE-ZLIB.cmake ++++ b/SuperBuild/External-CLOUDFLARE-ZLIB.cmake +@@ -1,8 +1,5 @@ +-set(CLOUDFLARE_BRANCH gcc.amd64) # Cloudflare zlib branch +- + ExternalProject_Add(zlib +- GIT_REPOSITORY "${git_protocol}://github.com/ningfei/zlib.git" +- GIT_TAG "${CLOUDFLARE_BRANCH}" ++ URL file://@cloudflareZlib@ + SOURCE_DIR cloudflare-zlib + BINARY_DIR cloudflare-zlib-build + CMAKE_ARGS +diff --git a/SuperBuild/SuperBuild.cmake b/SuperBuild/SuperBuild.cmake +index 2a0a956..81354a7 100644 +--- a/SuperBuild/SuperBuild.cmake ++++ b/SuperBuild/SuperBuild.cmake +@@ -1,17 +1,3 @@ +-# Check if git exists +-find_package(Git) +-if(NOT GIT_FOUND) +- message(FATAL_ERROR "Cannot find Git. Git is required for Superbuild") +-endif() +- +-# Use git protocol or not +-option(USE_GIT_PROTOCOL "If behind a firewall turn this off to use http instead." ON) +-if(USE_GIT_PROTOCOL) +- set(git_protocol "git") +-else() +- set(git_protocol "https") +-endif() +- + # Basic CMake build settings + if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING