diff --git a/flake.nix b/flake.nix index 76fe717..ff294eb 100644 --- a/flake.nix +++ b/flake.nix @@ -47,15 +47,23 @@ typelevelShell.jdk.package = pkgs.jdk17_headless; }; }; + + sbt1 = pkgs.callPackage ./pkgs/sbt1.nix { }; in { inherit devShells; checks = devShells; + packages = { + inherit sbt1; + }; }; in { inherit typelevelShell; - overlays.default = devshell.overlays.default; + overlays.default = final: prev: + (devshell.overlays.default final prev) // { + sbt1 = self.packages.${prev.stdenv.hostPlatform.system}.sbt1; + }; templates = { library = { path = ./library; diff --git a/modules/typelevelShell.nix b/modules/typelevelShell.nix index 7b83a6a..1fbfbe2 100644 --- a/modules/typelevelShell.nix +++ b/modules/typelevelShell.nix @@ -50,7 +50,7 @@ in commands = [ { package = pkgs.metals.override { jre = cfg.jdk.metals.package; }; } { package = pkgs.scala-cli.override { jre = cfg.jdk.scala-cli.package; }; } - { package = pkgs.sbt.override { jre = cfg.jdk.package; }; } + { package = pkgs.sbt1.override { jre = cfg.jdk.package; }; } ]; devshell.motd = diff --git a/pkgs/sbt1.nix b/pkgs/sbt1.nix new file mode 100644 index 0000000..12528be --- /dev/null +++ b/pkgs/sbt1.nix @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: MIT +# SPDX-FileCopyrightText: Copyright (c) 2003-2026 Eelco Dolstra and the Nixpkgs/NixOS contributors +# SPDX-FileContributor: https://github.com/nixos/nixpkgs/blob/d9507283e60f11ad9fcb53b734cbf59154fc3b01/pkgs/development/tools/build-managers/sbt/default.nix + +{ + lib, + stdenv, + fetchurl, + jre, + autoPatchelfHook, + zlib, + ncurses, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "sbt"; + version = "1.13.0"; + + src = fetchurl { + url = "https://github.com/sbt/sbt/releases/download/v${finalAttrs.version}/sbt-${finalAttrs.version}.tgz"; + hash = "sha256-BoBoBf/SYjJycyYhZ2btR5O1SfjB5v/u8uYQ23JFtpg="; + }; + + postPatch = '' + echo -java-home ${jre.home} >>conf/sbtopts + ''; + + nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ]; + + buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ + stdenv.cc.cc # libstdc++.so.6 + zlib + ]; + + propagatedBuildInputs = [ + # for infocmp + ncurses + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/share/sbt $out/bin + cp -ra . $out/share/sbt + ln -sT ../share/sbt/bin/sbt $out/bin/sbt + ln -sT ../share/sbt/bin/sbtn-${ + if (stdenv.hostPlatform.isDarwin) then + "universal-apple-darwin" + else if (stdenv.hostPlatform.isAarch64) then + "aarch64-pc-linux" + else + "x86_64-pc-linux" + } $out/bin/sbtn + + runHook postInstall + ''; + + meta = { + homepage = "https://www.scala-sbt.org/"; + license = lib.licenses.bsd3; + sourceProvenance = with lib.sourceTypes; [ + binaryBytecode + binaryNativeCode + ]; + description = "Build tool for Scala, Java and more"; + platforms = lib.platforms.unix; + mainProgram = "sbt"; + }; +})