From 31a346f4b63400386fce5e9feca2d5d6837aea1a Mon Sep 17 00:00:00 2001 From: Jiuyang Liu Date: Sat, 20 Jan 2024 18:04:56 +0800 Subject: [PATCH] add scala-cli, lit, filecheck to dependency --- flake.nix | 3 ++ nix/scala-cli.nix | 88 +++++++++++++++++++++++++++++++++++++++++++++++ nix/sources.json | 21 +++++++++++ overlay.nix | 1 + 4 files changed, 113 insertions(+) create mode 100644 nix/scala-cli.nix create mode 100644 nix/sources.json diff --git a/flake.nix b/flake.nix index 03cebc32443..41d8c91b0f2 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,9 @@ mill circt jextract + lit + llvm + scala-cli ]; in { diff --git a/nix/scala-cli.nix b/nix/scala-cli.nix new file mode 100644 index 00000000000..7e63b472c5e --- /dev/null +++ b/nix/scala-cli.nix @@ -0,0 +1,88 @@ +{ stdenv +, coreutils +, lib +, installShellFiles +, zlib +, autoPatchelfHook +, fetchurl +, makeWrapper +, callPackage +, jre +, testers +, scala-cli +}: + +let + pname = "scala-cli"; + sources = lib.importJSON ./sources.json; + inherit (sources) version assets; + + platforms = builtins.attrNames assets; +in +stdenv.mkDerivation { + inherit pname version; + nativeBuildInputs = [ installShellFiles makeWrapper ] + ++ lib.optional stdenv.isLinux autoPatchelfHook; + buildInputs = + assert lib.assertMsg (lib.versionAtLeast jre.version "17.0.0") '' + scala-cli requires Java 17 or newer, but ${jre.name} is ${jre.version} + ''; + [ coreutils zlib stdenv.cc.cc ]; + src = + let + asset = assets."${stdenv.hostPlatform.system}" or (throw "Unsupported platform ${stdenv.hostPlatform.system}"); + in + fetchurl { + url = "https://github.com/Virtuslab/scala-cli/releases/download/v${version}/${asset.asset}"; + sha256 = asset.sha256; + }; + unpackPhase = '' + runHook preUnpack + gzip -d < $src > scala-cli + runHook postUnpack + ''; + + installPhase = '' + runHook preInstall + install -Dm755 scala-cli $out/bin/.scala-cli-wrapped + makeWrapper $out/bin/.scala-cli-wrapped $out/bin/scala-cli \ + --set JAVA_HOME ${jre.home} \ + --argv0 "$out/bin/scala-cli" + runHook postInstall + ''; + + # We need to call autopatchelf before generating completions + dontAutoPatchelf = true; + + postFixup = lib.optionalString stdenv.isLinux '' + autoPatchelf $out + '' + '' + # hack to ensure the completion function looks right + # as $0 is used to generate the compdef directive + mkdir temp + cp $out/bin/.scala-cli-wrapped temp/scala-cli + PATH="./temp:$PATH" + + installShellCompletion --cmd scala-cli \ + --bash <(scala-cli completions bash) \ + --zsh <(scala-cli completions zsh) + ''; + + meta = with lib; { + homepage = "https://scala-cli.virtuslab.org"; + downloadPage = "https://github.com/VirtusLab/scala-cli/releases/v${version}"; + sourceProvenance = with sourceTypes; [ binaryNativeCode ]; + license = licenses.asl20; + description = "Command-line tool to interact with the Scala language"; + maintainers = [ maintainers.kubukoz ]; + inherit platforms; + }; + + passthru.updateScript = callPackage ./update.nix { } { inherit platforms pname version; }; + + passthru.tests.version = testers.testVersion { + package = scala-cli; + command = "scala-cli version --offline"; + }; +} + diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 00000000000..fa1f690317c --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,21 @@ +{ + "version": "1.1.2", + "assets": { + "aarch64-darwin": { + "asset": "scala-cli-aarch64-apple-darwin.gz", + "sha256": "1m5ac0pkp68k446xd8p21hc8caaahpyd3vm5pn1i1cc176f6fm8b" + }, + "aarch64-linux": { + "asset": "scala-cli-aarch64-pc-linux.gz", + "sha256": "1aqw8xmim7rmh8h98h10dlhm0hzl9bs89a51mbd3d99yxa5dq4z0" + }, + "x86_64-darwin": { + "asset": "scala-cli-x86_64-apple-darwin.gz", + "sha256": "06473l04z3nfadi72klk3aw4i39qkyzl3qp7kb1ysn5wx58ci51w" + }, + "x86_64-linux": { + "asset": "scala-cli-x86_64-pc-linux.gz", + "sha256": "1khdzv0s9l6wcb47hnv96prvzgzwcw0db34j6525bdgakj62fhf3" + } + } +} diff --git a/overlay.nix b/overlay.nix index 33037308f9c..740e9b5b614 100644 --- a/overlay.nix +++ b/overlay.nix @@ -50,4 +50,5 @@ final: prev: circt.llvm.lib ]; }; + scala-cli = prev.callPackage ./nix/scala-cli.nix { }; }