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