summary refs log tree commit diff
path: root/pkgs/development/tools/coursier
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/tools/coursier')
-rw-r--r--pkgs/development/tools/coursier/default.nix54
1 files changed, 42 insertions, 12 deletions
diff --git a/pkgs/development/tools/coursier/default.nix b/pkgs/development/tools/coursier/default.nix
index b54a831e955..64c48b702cf 100644
--- a/pkgs/development/tools/coursier/default.nix
+++ b/pkgs/development/tools/coursier/default.nix
@@ -1,18 +1,25 @@
-{ stdenv, fetchurl, makeWrapper, jre }:
+{ lib, stdenv, fetchurl, makeWrapper, jre, writeScript, common-updater-scripts
+, coreutils, git, gnused, nix, nixfmt }:
 
 let
-  zshCompletion = version: fetchurl {
-    url = "https://raw.githubusercontent.com/coursier/coursier/v${version}/modules/cli/src/main/resources/completions/zsh";
-    sha256 = "1mn6cdmf59nkz5012wgd3gd6hpk2w4629sk8z95230ky8487dac3";
+  version = "2.0.16";
+
+  zshCompletion = fetchurl {
+    url =
+      "https://raw.githubusercontent.com/coursier/coursier/v${version}/modules/cli/src/main/resources/completions/zsh";
+    sha256 = "0afxzrk9w1qinfsz55jjrxydw0fcv6p722g1q955dl7f6xbab1jh";
   };
-in
-stdenv.mkDerivation rec {
+
+  repo = "git@github.com:coursier/coursier.git";
+in stdenv.mkDerivation rec {
+  inherit version;
+
   pname = "coursier";
-  version = "2.0.0-RC6-18";
 
   src = fetchurl {
-    url = "https://github.com/coursier/coursier/releases/download/v${version}/coursier";
-    sha256 = "0vym99fyn0g8l5y2zvhf73ww17wywrh503wg5aw4nilj8w1ncvn2";
+    url =
+      "https://github.com/coursier/coursier/releases/download/v${version}/coursier";
+    sha256 = "sha256-Yx6PvBo763GnEwU5s7AYUs++Au25TF6cZ4WYGgruHpw=";
   };
 
   nativeBuildInputs = [ makeWrapper ];
@@ -23,12 +30,35 @@ stdenv.mkDerivation rec {
     wrapProgram $out/bin/coursier --prefix PATH ":" ${jre}/bin
 
     # copy zsh completion
-    install -Dm755 ${zshCompletion version} $out/share/zsh/site-functions/_coursier
+    install -Dm755 ${zshCompletion} $out/share/zsh/site-functions/_coursier
+  '';
+
+  passthru.updateScript = writeScript "update.sh" ''
+    #!${stdenv.shell}
+    set -o errexit
+    PATH=${
+      lib.makeBinPath [ common-updater-scripts coreutils git gnused nix nixfmt ]
+    }
+    oldVersion="$(nix-instantiate --eval -E "with import ./. {}; lib.getVersion ${pname}" | tr -d '"')"
+    latestTag="$(git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags ${repo} 'v*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3 | sed 's|^v||g')"
+    if [ "$oldVersion" != "$latestTag" ]; then
+      nixpkgs="$(git rev-parse --show-toplevel)"
+      default_nix="$nixpkgs/pkgs/development/tools/coursier/default.nix"
+      update-source-version ${pname} "$latestTag" --version-key=version --print-changes
+      url="${builtins.head zshCompletion.urls}"
+      completion_url=$(echo $url | sed "s|$oldVersion|$latestTag|g")
+      completion_sha256="$(nix-prefetch-url --type sha256 $completion_url)"
+      sed -i "s|${zshCompletion.outputHash}|$completion_sha256|g" "$default_nix"
+      nixfmt "$default_nix"
+    else
+      echo "${pname} is already up-to-date"
+    fi
   '';
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     homepage = "https://get-coursier.io/";
-    description = "A Scala library to fetch dependencies from Maven / Ivy repositories";
+    description =
+      "A Scala library to fetch dependencies from Maven / Ivy repositories";
     license = licenses.asl20;
     maintainers = with maintainers; [ adelbertc nequissimus ];
   };