nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv, coreutils, lib, installShellFiles, zlib, autoPatchelfHook, fetchurl }:
2
3let
4 version = "0.1.5";
5 assets = {
6 x86_64-darwin = {
7 asset = "scala-cli-x86_64-apple-darwin.gz";
8 sha256 = "1sczbvvhh1ff8mdb6zj4q3fnrz1qsqmr58jlb1s3fy1wv2p5ywxl";
9 };
10 x86_64-linux = {
11 asset = "scala-cli-x86_64-pc-linux.gz";
12 sha256 = "1ahvjgcghh1pmgfsajg0b8bf5aaqxdx0f6b6qgljs0xfqm7zs05v";
13 };
14 };
15in
16stdenv.mkDerivation {
17 pname = "scala-cli";
18 inherit version;
19 nativeBuildInputs = [ installShellFiles ]
20 ++ lib.optional stdenv.isLinux autoPatchelfHook;
21 buildInputs = [ coreutils zlib stdenv.cc.cc ];
22 src =
23 let
24 asset = assets."${stdenv.hostPlatform.system}" or (throw "Unsupported platform ${stdenv.hostPlatform.system}");
25 in
26 fetchurl {
27 url = "https://github.com/Virtuslab/scala-cli/releases/download/v${version}/${asset.asset}";
28 sha256 = asset.sha256;
29 };
30
31 unpackPhase = ''
32 runHook preUnpack
33 gzip -d < $src > scala-cli
34 runHook postUnpack
35 '';
36
37 installPhase = ''
38 runHook preInstall
39 install -Dm755 scala-cli $out/bin/scala-cli
40 runHook postInstall
41 '';
42
43 # We need to call autopatchelf before generating completions
44 dontAutoPatchelf = true;
45
46 postFixup = lib.optionalString stdenv.isLinux ''
47 autoPatchelf $out
48 '' + ''
49 # hack to ensure the completion function looks right
50 # as $0 is used to generate the compdef directive
51 PATH="$out/bin:$PATH"
52
53 installShellCompletion --cmd scala-cli \
54 --bash <(scala-cli completions bash) \
55 --zsh <(scala-cli completions zsh)
56 '';
57
58 meta = with lib; {
59 homepage = "https://scala-cli.virtuslab.org";
60 downloadPage = "https://github.com/VirtusLab/scala-cli/releases/v${version}";
61 license = licenses.asl20;
62 description = "Command-line tool to interact with the Scala language";
63 maintainers = [ maintainers.kubukoz ];
64 platforms = builtins.attrNames assets;
65 };
66}