nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 version,
3 hash,
4 patches ? [ ],
5}:
6
7{
8 lib,
9 stdenv,
10 fetchurl,
11 which,
12 python3,
13 gfortran,
14 cacert,
15 cmake,
16 perl,
17 gnum4,
18 openssl,
19 libxml2,
20 zlib,
21 buildPackages,
22}:
23
24let
25 skip_tests = [
26 # test flaky on ofborg
27 "channels"
28 # test flaky
29 "read"
30 "NetworkOptions"
31 "REPL"
32 "ccall"
33 ]
34 ++ lib.optionals (lib.versionAtLeast version "1.11") [
35 "loading"
36 "cmdlineargs"
37 ]
38 ++ lib.optionals (lib.versionAtLeast version "1.12") [
39 "Distributed"
40 # test flaky because of our RPATH patching
41 # https://github.com/NixOS/nixpkgs/pull/230965#issuecomment-1545336489
42 "Compiler/codegen"
43 "precompile"
44 "compileall"
45 ]
46 ++ lib.optionals (lib.versionOlder version "1.12") [
47 "compiler/codegen" # older versions' test was in lowercase
48 ];
49in
50
51stdenv.mkDerivation rec {
52 pname = "julia";
53
54 inherit version patches;
55
56 src = fetchurl {
57 url = "https://github.com/JuliaLang/julia/releases/download/v${version}/julia-${version}-full.tar.gz";
58 inherit hash;
59 };
60
61 strictDeps = true;
62
63 nativeBuildInputs = [
64 which
65 python3
66 gfortran
67 cmake
68 perl
69 gnum4
70 openssl
71 ];
72
73 buildInputs = [
74 libxml2
75 zlib
76 ]
77 ++ lib.optionals (lib.versionAtLeast version "1.11") [
78 cacert
79 ];
80
81 dontUseCmakeConfigure = true;
82
83 postPatch = ''
84 patchShebangs .
85 ''
86 + lib.optionalString (lib.versionAtLeast version "1.11") ''
87 substituteInPlace deps/curl.mk \
88 --replace-fail 'jxf $(notdir $<)' \
89 'jxf $(notdir $<) && sed -i "s|/usr/bin/env perl|${lib.getExe buildPackages.perl}|" curl-$(CURL_VER)/scripts/cd2nroff'
90 ''
91 + lib.optionalString (lib.versionOlder version "1.12") ''
92 substituteInPlace deps/tools/common.mk \
93 --replace-fail "CMAKE_COMMON := " "CMAKE_COMMON := ${lib.cmakeFeature "CMAKE_POLICY_VERSION_MINIMUM" "3.10"} "
94 ''
95 + lib.optionalString (lib.versionAtLeast version "1.12") ''
96 substituteInPlace deps/openssl.mk \
97 --replace-fail 'cd $(dir $<) && $(TAR) -zxf $<' \
98 'cd $(dir $<) && $(TAR) -zxf $< && sed -i "s|/usr/bin/env perl|${lib.getExe buildPackages.perl}|" openssl-$(OPENSSL_VER)/Configure'
99 '';
100
101 makeFlags = [
102 "prefix=$(out)"
103 "USE_BINARYBUILDER=0"
104 ]
105 ++ lib.optionals stdenv.hostPlatform.isx86_64 [
106 # https://github.com/JuliaCI/julia-buildkite/blob/main/utilities/build_envs.sh
107 "JULIA_CPU_TARGET=generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1);x86-64-v4,-rdrnd,base(1)"
108 ]
109 ++ lib.optionals stdenv.hostPlatform.isAarch64 [
110 "JULIA_CPU_TARGET=generic;cortex-a57;thunderx2t99;carmel,clone_all;apple-m1,base(3);neoverse-512tvb,base(3)"
111 ];
112
113 # remove forbidden reference to $TMPDIR
114 preFixup = ''
115 for file in libcurl.so libgmpxx.so libmpfr.so; do
116 patchelf --shrink-rpath --allowed-rpath-prefixes ${builtins.storeDir} "$out/lib/julia/$file"
117 done
118 '';
119
120 # tests are flaky for aarch64-linux on hydra
121 doInstallCheck = if (lib.versionOlder version "1.10") then !stdenv.hostPlatform.isAarch64 else true;
122
123 preInstallCheck = ''
124 export JULIA_TEST_USE_MULTIPLE_WORKERS="true"
125 # Some tests require read/write access to $HOME.
126 # And $HOME cannot be equal to $TMPDIR as it causes test failures
127 export HOME=$(mktemp -d)
128 '';
129
130 installCheckPhase = ''
131 runHook preInstallCheck
132 # Command lifted from `test/Makefile`.
133 $out/bin/julia \
134 --check-bounds=yes \
135 --startup-file=no \
136 --depwarn=error \
137 $out/share/julia/test/runtests.jl \
138 --skip internet_required ${toString skip_tests}
139 runHook postInstallCheck
140 '';
141
142 dontStrip = true;
143
144 enableParallelBuilding = true;
145
146 env = lib.optionalAttrs (lib.versionOlder version "1.11" || stdenv.hostPlatform.isAarch64) {
147 NIX_CFLAGS_COMPILE = toString [
148 "-Wno-error=implicit-function-declaration"
149 "-Wno-error=incompatible-pointer-types"
150 ];
151 };
152
153 meta = {
154 description = "High-level performance-oriented dynamical language for technical computing";
155 mainProgram = "julia";
156 homepage = "https://julialang.org/";
157 license = lib.licenses.mit;
158 maintainers = with lib.maintainers; [
159 nickcao
160 joshniemela
161 thomasjm
162 taranarmo
163 ];
164 platforms = [
165 "x86_64-linux"
166 "aarch64-linux"
167 ];
168 };
169}