1{
2 lib,
3 runCommand,
4
5 cacert,
6 curl,
7 git,
8 julia,
9 python3,
10 stdenv,
11
12 closureYaml,
13 extraLibs,
14 juliaCpuTarget,
15 overridesToml,
16 packageImplications,
17 packageNames,
18 precompile,
19 registry,
20}:
21
22let
23 # On darwin, we don't want to specify JULIA_SSL_CA_ROOTS_PATH. If we do (using a -bin julia derivation, which is the
24 # only kind darwin currently supports), you get an error like this:
25 #
26 # GitError(Code:ERROR, Class:SSL, Your Julia is built with a SSL/TLS engine that libgit2 doesn't know how to configure
27 # to use a file or directory of certificate authority roots, but your environment specifies one via the SSL_CERT_FILE
28 # variable. If you believe your system's root certificates are safe to use, you can `export JULIA_SSL_CA_ROOTS_PATH=""`
29 # in your environment to use those instead.)
30 setJuliaSslCaRootsPath =
31 if stdenv.targetPlatform.isDarwin then
32 ''export JULIA_SSL_CA_ROOTS_PATH=""''
33 else
34 ''export JULIA_SSL_CA_ROOTS_PATH="${cacert}/etc/ssl/certs/ca-bundle.crt"'';
35
36in
37
38runCommand "julia-depot"
39 {
40 nativeBuildInputs = [
41 curl
42 git
43 julia
44 (python3.withPackages (ps: with ps; [ pyyaml ]))
45 ]
46 ++ extraLibs;
47 inherit precompile registry;
48 }
49 (
50 ''
51 export HOME=$(pwd)
52
53 echo "Building Julia depot and project with the following inputs"
54 echo "Julia: ${julia}"
55 echo "Registry: $registry"
56 echo "Overrides ${overridesToml}"
57
58 mkdir -p $out/project
59 export JULIA_PROJECT="$out/project"
60
61 mkdir -p $out/depot/artifacts
62 export JULIA_DEPOT_PATH="$out/depot"
63 cp ${overridesToml} $out/depot/artifacts/Overrides.toml
64
65 # These can be useful to debug problems
66 # export JULIA_DEBUG=Pkg
67 # export JULIA_DEBUG=loading
68
69 ${setJuliaSslCaRootsPath}
70
71 # Only precompile if configured to below
72 export JULIA_PKG_PRECOMPILE_AUTO=0
73 ''
74 + lib.optionalString (juliaCpuTarget != null) ''
75 export JULIA_CPU_TARGET="${juliaCpuTarget}"
76 ''
77 + ''
78 # Prevent a warning where Julia tries to download package server info
79 export JULIA_PKG_SERVER=""
80
81 # See if we need to add any extra package names based on the closure
82 # and the packageImplications. We're using the full closure YAML here since
83 # it's available, which is slightly weird, but it should work just as well
84 # for finding the extra packages we need to add
85 python ${./python}/find_package_implications.py "${closureYaml}" '${
86 lib.generators.toJSON { } packageImplications
87 }' extra_package_names.txt
88
89 # Work around new git security features added in git 2.44.1
90 # See https://github.com/NixOS/nixpkgs/issues/315890
91 git config --global --add safe.directory '*'
92
93 # Tell Julia to use the Git binary we provide, rather than internal libgit2.
94 export JULIA_PKG_USE_CLI_GIT="true"
95
96 # At time of writing, this appears to be the only way to turn precompiling's
97 # terminal output into standard logging, so opportunistically do that.
98 # (Note this is different from JULIA_CI).
99 export CI=true
100
101 julia -e ' \
102 import Pkg
103 import Pkg.Types: PRESERVE_NONE
104
105 Pkg.Registry.add(Pkg.RegistrySpec(path="${registry}"))
106
107 input = ${lib.generators.toJSON { } packageNames} ::Vector{String}
108
109 if isfile("extra_package_names.txt")
110 append!(input, readlines("extra_package_names.txt"))
111 end
112
113 input = unique(input)
114
115 if !isempty(input)
116 println("Adding packages: " * join(input, " "))
117 Pkg.add(input; preserve=PRESERVE_NONE)
118 Pkg.instantiate()
119
120 if "precompile" in keys(ENV) && ENV["precompile"] != "0" && ENV["precompile"] != ""
121 if isdefined(Sys, :CPU_NAME)
122 println("Precompiling with CPU_NAME = " * Sys.CPU_NAME)
123 end
124
125 Pkg.precompile()
126 end
127 end
128
129 # Remove the registry to save space
130 Pkg.Registry.rm("General")
131 '
132 ''
133 )