nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv, lib, fetchurl, makeWrapper, jre, gnugrep, coreutils, writeScript
2, common-updater-scripts, git, gnused, nix, nixfmt, majorVersion }:
3
4with lib;
5
6let
7 repo = "git@github.com:scala/scala.git";
8
9 versionMap = {
10 "2.10" = {
11 version = "2.10.7";
12 sha256 = "koMRmRb2u3cU4HaihAzPItWIGbNVIo7RWRrm92kp8RE=";
13 pname = "scala_2_10";
14 };
15
16 "2.11" = {
17 version = "2.11.12";
18 sha256 = "sR19M2mcpPYLw7K2hY/ZU+PeK4UiyUP0zaS2dDFhlqg=";
19 pname = "scala_2_11";
20 };
21
22 "2.12" = {
23 version = "2.12.15";
24 sha256 = "F5RePKlHjQaoQ2BWqsa5r99g3q/cPjgsbAi2A5IberY=";
25 pname = "scala_2_12";
26 };
27
28 "2.13" = {
29 version = "2.13.8";
30 sha256 = "LLMdhGnGUYOfDpyDehqwZVDQMXJnUvVJBr4bneATFM8=";
31 pname = "scala_2_13";
32 };
33 };
34
35in with versionMap.${majorVersion};
36
37stdenv.mkDerivation rec {
38 inherit version;
39
40 name = "scala-${version}";
41
42 src = fetchurl {
43 inherit sha256;
44 url = "https://www.scala-lang.org/files/archive/scala-${version}.tgz";
45 };
46
47 propagatedBuildInputs = [ jre ];
48
49 nativeBuildInputs = [ makeWrapper ];
50
51 installPhase = ''
52 runHook preInstall
53 mkdir -p $out
54 rm bin/*.bat
55 mv * $out
56 # put docs in correct subdirectory
57 mkdir -p $out/share/doc
58 mv $out/doc $out/share/doc/${name}
59 mv $out/man $out/share/man
60 for p in $(ls $out/bin/) ; do
61 wrapProgram $out/bin/$p \
62 --prefix PATH ":" ${coreutils}/bin \
63 --prefix PATH ":" ${gnugrep}/bin \
64 --prefix PATH ":" ${jre}/bin \
65 --set JAVA_HOME ${jre}
66 done
67 runHook postInstall
68 '';
69
70 doInstallCheck = true;
71 installCheckPhase = ''
72 $out/bin/scalac -version 2>&1 | grep '^Scala compiler version ${version}'
73
74 echo 'println("foo"*3)' | $out/bin/scala 2>/dev/null | grep "foofoofoo"
75 '';
76
77 passthru = {
78 updateScript = writeScript "update.sh" ''
79 #!${stdenv.shell}
80 set -o errexit
81 PATH=${
82 lib.makeBinPath [
83 common-updater-scripts
84 coreutils
85 git
86 gnused
87 nix
88 nixfmt
89 ]
90 }
91 versionSelect='v${versions.major version}.${versions.minor version}.*'
92 oldVersion="$(nix-instantiate --eval -E "with import ./. {}; lib.getVersion ${pname}" | tr -d '"')"
93 latestTag="$(git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags ${repo} "$versionSelect" | tail --lines=1 | cut --delimiter='/' --fields=3 | sed 's|^v||g')"
94 if [ "$oldVersion" != "$latestTag" ]; then
95 nixpkgs="$(git rev-parse --show-toplevel)"
96 default_nix="$nixpkgs/pkgs/development/compilers/scala/2.x.nix"
97 update-source-version ${pname} "$latestTag" --version-key=version --print-changes
98 nixfmt "$default_nix"
99 else
100 echo "${pname} is already up-to-date"
101 fi
102 '';
103 };
104
105 meta = {
106 description = "A general purpose programming language";
107 longDescription = ''
108 Scala is a general purpose programming language designed to express
109 common programming patterns in a concise, elegant, and type-safe way.
110 It smoothly integrates features of object-oriented and functional
111 languages, enabling Java and other programmers to be more productive.
112 Code sizes are typically reduced by a factor of two to three when
113 compared to an equivalent Java application.
114 '';
115 homepage = "https://www.scala-lang.org/";
116 license = licenses.bsd3;
117 platforms = platforms.all;
118 branch = versions.majorMinor version;
119 maintainers = [ maintainers.nequissimus ];
120 };
121}