about summary refs log tree commit diff
path: root/pkgs/applications/science/misc
diff options
context:
space:
mode:
authorRobert Scott <code@humanleg.org.uk>2023-10-24 01:02:36 +0100
committerRobert Scott <code@humanleg.org.uk>2024-02-03 13:37:59 +0000
commit272f7bb1f4d02d42fc10fd26f21f4ca4c6f4d85a (patch)
treed173c8a4cdb0a1d5927c680de9c5deb8d169a5eb /pkgs/applications/science/misc
parent82ee069492ce894f02a2c6a9df42986269b428b9 (diff)
openrefine: init at 3.7.7
Diffstat (limited to 'pkgs/applications/science/misc')
-rw-r--r--pkgs/applications/science/misc/openrefine/default.nix136
-rwxr-xr-xpkgs/applications/science/misc/openrefine/update.sh20
2 files changed, 156 insertions, 0 deletions
diff --git a/pkgs/applications/science/misc/openrefine/default.nix b/pkgs/applications/science/misc/openrefine/default.nix
new file mode 100644
index 0000000000000..fafdcb03ec03a
--- /dev/null
+++ b/pkgs/applications/science/misc/openrefine/default.nix
@@ -0,0 +1,136 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, buildNpmPackage
+, curl
+, jdk
+, jq
+, makeWrapper
+, maven
+, writeText
+}:
+
+let
+  maven' = maven.override {
+    inherit jdk;
+  };
+
+  version = "3.7.7";
+  src = fetchFromGitHub {
+    owner = "openrefine";
+    repo = "openrefine";
+    rev = version;
+    hash = "sha256-/Txx+r+eFizxaTV5u/nOJwum8nJW6jsR6kYA0YbRsJs=";
+  };
+
+  npmPkg = buildNpmPackage {
+    inherit src version;
+
+    pname = "openrefine-npm";
+    sourceRoot = "source/main/webapp";
+
+    npmDepsHash = "sha256-8GhcL4tohQ5u2HeYN6JyTMMobUOqAL8ETCLiP1SoDSk=";
+
+    # package.json doesn't supply a version, which npm doesn't like - fix this.
+    # directly referencing jq because buildNpmPackage doesn't pass
+    # nativeBuildInputs through to fetchNpmDeps
+    postPatch = ''
+      NEW_PACKAGE_JSON=$(mktemp)
+      ${jq}/bin/jq '. + {version: $ENV.version}' package.json > $NEW_PACKAGE_JSON
+      cp $NEW_PACKAGE_JSON package.json
+    '';
+
+    dontNpmBuild = true;
+    installPhase = ''
+      mkdir -p $out
+      cp -r modules/core/3rdparty/* $out/
+    '';
+  };
+
+in maven'.buildMavenPackage {
+  inherit src version;
+
+  pname = "openrefine";
+
+  postPatch = ''
+    cp -r ${npmPkg} main/webapp/modules/core/3rdparty
+  '';
+  mvnParameters = "-DskipTests=true -pl !packaging";
+  mvnHash = "sha256-MqE+iloqzBav6E3/rf1LP5BlKhW/FBIt6+6U+S8UJWA=";
+
+  nativeBuildInputs = [ makeWrapper ];
+
+  installPhase = let
+    gitProperties = writeText "git.properties" (builtins.toJSON {
+      "git.build.version" = version;
+      "git.branch" = "none";
+      "git.build.time" = "1970-01-01T00:00:00+0000";
+      "git.commit.id.abbrev" = "none";
+      "git.commit.id.describe" = "none";
+    });
+  in ''
+    mkdir -p $out/lib/server/target/lib
+    cp -r server/target/lib/* $out/lib/server/target/lib/
+    cp server/target/openrefine-*-server.jar $out/lib/server/target/lib/
+
+    mkdir -p $out/lib/webapp
+    cp -r main/webapp/{WEB-INF,modules} $out/lib/webapp/
+    (
+      cd extensions
+      for ext in * ; do
+        if [ -d "$ext/module" ] ; then
+          mkdir -p "$out/lib/webapp/extensions/$ext"
+          cp -r "$ext/module" "$out/lib/webapp/extensions/$ext/"
+        fi
+      done
+    )
+
+    cp ${gitProperties} $out/lib/webapp/WEB-INF/classes/git.properties
+
+    mkdir -p $out/etc
+    cp refine.ini $out/etc/
+
+    mkdir -p $out/bin
+    cp refine $out/bin/
+  '';
+
+  preFixup = ''
+    find $out -name '*.java' -delete
+    sed -i -E 's|^(butterfly\.modules\.path =).*extensions.*$|\1 '"$out/lib/webapp/extensions|" \
+      $out/lib/webapp/WEB-INF/butterfly.properties
+
+    sed -i 's|^cd `dirname \$0`$|cd '"$out/lib|" $out/bin/refine
+
+    cat >> $out/etc/refine.ini <<EOF
+    REFINE_WEBAPP='$out/lib/webapp'
+    REFINE_LIB_DIR='$out/lib/server/target/lib'
+
+    JAVA_HOME='${jdk.home}'
+
+    # non-headless mode tries to launch a browser, causing a
+    # number of purity problems
+    JAVA_OPTIONS='-Drefine.headless=true'
+    EOF
+
+    wrapProgram $out/bin/refine \
+      --prefix PATH : '${lib.makeBinPath [ jdk curl ]}' \
+      --set-default REFINE_INI_PATH "$out/etc/refine.ini"
+  '';
+
+  passthru = {
+    inherit npmPkg;
+    updateScript = ./update.sh;
+  };
+
+  meta = with lib; {
+    description = "Power tool for working with messy data and improving it";
+    homepage = "https://openrefine.org";
+    license = licenses.bsd3;
+    maintainers = with maintainers; [ ris ];
+    sourceProvenance = with sourceTypes; [
+      fromSource
+      binaryBytecode  # maven dependencies
+    ];
+    broken = stdenv.isDarwin;  # builds, doesn't run
+  };
+}
diff --git a/pkgs/applications/science/misc/openrefine/update.sh b/pkgs/applications/science/misc/openrefine/update.sh
new file mode 100755
index 0000000000000..545a5bd4e1982
--- /dev/null
+++ b/pkgs/applications/science/misc/openrefine/update.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p nix nix-update
+
+set -euxo pipefail
+
+nix-update "${UPDATE_NIX_ATTR_PATH}"
+nix-update "${UPDATE_NIX_ATTR_PATH}.npmPkg" --version=skip
+
+FILE="$(nix-instantiate --eval -E 'with import ./. {}; (builtins.unsafeGetAttrPos "version" '"${UPDATE_NIX_ATTR_PATH}"').file' | tr -d '"')"
+
+MVNHASH_OLD=$(nix-instantiate --eval . -A "${UPDATE_NIX_ATTR_PATH}.mvnHash" | tr -d '"')
+MVNHASH_OLD_ESCAPED=$(echo "${MVNHASH_OLD}" | sed -re 's|[+]|\\&|g')
+FAKEHASH=$(nix-instantiate --eval . -A "lib.fakeHash" | tr -d '"')
+FAKEHASH_ESCAPED=$(echo "${FAKEHASH}" | sed -re 's|[+]|\\&|g')
+
+sed -E -i "s|${MVNHASH_OLD_ESCAPED}|${FAKEHASH}|g" "${FILE}"
+
+MVNHASH_NEW="$(nix-build . -A "${UPDATE_NIX_ATTR_PATH}" 2>&1 | tail -n10 | grep 'got:' | cut -d: -f2- | xargs echo || true)"
+
+sed -E -i "s|${FAKEHASH_ESCAPED}|${MVNHASH_NEW}|g" "${FILE}"