at 24.11-pre 88 lines 2.5 kB view raw
1{ stdenv 2, coreutils 3, lib 4, installShellFiles 5, zlib 6, autoPatchelfHook 7, fetchurl 8, makeWrapper 9, callPackage 10, jre 11, testers 12, scala-cli 13}: 14 15let 16 pname = "scala-cli"; 17 sources = lib.importJSON ./sources.json; 18 inherit (sources) version assets; 19 20 platforms = builtins.attrNames assets; 21in 22stdenv.mkDerivation { 23 inherit pname version; 24 nativeBuildInputs = [ installShellFiles makeWrapper ] 25 ++ lib.optional stdenv.isLinux autoPatchelfHook; 26 buildInputs = 27 assert lib.assertMsg (lib.versionAtLeast jre.version "17.0.0") '' 28 scala-cli requires Java 17 or newer, but ${jre.name} is ${jre.version} 29 ''; 30 [ coreutils zlib stdenv.cc.cc ]; 31 src = 32 let 33 asset = assets."${stdenv.hostPlatform.system}" or (throw "Unsupported platform ${stdenv.hostPlatform.system}"); 34 in 35 fetchurl { 36 url = "https://github.com/Virtuslab/scala-cli/releases/download/v${version}/${asset.asset}"; 37 sha256 = asset.sha256; 38 }; 39 unpackPhase = '' 40 runHook preUnpack 41 gzip -d < $src > scala-cli 42 runHook postUnpack 43 ''; 44 45 installPhase = '' 46 runHook preInstall 47 install -Dm755 scala-cli $out/bin/.scala-cli-wrapped 48 makeWrapper $out/bin/.scala-cli-wrapped $out/bin/scala-cli \ 49 --set JAVA_HOME ${jre.home} \ 50 --argv0 "$out/bin/scala-cli" 51 runHook postInstall 52 ''; 53 54 # We need to call autopatchelf before generating completions 55 dontAutoPatchelf = true; 56 57 postFixup = lib.optionalString stdenv.isLinux '' 58 autoPatchelf $out 59 '' + '' 60 # hack to ensure the completion function looks right 61 # as $0 is used to generate the compdef directive 62 mkdir temp 63 cp $out/bin/.scala-cli-wrapped temp/scala-cli 64 PATH="./temp:$PATH" 65 66 installShellCompletion --cmd scala-cli \ 67 --bash <(scala-cli completions bash) \ 68 --zsh <(scala-cli completions zsh) 69 ''; 70 71 meta = with lib; { 72 homepage = "https://scala-cli.virtuslab.org"; 73 downloadPage = "https://github.com/VirtusLab/scala-cli/releases/v${version}"; 74 sourceProvenance = with sourceTypes; [ binaryNativeCode ]; 75 license = licenses.asl20; 76 description = "Command-line tool to interact with the Scala language"; 77 mainProgram = "scala-cli"; 78 maintainers = [ maintainers.kubukoz ]; 79 inherit platforms; 80 }; 81 82 passthru.updateScript = callPackage ./update.nix { } { inherit platforms pname version; }; 83 84 passthru.tests.version = testers.testVersion { 85 package = scala-cli; 86 command = "scala-cli version --offline"; 87 }; 88}