Subject: [00/11] Update Julia, Fix precompilation, add HTTP.jl

From: [email-masked] (Nicolò Balzarotti)
Date: Sat, 18 Jan 2020 14:59:14 +0100

I'm sending the patches again as attachments since I think some of them
was badly formatted.

>From 74c02f9b22a4d7cf0bc9a98c17ed69af80cacb0e Mon Sep 17 00:00:00 2001
From: nixo <[email-masked]>
Date: Thu, 12 Dec 2019 09:43:20 +0100
Subject: [PATCH 01/11] gnu: julia: Update to 1.3.1.

* gnu/packages/julia.scm (julia): Update to 1.3.1.
* gnu/packages/julia.scm (libuv-julia): Update to 2.0.0.
---
 gnu/packages/julia.scm | 278 +++++++++++++++++------------------------
 1 file changed, 113 insertions(+), 165 deletions(-)

diff --git a/gnu/packages/julia.scm b/gnu/packages/julia.scm
index 65a5e42beb..e4db39afbd 100644
--- a/gnu/packages/julia.scm
+++ b/gnu/packages/julia.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015, 2016, 2017 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2016 Efraim Flashner <[email-masked]>
+;;; Copyright © 2020 Nicolò Balzarotti <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -28,6 +29,7 @@
   #:use-module (gnu packages algebra)
   #:use-module (gnu packages base)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages curl)
   #:use-module (gnu packages elf)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages llvm)
@@ -43,18 +45,30 @@
   #:use-module (gnu packages textutils)
   #:use-module (gnu packages tls)
   #:use-module (gnu packages version-control)
+  #:use-module (gnu packages ssh)
   #:use-module (gnu packages wget)
   #:use-module (ice-9 match))
 
+(define (julia-patch-url version name)
+  (string-append "https://raw.githubusercontent.com/JuliaLang/julia/v" version
+		 "/deps/patches/" name ".patch"))
+
+(define (julia-patch name sha)
+  (let ((version "1.3.1"))
+    (origin (method url-fetch)
+	    (uri (julia-patch-url version name))
+	    (sha256 (base32 sha))
+	    (file-name name))))
+
 (define libuv-julia
-  (let ((commit "26dbe5672c33fc885462c509fe2a9b36f35866fd")
-        (revision "6"))
+  (let ((commit "35b1504507a7a4168caae3d78db54d1121b121e1"))
     ;; When upgrading Julia, also upgrade this.
-    ;; Get the commit from https://github.com/JuliaLang/julia/blob/v1.1.1/deps/libuv.version
+    ;; Get the commit from
+    ;; https://github.com/JuliaLang/julia/blob/v1.3.1/deps/libuv.version
     (package
       (inherit libuv)
       (name "libuv-julia")
-      (version (string-append "1.9.0-" revision "." (string-take commit 8)))
+      (version (string-append "2.0.0" "." (string-take commit 8)))
       (source (origin
                 (method git-fetch)
                 (uri (git-reference
@@ -63,7 +77,7 @@
                 (file-name (string-append name "-" version "-checkout"))
                 (sha256
                  (base32
-                  "17pn2xmqaramilx897s9grs966i5246gi6sric5alch4g9j4685n"))))
+                  "0dn3v6fdp1z382pqg3nhjzk60l61ky9b65mfgaj29fv2da95rwjs"))))
       (build-system gnu-build-system)
       (arguments
        (substitute-keyword-arguments (package-arguments libuv)
@@ -72,16 +86,27 @@
              (delete 'autogen)))))
       (home-page "https://github.com/JuliaLang/libuv"))))
 
-(define (llvm-patch-url version name)
-  (string-append "https://raw.githubusercontent.com/JuliaLang/julia/v" version
-		 "/deps/patches/" name))
-
-(define (llvm-patch name sha)
-  (let ((version "1.1.1"))
-    (origin (method url-fetch)
-	    (uri (llvm-patch-url version name))
-	    (sha256 (base32 sha))
-	    (file-name name))))
+(define libunwind-julia
+  ;; julia requires a patched version
+  (package
+    (inherit libunwind)
+    (name "libunwind-julia")
+    (version "1.3.1")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "mirror://savannah/libunwind/libunwind-"
+                                  version ".tar.gz"))
+              (sha256
+               (base32
+                "1y0l08k6ak1mqbfj6accf9s5686kljwgsl4vcqpxzk5n74wpm6a3"))
+              (patches
+               (list
+	        (julia-patch "libunwind-prefer-extbl"
+                             "0lr4dafw8qyfh8sw8hhbwkql1dlhqv8px7k81y2l20hhxfgnh2m1")
+                (julia-patch "libunwind-static-arm"
+                             "1jk3bmiw61ypcchqkk1fyg5wh8wpggk574wxyfyaic870zh3lhgq")))))
+    (build-system gnu-build-system)
+    (home-page "https://github.com/JuliaLang/libuv")))
 
 (define llvm-julia
   (package
@@ -99,39 +124,39 @@
               ;; Discussion: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=919628
               (patches
                (list
-	        (llvm-patch "llvm-6.0-D44650.patch"
+	        (julia-patch "llvm-6.0-D44650"
 			    "1336q4vqayr94wdcnlmcxh90mjdh34dzw9x2cbiqjnx9b1j8fxyb")
-	        (llvm-patch "llvm-6.0-DISABLE_ABI_CHECKS.patch"
+	        (julia-patch "llvm-6.0-DISABLE_ABI_CHECKS"
 			    "014fawd1ba7yckalypfld22zgic87x9nx3cim42zrwygywd36pyg")
-	        (llvm-patch "llvm-6.0-NVPTX-addrspaces.patch"
+	        (julia-patch "llvm-6.0-NVPTX-addrspaces"
 			    "1qdi2zmrjsrj0h84zv2vyly2hjcn4f67mfy0s1q353g4v4jkscqc")
-	        (llvm-patch "llvm-6.0.0_D27296-libssp.patch"
+	        (julia-patch "llvm-6.0.0_D27296-libssp"
 			    "0s5hi2r1j63i8m6ig1346crx2aiv9f7rgb3mg80kw1wx5y7pdpfh")
-	        (llvm-patch "llvm-D27629-AArch64-large_model_6.0.1.patch"
+	        (julia-patch "llvm-D27629-AArch64-large_model_6.0.1"
 			    "1qrshmlqvnasdyc158vfn3hnbigqph3lsq7acb9w8lwkpnnm2j4z")
-	        (llvm-patch "llvm-D34078-vectorize-fdiv.patch"
+	        (julia-patch "llvm-D34078-vectorize-fdiv"
 			    "1696hg84a0jxcnggvqsc2cdp271hf9a44p4qsd078qm1mfawkaay")
-	        (llvm-patch "llvm-D42262-jumpthreading-not-i1.patch"
+	        (julia-patch "llvm-D42262-jumpthreading-not-i1"
 			    "1c8w210gwidbnkkw8anp17dk5pnxws2fl3mb2qxh7y9wzfpixgaq")
-	        (llvm-patch "llvm-D44892-Perf-integration.patch"
+	        (julia-patch "llvm-D44892-Perf-integration"
 			    "0r37jd0ssh2k1pndkfd5blgpg9z90im4vlzprhb0n0wwz45g4b05")
-	        (llvm-patch "llvm-D46460.patch"
+	        (julia-patch "llvm-D46460"
 			    "1miqgswdc0qvbaf4571c2xkxyp9ais06b1bcpa83sq22vr4hbsfb")
-	        (llvm-patch "llvm-D49832-SCEVPred.patch"
+	        (julia-patch "llvm-D49832-SCEVPred"
 			    "0v5c88hgqj6dymv3j86ca5mhpqab5fbnrvjiw1nvnrnya9l4dlbn")
-	        (llvm-patch "llvm-D50010-VNCoercion-ni.patch"
+	        (julia-patch "llvm-D50010-VNCoercion-ni"
 			    "0iblb3q1xixwrb12jpb89h3ywmqmzdp6aqp416j4ncwakyjhhfkp")
-	        (llvm-patch "llvm-D50167-scev-umin.patch"
+	        (julia-patch "llvm-D50167-scev-umin"
 			    "1f2rakcnnyhr7w10k7gqg0k0491pyvx5ijplivw557f714ys3q6v")
-	        (llvm-patch "llvm-OProfile-line-num.patch"
+	        (julia-patch "llvm-OProfile-line-num"
 			    "1jvbbmwyags0xfwamb13qrf3rgcz9i1r03m9lava7swag8xb78c7")
-	        (llvm-patch "llvm-PPC-addrspaces.patch"
+	        (julia-patch "llvm-PPC-addrspaces"
 			    "1f23nhsxh2s3jskbgs7da9nwg3s1hrkbk5aahl08x41wi3mny01p")
-	        (llvm-patch "llvm-rL323946-LSRTy.patch"
+	        (julia-patch "llvm-rL323946-LSRTy"
 			    "10cz3vy1yw0w643z7xx021wa4kymx9fcm3bjg61s6vzdqd6d9fns")
-	        (llvm-patch "llvm-rL326967-aligned-load.patch"
+	        (julia-patch "llvm-rL326967-aligned-load"
 			    "04jxnv32yj5x17hqhi8g2p8rhgp38gmjzr871w7z8s44pq10v9v4")
-	        (llvm-patch "llvm-rL327898.patch"
+	        (julia-patch "llvm-rL327898"
 			    "15ah49gbsll23z28kpyahi5vl0fh3fkxcgd1zmxxdcl96s3x8bnq")))))
     (arguments
      (substitute-keyword-arguments (package-arguments llvm-6)
@@ -158,7 +183,7 @@
 (define-public julia
   (package
     (name "julia")
-    (version "1.1.1")
+    (version "1.3.1")
     (source (origin
               (method url-fetch)
               (uri (string-append
@@ -166,7 +191,7 @@
                     version "/julia-" version ".tar.gz"))
               (sha256
                (base32
-                "0hk983mywimclgnjc41zmlppm5kfdz2aj85ky07p49ilcqxi998f"))))
+                "1nwkmr9j55g1zkxdchnid1h022s0is52vx23niksshgvh793g41x"))))
     (build-system gnu-build-system)
     (arguments
      `(#:test-target "test"
@@ -188,30 +213,24 @@
          (add-after 'unpack 'prepare-deps
            (lambda* (#:key inputs #:allow-other-keys)
              (mkdir "deps/srccache")
-             (copy-file (assoc-ref inputs "dsfmt")
-                        "deps/srccache/dsfmt-2.2.3.tar.gz")
+             ;; no USE_SYSTEM_{OBJCONV/LIBWHICH}
              (copy-file (assoc-ref inputs "objconv")
                         "deps/srccache/objconv.zip")
-             (copy-file (assoc-ref inputs "suitesparse")
-                        "deps/srccache/SuiteSparse-4.4.5.tar.gz")
-             (copy-file (string-append (assoc-ref inputs "virtualenv")
-                                       "/bin/virtualenv")
-                        "julia-env")
              (copy-file (assoc-ref inputs "libwhich")
                         (string-append "deps/srccache/libwhich-"
                                        "81e9723c0273d78493dc8c8ed570f68d9ce7e89e"
                                        ".tar.gz"))
-             (copy-file (assoc-ref inputs "rmath")
-                        "deps/srccache/Rmath-julia-0.1.tar.gz")
-
 	     ;; needed by libwhich
 	     (setenv "LD_LIBRARY_PATH"
 		     (string-join (map (lambda (pkg)
                                          (string-append (assoc-ref inputs pkg)
                                                         "/lib"))
-                                       '("arpack-ng" "fftw" "gmp" "lapack"
-			                 "libgit2" "mpfr" "openblas" "openlibm"
-			                 "openspecfun" "pcre2"))
+                                       '("arpack-ng" "curl" "dsfmt"
+                                         "gmp" "lapack"
+                                         "libssh2" "libgit2"
+                                         "mbedtls" "mpfr"
+                                         "openblas" "openlibm" "pcre2"
+                                         "suitesparse"))
                                   ":"))
 	     #t))
          ;; FIXME: Building the documentation requires Julia packages that
@@ -233,44 +252,12 @@
           ;; using the output of "/sbin/ldconfig -p".  Since ldconfig is not
           ;; used in Guix, we patch runtime_ccall.cpp to contain a static map.
           (lambda* (#:key inputs #:allow-other-keys)
-            (use-modules (ice-9 match))
-            (substitute* "src/runtime_ccall.cpp"
-              ;; Patch out invocations of '/sbin/ldconfig' to avoid getting
-              ;; error messages about missing '/sbin/ldconfig' on Guix System.
-              (("popen\\(.*ldconfig.*\\);")
-               "NULL;\n")
-
-              ;; Populate 'sonameMap'.
-              (("jl_read_sonames.*;")
-               (string-join
-                (map (match-lambda
-                       ((input libname soname)
-                        (string-append
-                         "sonameMap[\"" libname "\"] = "
-                         "\"" (assoc-ref inputs input) "/lib/" soname "\";")))
-                     '(("libc"        "libc"           "libc.so.6")
-                       ("pcre2"       "libpcre2-8"     "libpcre2-8.so")
-                       ("mpfr"        "libmpfr"        "libmpfr.so")
-                       ("openblas"    "libblas"        "libopenblas.so")
-                       ("arpack-ng"   "libarpack"      "libarpack.so")
-                       ("lapack"      "liblapack"      "liblapack.so")
-                       ("libgit2"     "libgit2"        "libgit2.so")
-                       ("gmp"         "libgmp"         "libgmp.so")
-                       ("openspecfun" "libopenspecfun" "libopenspecfun.so")
-                       ("fftw"        "libfftw3"       "libfftw3_threads.so")
-                       ("fftwf"       "libfftw3f"      "libfftw3f_threads.so"))))))
             (substitute* "base/math.jl"
               (("const libm = Base.libm_name")
                (string-append "const libm = \""
                               (assoc-ref inputs "openlibm")
                               "/lib/libopenlibm.so"
-                              "\""))
-              (("const openspecfun = \"libopenspecfun\"")
-               (string-append "const openspecfun = \""
-                              (assoc-ref inputs "openspecfun")
-                              "/lib/libopenspecfun.so"
-                              "\"")))
-            #t))
+                              "\"")))))
          (add-before 'build 'fix-include-and-link-paths
           (lambda* (#:key inputs #:allow-other-keys)
             ;; LIBUTF8PROC is a linker flag, not a build target.  It is
@@ -278,10 +265,10 @@
             ;; collection of build targets and a list of libraries to link
             ;; against.
             (substitute* "src/flisp/Makefile"
-              (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\): \\$\\(OBJS\\) \\$\\(LIBFILES_release\\)")
-               "$(BUILDDIR)/$(EXENAME): $(OBJS) $(LLT_release)")
-              (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)-debug: \\$\\(DOBJS\\) \\$\\(LIBFILES_debug\\)")
-               "$(BUILDDIR)/$(EXENAME)-debug: $(DOBJS) $(LLT_debug)"))
+               (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)\\$\\(EXE\\): \\$\\(OBJS\\) \\$\\(LIBFILES_release\\)")
+                "$(BUILDDIR)/$(EXENAME)$(EXE): $(OBJS) $(LLT_release)")
+               (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)-debug$(EXE): \\$\\(DOBJS\\) \\$\\(LIBFILES_debug\\)")
+                "$(BUILDDIR)/$(EXENAME)-debug\\$\\(EXE\\): $(DOBJS) $(LLT_debug)"))
 
             ;; The REPL must be linked with libuv.
             (substitute* "ui/Makefile"
@@ -296,38 +283,28 @@
                               "/include/uv/errno.h")))
             #t))
          (add-before 'build 'replace-default-shell
-          (lambda _
-            (substitute* "base/client.jl"
-              (("/bin/sh") (which "sh")))
-            #t))
-         (add-after 'unpack 'hardcode-paths
            (lambda _
-             (substitute* "stdlib/InteractiveUtils/src/InteractiveUtils.jl"
-               (("`which") (string-append "`" (which "which")))
-               (("`wget")  (string-append "`" (which "wget"))))
+             (substitute* "base/client.jl"
+               (("/bin/sh") (which "sh")))
              #t))
-         (add-before 'check 'disable-broken-tests
+         (add-before 'check 'fix-broken-tests
            (lambda _
-             (define (touch file-name)
-               (call-with-output-file file-name (const #t)))
-	     ;; FIXME: All git tests works except this one. But *THIS* "fix"
-             ;; is not working, so right now I'm disabling all libgit2.jl tests
-	     ;; (substitute* "stdlib/LibGit2/test/libgit2.jl"
-	     ;; (("!LibGit2.use_http_path(cfg, github_cred)") "true")
-	     ;; (("LibGit2.use_http_path(cfg, mygit_cred)") "true"))
-             (map (lambda (test)
-                    (delete-file test)
-                    (touch test))
-	          '("stdlib/Sockets/test/runtests.jl"
-		    "stdlib/Distributed/test/runtests.jl"
-                    ;; FIXME: see above
-		    "stdlib/LibGit2/test/libgit2.jl"))
-	     (substitute* "test/choosetests.jl"
-	       ;; These tests fail, probably because some of the input
-	       ;; binaries have been stripped and thus backtraces don't look
-	       ;; as expected.
-	       (("\"backtrace\",") "")
-	       (("\"cmdlineargs\",") ""))
+             (substitute* "test/choosetests.jl"
+               (("tests = testnames")
+                ;; Those failings are not deterministic.  They depends on the
+                ;; running order.  I think it depends on the number of
+                ;; runners, disabling it for now
+                ;; https://github.com/JuliaLang/julia/issues/34330
+                "tests = filter(e->!in(e,[\"backtrace\",\"exceptions\",\"client\",\"stacktraces\"]),testnames)"))
+             ;; When HOME is not set, julia calls uv_os_homedir, which in
+             ;; turns call getpwuid_r. Add the HOME env variable to the
+             ;; external julia call to fix this
+             (substitute* "test/cmdlineargs.jl"
+               (("\"JULIA_PROJECT\"") "\"HOME\"=>\"/tmp\", \"JULIA_PROJECT\""))
+             ;; Marking the test as broken as it's a known bug:
+             ;; https://github.com/JuliaLang/julia/issues/32377
+             (substitute* "stdlib/REPL/test/replcompletions.jl"
+               (("@test count") "@test_broken count"))
 	     #t)))
        #:make-flags
        (list
@@ -345,26 +322,21 @@
            ;; platforms, e.g. when running "guix package --search="
            (_ "MARCH=UNSUPPORTED"))
 
-        "CONFIG_SHELL=bash"     ;needed to build bundled libraries
-        "USE_SYSTEM_DSFMT=0"    ;not packaged for Guix and upstream has no
-                                ;build system for a shared library.
+        "CONFIG_SHELL=bash"             ;needed to build bundled libraries
+        ;; list of "USE_SYSTEM_*" is here:
+        ;; https://github.com/JuliaLang/julia/blob/v1.3.1/Make.inc
+        "USE_SYSTEM_DSFMT=1"
+        "USE_SYSTEM_P7ZIP=1"
         "USE_SYSTEM_LAPACK=1"
         "USE_SYSTEM_BLAS=1"
         "USE_BLAS64=0"          ;needed when USE_SYSTEM_BLAS=1
         "LIBBLAS=-lopenblas"
         "LIBBLASNAME=libopenblas"
 
-        "USE_SYSTEM_FFTW=1"
-        "LIBFFTWNAME=libfftw3"
-        "LIBFFTWFNAME=libfftw3f"
-
-        ;; TODO: Suitesparse does not install shared libraries, so we cannot
-        ;; use the suitesparse package.
-        ;; "USE_SYSTEM_SUITESPARSE=1"
-        ;; (string-append "SUITESPARSE_INC=-I "
-        ;;                (assoc-ref %build-inputs "suitesparse")
-        ;;                "/include")
-
+        "USE_SYSTEM_SUITESPARSE=1"
+        (string-append "SUITESPARSE_INC=-I "
+                       (assoc-ref %build-inputs "suitesparse")
+                       "/include")
         "USE_GPL_LIBS=1"        ;proudly
         "USE_SYSTEM_UTF8PROC=1"
         (string-append "UTF8PROC_INC="
@@ -385,16 +357,19 @@
 	"USE_SYSTEM_PATCHELF=1"
 	"USE_SYSTEM_PCRE=1"
 	"USE_SYSTEM_OPENLIBM=1"
-
+        "USE_SYSTEM_LIBM=0"
+        "USE_SYSTEM_LIBSSH2=1"
+        "USE_SYSTEM_CURL=1"
 	"USE_SYSTEM_GMP=1"
 	"USE_SYSTEM_MPFR=1"
+	"USE_SYSTEM_MBEDTLS=1"
 	"USE_SYSTEM_ARPACK=1"
 	"USE_SYSTEM_LIBGIT2=1"
-	"USE_SYSTEM_ZLIB=1"
-	"USE_SYSTEM_OPENSPECFUN=1")))
+	"USE_SYSTEM_ZLIB=1")))
     (inputs
      `(("llvm" ,llvm-julia)
 
+       ("p7zip" ,p7zip)
        ;; The bundled version is 3.3.0 so stick to that version.  With other
        ;; versions, we get test failures in 'linalg/arnoldi' as described in
        ;; <https://bugs.gnu.org/30282>.
@@ -403,12 +378,12 @@
        ("coreutils" ,coreutils) ;for bindings to "mkdir" and the like
        ("lapack" ,lapack)
        ("openblas" ,openblas) ;Julia does not build with Atlas
-       ("libunwind" ,libunwind)
+       ("libunwind" ,libunwind-julia)
        ("openlibm" ,openlibm)
-       ("openspecfun" ,openspecfun)
+       ("mbedtls" ,mbedtls-apache)
+       ("curl" ,curl)
        ("libgit2" ,libgit2)
-       ("fftw" ,fftw)
-       ("fftwf" ,fftwf)
+       ("libssh2" ,libssh2)
        ("fortran" ,gfortran)
        ("libuv" ,libuv-julia)
        ("pcre2" ,pcre2)
@@ -418,31 +393,12 @@
        ("which" ,which)
        ("zlib" ,zlib)
        ("gmp" ,gmp)
-       ("virtualenv" ,python2-virtualenv)
+       ("suitesparse" ,suitesparse)
        ;; FIXME: The following inputs are downloaded from upstream to allow us
        ;; to use the lightweight Julia release tarball.  Ideally, these inputs
        ;; would eventually be replaced with proper Guix packages.
-
-       ;; TODO: run "make -f contrib/repackage_system_suitesparse4.make" to copy static lib
-       ;; Find dependency versions here:
-       ;; https://raw.githubusercontent.com/JuliaLang/julia/77a2c1e245c85812dc1c7687540beedecc52758f/deps/Versions.make
-       ("rmath"
-	,(origin
-	   (method git-fetch)
-	   (uri (git-reference
-                 (url "https://github.com/JuliaLang/Rmath-julia")
-                 (commit "v0.1")))
-           (file-name "rmath-julia-0.1-checkout")
-	   (sha256
-	    (base32
-	     "1zkpy0cg5zivq40zbhbdgj9128fqzs2j94wkwih8nc6xaj3gp9p6"))))
-       ("suitesparse"
-        ,(origin
-           (method url-fetch)
-           (uri "http://faculty.cse.tamu.edu/davis/SuiteSparse/SuiteSparse-4.4.5.tar.gz")
-           (sha256
-            (base32
-             "1jcbxb8jx5wlcixzf6n5dca2rcfx6mlcms1k2rl5gp67ay3bix43"))))
+       ;; Find dependencies versions here:
+       ;; https://raw.githubusercontent.com/JuliaLang/julia/v1.3.0/deps/Versions.make
        ("objconv"
         ,(origin
            (method url-fetch)
@@ -467,15 +423,7 @@
 	     (sha256
 	      (base32
 	       "1p7zg31kpmpbmh1znrk1xrbd074agx13b9q4dcw8n2zrwwdlbz3b")))))
-       ("dsfmt"
-        ,(origin
-           (method url-fetch)
-           (uri (string-append
-                 "http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/"
-                 "SFMT/dSFMT-src-2.2.3.tar.gz"))
-           (sha256
-            (base32
-             "03kaqbjbi6viz0n33dk5jlf6ayxqlsq4804n7kwkndiga9s4hd42"))))))
+       ("dsfmt" ,dsfmt)))
     (native-inputs
      `(("openssl" ,openssl)
        ("perl" ,perl)
-- 
2.24.1

>From aa245450a7c8a92c29388cc6603ff43f278dfdd7 Mon Sep 17 00:00:00 2001
From: nixo <[email-masked]>
Date: Sat, 18 Jan 2020 13:58:37 +0100
Subject: [PATCH 02/11] gnu: julia: use SOURCE_DATE_EPOCH for precompilation
 timestamp

* gnu/packages/patches/julia-fake-mtime-with-SOURCE_DATE_EPOCH.patch: new file
---
 gnu/local.mk                                  |  1 +
 gnu/packages/julia.scm                        |  4 ++-
 ...ia-fake-mtime-with-SOURCE_DATE_EPOCH.patch | 29 +++++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/julia-fake-mtime-with-SOURCE_DATE_EPOCH.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 00ff3b8d61..fe8634b44d 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1010,6 +1010,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/java-xerces-bootclasspath.patch	\
   %D%/packages/patches/java-xerces-build_dont_unzip.patch	\
   %D%/packages/patches/java-xerces-xjavac_taskdef.patch	\
+  %D%/packages/patches/julia-SOURCE_DATE_EPOCH-mtime.patch      \
   %D%/packages/patches/jbig2dec-ignore-testtest.patch		\
   %D%/packages/patches/kdbusaddons-kinit-file-name.patch	\
   %D%/packages/patches/libvirt-create-machine-cgroup.patch	\
diff --git a/gnu/packages/julia.scm b/gnu/packages/julia.scm
index e4db39afbd..a66309b611 100644
--- a/gnu/packages/julia.scm
+++ b/gnu/packages/julia.scm
@@ -191,7 +191,9 @@
                     version "/julia-" version ".tar.gz"))
               (sha256
                (base32
-                "1nwkmr9j55g1zkxdchnid1h022s0is52vx23niksshgvh793g41x"))))
+                "1nwkmr9j55g1zkxdchnid1h022s0is52vx23niksshgvh793g41x"))
+              (patches
+               (search-patches "julia-fake-mtime-with-SOURCE_DATE_EPOCH.patch"))))
     (build-system gnu-build-system)
     (arguments
      `(#:test-target "test"
diff --git a/gnu/packages/patches/julia-fake-mtime-with-SOURCE_DATE_EPOCH.patch b/gnu/packages/patches/julia-fake-mtime-with-SOURCE_DATE_EPOCH.patch
new file mode 100644
index 0000000000..467e6d68d1
--- /dev/null
+++ b/gnu/packages/patches/julia-fake-mtime-with-SOURCE_DATE_EPOCH.patch
@@ -0,0 +1,29 @@
+From e4dc28db1d70819505fd1a68fd9d2bfc4fb61a7d Mon Sep 17 00:00:00 2001
+From: nixo <[email-masked]>
+Date: Fri, 17 Jan 2020 11:28:30 +0100
+Subject: [PATCH] base: loading: support fake mtime with SOURCE_DATE_EPCOCH
+
+Do this when loading libraries
+---
+ base/loading.jl | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+diff --git a/base/loading.jl b/base/loading.jl
+index 7f11a2d4fc..1b4686d1dc 100644
+--- a/base/loading.jl
++++ b/base/loading.jl
+@@ -807,7 +807,10 @@ function _include_dependency(mod::Module, _path::AbstractString)
+         path = normpath(joinpath(dirname(prev), _path))
+     end
+     if _track_dependencies[]
+-        push!(_require_dependencies, (mod, path, mtime(path)))
++        push!(_require_dependencies,
++              (mod, path,
++               haskey(ENV, "SOURCE_DATE_EPOCH") ?
++               parse(Float64, ENV["SOURCE_DATE_EPOCH"]) : mtime(path)))
+     end
+     return path, prev
+ end
+-- 
+2.24.1
+
-- 
2.24.1

>From 66a9b56bfbc66d5c4c21e5f67c6f759a7f838786 Mon Sep 17 00:00:00 2001
From: nixo <[email-masked]>
Date: Fri, 10 Jan 2020 10:25:49 +0100
Subject: [PATCH 03/11] gnu: julia: Adjust indentation.

* gnu/packages/julia.scm (julia): Correct indentation, untabify
---
 gnu/packages/julia.scm | 216 ++++++++++++++++++++---------------------
 1 file changed, 108 insertions(+), 108 deletions(-)

diff --git a/gnu/packages/julia.scm b/gnu/packages/julia.scm
index a66309b611..e1c4685227 100644
--- a/gnu/packages/julia.scm
+++ b/gnu/packages/julia.scm
@@ -51,14 +51,14 @@
 
 (define (julia-patch-url version name)
   (string-append "https://raw.githubusercontent.com/JuliaLang/julia/v" version
-		 "/deps/patches/" name ".patch"))
+                 "/deps/patches/" name ".patch"))
 
 (define (julia-patch name sha)
   (let ((version "1.3.1"))
     (origin (method url-fetch)
-	    (uri (julia-patch-url version name))
-	    (sha256 (base32 sha))
-	    (file-name name))))
+            (uri (julia-patch-url version name))
+            (sha256 (base32 sha))
+            (file-name name))))
 
 (define libuv-julia
   (let ((commit "35b1504507a7a4168caae3d78db54d1121b121e1"))
@@ -101,7 +101,7 @@
                 "1y0l08k6ak1mqbfj6accf9s5686kljwgsl4vcqpxzk5n74wpm6a3"))
               (patches
                (list
-	        (julia-patch "libunwind-prefer-extbl"
+                (julia-patch "libunwind-prefer-extbl"
                              "0lr4dafw8qyfh8sw8hhbwkql1dlhqv8px7k81y2l20hhxfgnh2m1")
                 (julia-patch "libunwind-static-arm"
                              "1jk3bmiw61ypcchqkk1fyg5wh8wpggk574wxyfyaic870zh3lhgq")))))
@@ -124,45 +124,45 @@
               ;; Discussion: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=919628
               (patches
                (list
-	        (julia-patch "llvm-6.0-D44650"
-			    "1336q4vqayr94wdcnlmcxh90mjdh34dzw9x2cbiqjnx9b1j8fxyb")
-	        (julia-patch "llvm-6.0-DISABLE_ABI_CHECKS"
-			    "014fawd1ba7yckalypfld22zgic87x9nx3cim42zrwygywd36pyg")
-	        (julia-patch "llvm-6.0-NVPTX-addrspaces"
-			    "1qdi2zmrjsrj0h84zv2vyly2hjcn4f67mfy0s1q353g4v4jkscqc")
-	        (julia-patch "llvm-6.0.0_D27296-libssp"
-			    "0s5hi2r1j63i8m6ig1346crx2aiv9f7rgb3mg80kw1wx5y7pdpfh")
-	        (julia-patch "llvm-D27629-AArch64-large_model_6.0.1"
-			    "1qrshmlqvnasdyc158vfn3hnbigqph3lsq7acb9w8lwkpnnm2j4z")
-	        (julia-patch "llvm-D34078-vectorize-fdiv"
-			    "1696hg84a0jxcnggvqsc2cdp271hf9a44p4qsd078qm1mfawkaay")
-	        (julia-patch "llvm-D42262-jumpthreading-not-i1"
-			    "1c8w210gwidbnkkw8anp17dk5pnxws2fl3mb2qxh7y9wzfpixgaq")
-	        (julia-patch "llvm-D44892-Perf-integration"
-			    "0r37jd0ssh2k1pndkfd5blgpg9z90im4vlzprhb0n0wwz45g4b05")
-	        (julia-patch "llvm-D46460"
-			    "1miqgswdc0qvbaf4571c2xkxyp9ais06b1bcpa83sq22vr4hbsfb")
-	        (julia-patch "llvm-D49832-SCEVPred"
-			    "0v5c88hgqj6dymv3j86ca5mhpqab5fbnrvjiw1nvnrnya9l4dlbn")
-	        (julia-patch "llvm-D50010-VNCoercion-ni"
-			    "0iblb3q1xixwrb12jpb89h3ywmqmzdp6aqp416j4ncwakyjhhfkp")
-	        (julia-patch "llvm-D50167-scev-umin"
-			    "1f2rakcnnyhr7w10k7gqg0k0491pyvx5ijplivw557f714ys3q6v")
-	        (julia-patch "llvm-OProfile-line-num"
-			    "1jvbbmwyags0xfwamb13qrf3rgcz9i1r03m9lava7swag8xb78c7")
-	        (julia-patch "llvm-PPC-addrspaces"
-			    "1f23nhsxh2s3jskbgs7da9nwg3s1hrkbk5aahl08x41wi3mny01p")
-	        (julia-patch "llvm-rL323946-LSRTy"
-			    "10cz3vy1yw0w643z7xx021wa4kymx9fcm3bjg61s6vzdqd6d9fns")
-	        (julia-patch "llvm-rL326967-aligned-load"
-			    "04jxnv32yj5x17hqhi8g2p8rhgp38gmjzr871w7z8s44pq10v9v4")
-	        (julia-patch "llvm-rL327898"
-			    "15ah49gbsll23z28kpyahi5vl0fh3fkxcgd1zmxxdcl96s3x8bnq")))))
+                (julia-patch "llvm-6.0-D44650"
+                            "1336q4vqayr94wdcnlmcxh90mjdh34dzw9x2cbiqjnx9b1j8fxyb")
+                (julia-patch "llvm-6.0-DISABLE_ABI_CHECKS"
+                            "014fawd1ba7yckalypfld22zgic87x9nx3cim42zrwygywd36pyg")
+                (julia-patch "llvm-6.0-NVPTX-addrspaces"
+                            "1qdi2zmrjsrj0h84zv2vyly2hjcn4f67mfy0s1q353g4v4jkscqc")
+                (julia-patch "llvm-6.0.0_D27296-libssp"
+                            "0s5hi2r1j63i8m6ig1346crx2aiv9f7rgb3mg80kw1wx5y7pdpfh")
+                (julia-patch "llvm-D27629-AArch64-large_model_6.0.1"
+                            "1qrshmlqvnasdyc158vfn3hnbigqph3lsq7acb9w8lwkpnnm2j4z")
+                (julia-patch "llvm-D34078-vectorize-fdiv"
+                            "1696hg84a0jxcnggvqsc2cdp271hf9a44p4qsd078qm1mfawkaay")
+                (julia-patch "llvm-D42262-jumpthreading-not-i1"
+                            "1c8w210gwidbnkkw8anp17dk5pnxws2fl3mb2qxh7y9wzfpixgaq")
+                (julia-patch "llvm-D44892-Perf-integration"
+                            "0r37jd0ssh2k1pndkfd5blgpg9z90im4vlzprhb0n0wwz45g4b05")
+                (julia-patch "llvm-D46460"
+                            "1miqgswdc0qvbaf4571c2xkxyp9ais06b1bcpa83sq22vr4hbsfb")
+                (julia-patch "llvm-D49832-SCEVPred"
+                            "0v5c88hgqj6dymv3j86ca5mhpqab5fbnrvjiw1nvnrnya9l4dlbn")
+                (julia-patch "llvm-D50010-VNCoercion-ni"
+                            "0iblb3q1xixwrb12jpb89h3ywmqmzdp6aqp416j4ncwakyjhhfkp")
+                (julia-patch "llvm-D50167-scev-umin"
+                            "1f2rakcnnyhr7w10k7gqg0k0491pyvx5ijplivw557f714ys3q6v")
+                (julia-patch "llvm-OProfile-line-num"
+                            "1jvbbmwyags0xfwamb13qrf3rgcz9i1r03m9lava7swag8xb78c7")
+                (julia-patch "llvm-PPC-addrspaces"
+                            "1f23nhsxh2s3jskbgs7da9nwg3s1hrkbk5aahl08x41wi3mny01p")
+                (julia-patch "llvm-rL323946-LSRTy"
+                            "10cz3vy1yw0w643z7xx021wa4kymx9fcm3bjg61s6vzdqd6d9fns")
+                (julia-patch "llvm-rL326967-aligned-load"
+                            "04jxnv32yj5x17hqhi8g2p8rhgp38gmjzr871w7z8s44pq10v9v4")
+                (julia-patch "llvm-rL327898"
+                            "15ah49gbsll23z28kpyahi5vl0fh3fkxcgd1zmxxdcl96s3x8bnq")))))
     (arguments
      (substitute-keyword-arguments (package-arguments llvm-6)
        ((#:configure-flags flags)
         `(list ;; Taken from NixOS. Only way I could get libLLVM-6.0.so
-	  "-DCMAKE_BUILD_TYPE=Release"
+          "-DCMAKE_BUILD_TYPE=Release"
 
           ;; Build a native compiler and the NVPTX backend (NVIDIA) since
           ;; Julia insists on it, nothing more.  This reduces build times and
@@ -170,15 +170,15 @@
           ,(string-append "-DLLVM_TARGETS_TO_BUILD=" (system->llvm-target))
           "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=NVPTX"
 
-	  "-DLLVM_INSTALL_UTILS=ON"
-	  "-DLLVM_BUILD_TESTS=ON"
-	  "-DLLVM_ENABLE_FFI=ON"
-	  "-DLLVM_ENABLE_RTTI=ON"
+          "-DLLVM_INSTALL_UTILS=ON"
+          "-DLLVM_BUILD_TESTS=ON"
+          "-DLLVM_ENABLE_FFI=ON"
+          "-DLLVM_ENABLE_RTTI=ON"
           ;; "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
           ;; "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
-	  ;; "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly"
-	  "-DLLVM_ENABLE_DUMP=ON"
-	  "-DLLVM_LINK_LLVM_DYLIB=ON"))))))
+          ;; "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly"
+          "-DLLVM_ENABLE_DUMP=ON"
+          "-DLLVM_LINK_LLVM_DYLIB=ON"))))))
 
 (define-public julia
   (package
@@ -222,9 +222,9 @@
                         (string-append "deps/srccache/libwhich-"
                                        "81e9723c0273d78493dc8c8ed570f68d9ce7e89e"
                                        ".tar.gz"))
-	     ;; needed by libwhich
-	     (setenv "LD_LIBRARY_PATH"
-		     (string-join (map (lambda (pkg)
+             ;; needed by libwhich
+             (setenv "LD_LIBRARY_PATH"
+                     (string-join (map (lambda (pkg)
                                          (string-append (assoc-ref inputs pkg)
                                                         "/lib"))
                                        '("arpack-ng" "curl" "dsfmt"
@@ -234,7 +234,7 @@
                                          "openblas" "openlibm" "pcre2"
                                          "suitesparse"))
                                   ":"))
-	     #t))
+             #t))
          ;; FIXME: Building the documentation requires Julia packages that
          ;; would be downloaded from the Internet.  We should build them in a
          ;; separate build phase.
@@ -250,40 +250,40 @@
            ;; Some tests require a home directory to be set.
            (lambda _ (setenv "HOME" "/tmp") #t))
          (add-after 'unpack 'hardcode-soname-map
-          ;; ./src/runtime_ccall.cpp creates a map from library names to paths
-          ;; using the output of "/sbin/ldconfig -p".  Since ldconfig is not
-          ;; used in Guix, we patch runtime_ccall.cpp to contain a static map.
-          (lambda* (#:key inputs #:allow-other-keys)
-            (substitute* "base/math.jl"
-              (("const libm = Base.libm_name")
-               (string-append "const libm = \""
-                              (assoc-ref inputs "openlibm")
-                              "/lib/libopenlibm.so"
-                              "\"")))))
+           ;; ./src/runtime_ccall.cpp creates a map from library names to paths
+           ;; using the output of "/sbin/ldconfig -p".  Since ldconfig is not
+           ;; used in Guix, we patch runtime_ccall.cpp to contain a static map.
+           (lambda* (#:key inputs #:allow-other-keys)
+             (substitute* "base/math.jl"
+               (("const libm = Base.libm_name")
+                (string-append "const libm = \""
+                               (assoc-ref inputs "openlibm")
+                               "/lib/libopenlibm.so"
+                               "\"")))))
          (add-before 'build 'fix-include-and-link-paths
-          (lambda* (#:key inputs #:allow-other-keys)
-            ;; LIBUTF8PROC is a linker flag, not a build target.  It is
-            ;; included in the LIBFILES_* variable which is used as a
-            ;; collection of build targets and a list of libraries to link
-            ;; against.
-            (substitute* "src/flisp/Makefile"
+           (lambda* (#:key inputs #:allow-other-keys)
+             ;; LIBUTF8PROC is a linker flag, not a build target.  It is
+             ;; included in the LIBFILES_* variable which is used as a
+             ;; collection of build targets and a list of libraries to link
+             ;; against.
+             (substitute* "src/flisp/Makefile"
                (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)\\$\\(EXE\\): \\$\\(OBJS\\) \\$\\(LIBFILES_release\\)")
                 "$(BUILDDIR)/$(EXENAME)$(EXE): $(OBJS) $(LLT_release)")
                (("\\$\\(BUILDDIR\\)/\\$\\(EXENAME\\)-debug$(EXE): \\$\\(DOBJS\\) \\$\\(LIBFILES_debug\\)")
                 "$(BUILDDIR)/$(EXENAME)-debug\\$\\(EXE\\): $(DOBJS) $(LLT_debug)"))
 
-            ;; The REPL must be linked with libuv.
-            (substitute* "ui/Makefile"
-              (("JLDFLAGS \\+= ")
-               (string-append "JLDFLAGS += "
-                              (assoc-ref %build-inputs "libuv")
-                              "/lib/libuv.so ")))
+             ;; The REPL must be linked with libuv.
+             (substitute* "ui/Makefile"
+               (("JLDFLAGS \\+= ")
+                (string-append "JLDFLAGS += "
+                               (assoc-ref %build-inputs "libuv")
+                               "/lib/libuv.so ")))
 
-            (substitute* "base/Makefile"
-              (("\\$\\(build_includedir\\)/uv/errno.h")
-               (string-append (assoc-ref inputs "libuv")
-                              "/include/uv/errno.h")))
-            #t))
+             (substitute* "base/Makefile"
+               (("\\$\\(build_includedir\\)/uv/errno.h")
+                (string-append (assoc-ref inputs "libuv")
+                               "/include/uv/errno.h")))
+             #t))
          (add-before 'build 'replace-default-shell
            (lambda _
              (substitute* "base/client.jl"
@@ -307,7 +307,7 @@
              ;; https://github.com/JuliaLang/julia/issues/32377
              (substitute* "stdlib/REPL/test/replcompletions.jl"
                (("@test count") "@test_broken count"))
-	     #t)))
+             #t)))
        #:make-flags
        (list
         (string-append "prefix=" (assoc-ref %outputs "out"))
@@ -331,7 +331,7 @@
         "USE_SYSTEM_P7ZIP=1"
         "USE_SYSTEM_LAPACK=1"
         "USE_SYSTEM_BLAS=1"
-        "USE_BLAS64=0"          ;needed when USE_SYSTEM_BLAS=1
+        "USE_BLAS64=0"                  ;needed when USE_SYSTEM_BLAS=1
         "LIBBLAS=-lopenblas"
         "LIBBLASNAME=libopenblas"
 
@@ -339,35 +339,35 @@
         (string-append "SUITESPARSE_INC=-I "
                        (assoc-ref %build-inputs "suitesparse")
                        "/include")
-        "USE_GPL_LIBS=1"        ;proudly
+        "USE_GPL_LIBS=1"                ;proudly
         "USE_SYSTEM_UTF8PROC=1"
         (string-append "UTF8PROC_INC="
                        (assoc-ref %build-inputs "utf8proc")
                        "/include")
         "USE_SYSTEM_LLVM=1"
-	"LLVM_VER=6.0.1"
+        "LLVM_VER=6.0.1"
 
-	"USE_LLVM_SHLIB=1"
-	"USE_SYSTEM_LIBUNWIND=1"
-	"USE_SYSTEM_LIBUV=1"
-	(string-append "LIBUV="
-		       (assoc-ref %build-inputs "libuv")
-		       "/lib/libuv.so")
-	(string-append "LIBUV_INC="
-		       (assoc-ref %build-inputs "libuv")
-		       "/include")
-	"USE_SYSTEM_PATCHELF=1"
-	"USE_SYSTEM_PCRE=1"
-	"USE_SYSTEM_OPENLIBM=1"
+        "USE_LLVM_SHLIB=1"
+        "USE_SYSTEM_LIBUNWIND=1"
+        "USE_SYSTEM_LIBUV=1"
+        (string-append "LIBUV="
+                       (assoc-ref %build-inputs "libuv")
+                       "/lib/libuv.so")
+        (string-append "LIBUV_INC="
+                       (assoc-ref %build-inputs "libuv")
+                       "/include")
+        "USE_SYSTEM_PATCHELF=1"
+        "USE_SYSTEM_PCRE=1"
+        "USE_SYSTEM_OPENLIBM=1"
         "USE_SYSTEM_LIBM=0"
         "USE_SYSTEM_LIBSSH2=1"
         "USE_SYSTEM_CURL=1"
-	"USE_SYSTEM_GMP=1"
-	"USE_SYSTEM_MPFR=1"
-	"USE_SYSTEM_MBEDTLS=1"
-	"USE_SYSTEM_ARPACK=1"
-	"USE_SYSTEM_LIBGIT2=1"
-	"USE_SYSTEM_ZLIB=1")))
+        "USE_SYSTEM_GMP=1"
+        "USE_SYSTEM_MPFR=1"
+        "USE_SYSTEM_MBEDTLS=1"
+        "USE_SYSTEM_ARPACK=1"
+        "USE_SYSTEM_LIBGIT2=1"
+        "USE_SYSTEM_ZLIB=1")))
     (inputs
      `(("llvm" ,llvm-julia)
 
@@ -377,9 +377,9 @@
        ;; <https://bugs.gnu.org/30282>.
        ("arpack-ng" ,arpack-ng-3.3.0)
 
-       ("coreutils" ,coreutils) ;for bindings to "mkdir" and the like
+       ("coreutils" ,coreutils)         ;for bindings to "mkdir" and the like
        ("lapack" ,lapack)
-       ("openblas" ,openblas) ;Julia does not build with Atlas
+       ("openblas" ,openblas)           ;Julia does not build with Atlas
        ("libunwind" ,libunwind-julia)
        ("openlibm" ,openlibm)
        ("mbedtls" ,mbedtls-apache)
@@ -411,20 +411,20 @@
             (base32
              "0wp6ld9vk11f4nnkn56627zmlv9k5vafi99qa3yyn1pgcd61zcfs"))))
        ("libwhich"
-	,(let ((commit "81e9723c0273d78493dc8c8ed570f68d9ce7e89e"))
+        ,(let ((commit "81e9723c0273d78493dc8c8ed570f68d9ce7e89e"))
            (origin
              ;; Note: We use a /tarball URL, but that's because Julia's build
              ;; system checks the hash of that tarball; thus we can't use
              ;; 'git-fetch'.
-	     (method url-fetch)
-	     (uri (string-append
+             (method url-fetch)
+             (uri (string-append
                    "https://api.github.com/repos/vtjnash/libwhich/tarball/"
                    commit))
              (file-name (string-append "libwhich-" (string-take commit 7)
                                        ".tar.gz"))
-	     (sha256
-	      (base32
-	       "1p7zg31kpmpbmh1znrk1xrbd074agx13b9q4dcw8n2zrwwdlbz3b")))))
+             (sha256
+              (base32
+               "1p7zg31kpmpbmh1znrk1xrbd074agx13b9q4dcw8n2zrwwdlbz3b")))))
        ("dsfmt" ,dsfmt)))
     (native-inputs
      `(("openssl" ,openssl)
-- 
2.24.1

>From fe1f84062e88b6e4d77f35f12d7219fd47687c3a Mon Sep 17 00:00:00 2001
From: nixo <[email-masked]>
Date: Sat, 18 Jan 2020 14:23:44 +0100
Subject: [PATCH 04/11] use wrapper to set JULIA_LOAD_PATH and JULIA_DEPOT_PATH

---
 gnu/packages/julia.scm | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/julia.scm b/gnu/packages/julia.scm
index e1c4685227..39c7d6d34f 100644
--- a/gnu/packages/julia.scm
+++ b/gnu/packages/julia.scm
@@ -297,7 +297,9 @@
                 ;; running order.  I think it depends on the number of
                 ;; runners, disabling it for now
                 ;; https://github.com/JuliaLang/julia/issues/34330
-                "tests = filter(e->!in(e,[\"backtrace\",\"exceptions\",\"client\",\"stacktraces\"]),testnames)"))
+                "tests = filter(e->!in(e,[\"backtrace\",\"exceptions\",\"client\",
+                                          \"stacktraces\",\"stress\",\"precompile\"]),
+                                testnames)"))
              ;; When HOME is not set, julia calls uv_os_homedir, which in
              ;; turns call getpwuid_r. Add the HOME env variable to the
              ;; external julia call to fix this
@@ -307,11 +309,23 @@
              ;; https://github.com/JuliaLang/julia/issues/32377
              (substitute* "stdlib/REPL/test/replcompletions.jl"
                (("@test count") "@test_broken count"))
-             #t)))
+             #t))
+         (add-after 'install 'make-wrapper
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (bin (string-append out "/bin"))
+                    (program "julia"))
+               (with-directory-excursion bin
+                 (wrap-program program
+                   `("JULIA_LOAD_PATH" ":" prefix
+                     ("" "$JULIA_LOAD_PATH")))
+                 (wrap-program program
+                   `("JULIA_DEPOT_PATH" ":" prefix
+                     ("" "$JULIA_DEPOT_PATH"))))
+               #t))))
        #:make-flags
        (list
         (string-append "prefix=" (assoc-ref %outputs "out"))
-        (string-append "PREFIX=" (assoc-ref %outputs "out"))
 
         ;; Passing the MARCH flag is necessary to build binary substitutes for
         ;; the supported architectures.
@@ -435,7 +449,10 @@
     (native-search-paths
      (list (search-path-specification
             (variable "JULIA_LOAD_PATH")
-            (files (list "share/julia/packages/")))))
+            (files (list "share/julia/packages/")))
+           (search-path-specification
+            (variable "JULIA_DEPOT_PATH")
+            (files (list "share/julia/")))))
     ;; Julia is not officially released for ARM and MIPS.
     ;; See https://github.com/JuliaLang/julia/issues/10639
     (supported-systems '("i686-linux" "x86_64-linux" "aarch64-linux"))
-- 
2.24.1

>From 3191a0958c97831bc65750a6c4231d449e92aca3 Mon Sep 17 00:00:00 2001
From: nixo <[email-masked]>
Date: Fri, 17 Jan 2020 19:40:55 +0100
Subject: [PATCH 05/11] gnu: build: julia-build-system: fix package
 precompilation

---
 guix/build/julia-build-system.scm | 51 +++++++++++++------------------
 1 file changed, 22 insertions(+), 29 deletions(-)

diff --git a/guix/build/julia-build-system.scm b/guix/build/julia-build-system.scm
index ff6fcf5fe3..dbd4af623d 100644
--- a/guix/build/julia-build-system.scm
+++ b/guix/build/julia-build-system.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2019 Nicolò Balzarotti <[email-masked]>
+;;; Copyright © 2019, 2020 Nicolò Balzarotti <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -37,53 +37,46 @@
 ;; subpath where we store the package content
 (define %package-path "/share/julia/packages/")
 
-(define (generate-load-path inputs outputs)
-  (string-append
-   (string-join (map (match-lambda
-                       ((_ . path)
-                        (string-append path %package-path)))
-                     ;; Restrict to inputs beginning with "julia-".
-                     (filter (match-lambda
-                               ((name . _)
-                                (string-prefix? "julia-" name)))
-                             inputs))
-                ":")
-   (string-append ":" (assoc-ref outputs "out") %package-path)
-   ;; stdlib is always required to find Julia's standard libraries.
-   ;; usually there are other two paths in this variable:
-   ;; "@" and "@v#.#"
-   ":@stdlib"))
-
 (define* (install #:key source inputs outputs #:allow-other-keys)
   (let* ((out (assoc-ref outputs "out"))
          (package-dir (string-append out %package-path
-                                     (string-append
-                                      (strip-store-file-name source)))))
-    (setenv "JULIA_LOAD_PATH" (generate-load-path inputs outputs))
+                                     (strip-store-file-name source))))
     (mkdir-p package-dir)
-    (copy-recursively source package-dir))
+    (copy-recursively (getcwd) package-dir))
   #t)
 
-;; TODO: Precompilation is working, but I don't know how to tell
-;; julia to use use it. If (on rantime) we set HOME to
-;; store path, julia tries to write files there (failing)
 (define* (precompile #:key source inputs outputs #:allow-other-keys)
   (let* ((out (assoc-ref outputs "out"))
          (builddir (string-append out "/share/julia/"))
          (package (strip-store-file-name source)))
     (mkdir-p builddir)
+    ;; With a patch, SOURCE_DATE_EPOCH is honored
+    (setenv "SOURCE_DATE_EPOCH" "1")
     (setenv "JULIA_DEPOT_PATH" builddir)
-    (setenv "JULIA_LOAD_PATH" (generate-load-path inputs outputs))
-    ;; Actual precompilation
-    (invoke-julia (string-append "using " package)))
+    ;; add new package dir to the load path
+    (setenv "JULIA_LOAD_PATH"
+            (string-append builddir "packages/" ":"
+                           (or (getenv "JULIA_LOAD_PATH")
+                               "")))
+    ;; Actual precompilation.
+    (invoke-julia
+     ;; when using julia as a user, julia writes precompile cache to the first
+     ;; entry of the DEPOT_PATH list (by default, the home dir).  We want to
+     ;; write it to the store, so let's push the store path as the first
+     ;; element of DEPOT_PATH.  Once the cache file exists, this hack is not
+     ;; needed anymore (like in the check phase).  If the user install new
+     ;; pacakges, those will be installed and precompiled in the home dir
+     (string-append "pushfirst!(DEPOT_PATH, pop!(DEPOT_PATH)); using " package)))
   #t)
 
 (define* (check #:key source inputs outputs #:allow-other-keys)
   (let* ((out (assoc-ref outputs "out"))
          (package (strip-store-file-name source))
          (builddir (string-append out "/share/julia/")))
+    ;; With a patch, SOURCE_DATE_EPOCH is honored
+    (setenv "SOURCE_DATE_EPOCH" "1")
     (setenv "JULIA_DEPOT_PATH" builddir)
-    (setenv "JULIA_LOAD_PATH" (generate-load-path inputs outputs))
+    (setenv "JULIA_LOAD_PATH" (string-append builddir "packages/"))
     (invoke-julia (string-append "using Pkg;Pkg.test(\"" package "\")")))
   #t)
 
-- 
2.24.1

>From 7aabfd980a00fa292e73db66230a0558389a9011 Mon Sep 17 00:00:00 2001
From: nixo <[email-masked]>
Date: Sat, 18 Jan 2020 14:05:00 +0100
Subject: [PATCH 06/11] gnu: Add julia-compat.

* gnu/packages/julia-xyz.scm: New file
* gnu/packages/julia-xyz.scm (julia-compat): New variable
---
 gnu/local.mk               |  1 +
 gnu/packages/julia-xyz.scm | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 gnu/packages/julia-xyz.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index fe8634b44d..e07229ee20 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -277,6 +277,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/jrnl.scm				\
   %D%/packages/jose.scm				\
   %D%/packages/julia.scm			\
+  %D%/packages/julia-xyz.scm			\
   %D%/packages/jupyter.scm			\
   %D%/packages/kawa.scm				\
   %D%/packages/kde.scm				\
diff --git a/gnu/packages/julia-xyz.scm b/gnu/packages/julia-xyz.scm
new file mode 100644
index 0000000000..7d9faa63e9
--- /dev/null
+++ b/gnu/packages/julia-xyz.scm
@@ -0,0 +1,27 @@
+(define-module (gnu packages julia-xyz)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix packages)
+  #:use-module (guix git-download)
+  #:use-module (guix build-system julia))
+
+(define-public julia-compat
+  (package
+    (name "julia-compat")
+    (version "3.2.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/JuliaLang/Compat.jl")
+             (commit (string-append "v" version))))
+       (file-name "Compat")
+       (sha256
+        (base32 "0d21h3l2ry2mmlhpg7b9cxifayzwcv7r13h5wydcbd5pjf6k4qd4"))))
+    (build-system julia-build-system)
+    (home-page "https://github.com/JuliaLang/Compat.jl")
+    (synopsis "Compatibility across Julia versions")
+    (description "The Compat package is designed to ease interoperability
+between older and newer versions of the Julia language.  The Compat package
+provides a macro that lets you use the latest syntax in a backwards-compatible
+way.")
+    (license license:expat)))
-- 
2.24.1

>From 9d6e97b3b87480fbc5f7dc32ad8e9db838e141ff Mon Sep 17 00:00:00 2001
From: nixo <[email-masked]>
Date: Sat, 18 Jan 2020 14:06:11 +0100
Subject: [PATCH 07/11] gnu: Add julia-inifile.

* gnu/packages/julia-xyz.scm (julia-inifile): New variable.
---
 gnu/packages/julia-xyz.scm | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/gnu/packages/julia-xyz.scm b/gnu/packages/julia-xyz.scm
index 7d9faa63e9..6b8053e5f8 100644
--- a/gnu/packages/julia-xyz.scm
+++ b/gnu/packages/julia-xyz.scm
@@ -25,3 +25,23 @@ between older and newer versions of the Julia language.  The Compat package
 provides a macro that lets you use the latest syntax in a backwards-compatible
 way.")
     (license license:expat)))
+
+(define-public julia-inifile
+  (package
+    (name "julia-inifile")
+    (version "0.5.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/JuliaIO/IniFile.jl")
+             (commit "8ba59958495fa276d6489d2c3903e765d75e0bc0")))
+       (file-name "IniFile")
+       (sha256
+        (base32 "11h6f99jpbg729lplw841m68jprka7q3n8yw390bndlmcdsjabpd"))))
+    (build-system julia-build-system)
+    (home-page "https://github.com/JuliaIO/IniFile.jl")
+    (synopsis "Reading Windows-style INI files")
+    (description "This is a julia package that defines an IniFile type that
+allows to interface with @file{.ini} files")
+    (license license:expat)))
-- 
2.24.1

>From bc96f48b6916eab179f7f1a911e54182e9c9ed71 Mon Sep 17 00:00:00 2001
From: nixo <[email-masked]>
Date: Sat, 18 Jan 2020 14:07:13 +0100
Subject: [PATCH 08/11] gnu: Add julia-sha.

* gnu/packages/julia-xyz.scm (julia-sha): New variable.
---
 gnu/packages/julia-xyz.scm | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/gnu/packages/julia-xyz.scm b/gnu/packages/julia-xyz.scm
index 6b8053e5f8..92ffde58e7 100644
--- a/gnu/packages/julia-xyz.scm
+++ b/gnu/packages/julia-xyz.scm
@@ -45,3 +45,26 @@ way.")
     (description "This is a julia package that defines an IniFile type that
 allows to interface with @file{.ini} files")
     (license license:expat)))
+
+(define-public julia-sha
+  (package
+    (name "julia-sha")
+    (version "0.5.7")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/staticfloat/SHA.jl")
+             (commit (string-append "v" version))))
+       (file-name "SHA")
+       (sha256
+        (base32 "10a09kg9z0m8rvwmlgsna6p342kyvizx2axdqc6pzyhraddr8jrp"))))
+    (propagated-inputs `(("julia-compat" ,julia-compat)))
+    (build-system julia-build-system)
+    (home-page "https://github.com/staticfloat/SHA.jl")
+    (synopsis
+     "Performant, 100% native-julia SHA1, SHA2, and SHA3 implementation")
+    (description "Julia package implementing SHA algorithms.  Each exported
+function takes in either an @code{Array{UInt8}}, a @code{ByteString} or an
+@code{IO} object.")
+    (license license:expat)))
-- 
2.24.1

>From d1094a0e8346807904a96424d8c8c59c6a91bf40 Mon Sep 17 00:00:00 2001
From: nixo <[email-masked]>
Date: Sat, 18 Jan 2020 14:07:36 +0100
Subject: [PATCH 09/11] gnu: Add julia-binaryprovider.

* gnu/packages/julia-xyz.scm (julia-binaryprovider): New variable.
---
 gnu/packages/julia-xyz.scm | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/gnu/packages/julia-xyz.scm b/gnu/packages/julia-xyz.scm
index 92ffde58e7..0f8e04b4d1 100644
--- a/gnu/packages/julia-xyz.scm
+++ b/gnu/packages/julia-xyz.scm
@@ -68,3 +68,36 @@ allows to interface with @file{.ini} files")
 function takes in either an @code{Array{UInt8}}, a @code{ByteString} or an
 @code{IO} object.")
     (license license:expat)))
+
+(define-public julia-binaryprovider
+  (package
+    (name "julia-binaryprovider")
+    (version "0.5.8")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/JuliaPackaging/BinaryProvider.jl")
+             (commit (string-append "v" version))))
+       (file-name "BinaryProvider")
+       (sha256
+        (base32 "174jmg4w8ncgfhdvfnm0p4cnlayw31j4s9sksqlwz1sipywqvww7"))))
+    (propagated-inputs `(("julia-sha" ,julia-sha)))
+    ;; We don't really need BinaryProvider (as guix provides the binaries) but
+    ;; since it's a dependency of other packages we want to precompile it.
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'disable-engine-probe
+           (lambda _
+             (substitute* "src/BinaryProvider.jl"
+               ;; Precompilation tries to download things from the internet,
+               ;; disable the download part
+               (("probe_platform_engines") "# probe_platform_engines"))
+             #t)))))
+    (build-system julia-build-system)
+    (home-page "https://github.com/JuliaPackaging/BinaryProvider.jl")
+    (synopsis "Reliable Binary provider for Julia")
+    (description "@code{BinaryProvider.jl} simplifies the installation of
+binaries required by julia packages.")
+    (license license:expat)))
-- 
2.24.1

>From 5239d2a1c3dc713496817eb0018a062af4b280be Mon Sep 17 00:00:00 2001
From: nixo <[email-masked]>
Date: Sat, 18 Jan 2020 14:11:14 +0100
Subject: [PATCH 10/11] gnu: Add julia-mbedtls.

* gnu/packages/julia-xyz.scm (julia-mbedtls): New variable.
---
 gnu/packages/julia-xyz.scm | 49 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/julia-xyz.scm b/gnu/packages/julia-xyz.scm
index 0f8e04b4d1..3e9f532697 100644
--- a/gnu/packages/julia-xyz.scm
+++ b/gnu/packages/julia-xyz.scm
@@ -2,7 +2,8 @@
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (guix packages)
   #:use-module (guix git-download)
-  #:use-module (guix build-system julia))
+  #:use-module (guix build-system julia)
+  #:use-module (gnu packages tls))
 
 (define-public julia-compat
   (package
@@ -101,3 +102,49 @@ function takes in either an @code{Array{UInt8}}, a @code{ByteString} or an
     (description "@code{BinaryProvider.jl} simplifies the installation of
 binaries required by julia packages.")
     (license license:expat)))
+
+(define-public julia-mbedtls
+  (package
+    (name "julia-mbedtls")
+    (version "0.7.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/JuliaLang/MbedTLS.jl")
+             (commit (string-append "v" version))))
+       (file-name "MbedTLS")
+       (sha256
+        (base32 "1a8snw9gi21lm6r3kh6ly7ngi99s9k5shqkfiizj3g9li20q23h2"))))
+    (propagated-inputs
+     `(("julia-binaryprovider" ,julia-binaryprovider)
+       ("mbedtls-apache" ,mbedtls-apache)))
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-before 'precompile 'build-deps
+           (lambda* (#:key outputs source inputs #:allow-other-keys)
+             (let ((f (open-file
+                       (string-append
+                        (assoc-ref outputs "out")
+                        "/share/julia/packages/"
+                        (string-append
+                         (strip-store-file-name source) "/deps/deps.jl"))
+                       "w")))
+               (display (string-append "const libmbedcrypto = \""
+                                       (assoc-ref inputs "mbedtls-apache")
+                                       "/lib/libmbedcrypto.so\"\n") f)
+               (display (string-append "const libmbedtls = \""
+                                       (assoc-ref inputs "mbedtls-apache")
+                                       "/lib/libmbedtls.so\"\n") f)
+               (display (string-append "const libmbedx509 = \""
+                                       (assoc-ref inputs "mbedtls-apache")
+                                       "/lib/libmbedx509.so\"\n") f)
+               (close-port f))
+             #t)))))
+    (build-system julia-build-system)
+    (home-page "https://github.com/JuliaLang/MbedTLS.jl")
+    (synopsis "Apache's mbed TLS library wrapper")
+    (description "@code{MbedTLS.jl} provides a wrapper around the mbed TLS and
+cryptography C libary for Julia.")
+    (license license:expat)))
-- 
2.24.1

>From bd7ba60316819b1201966dc650f50e4c320a4dfd Mon Sep 17 00:00:00 2001
From: nixo <[email-masked]>
Date: Sat, 18 Jan 2020 14:11:45 +0100
Subject: [PATCH 11/11] gnu: Add julia-http.

* gnu/packages/julia-xyz.scm (julia-http): New variable.
---
 gnu/packages/julia-xyz.scm | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/gnu/packages/julia-xyz.scm b/gnu/packages/julia-xyz.scm
index 3e9f532697..ff1bb483f9 100644
--- a/gnu/packages/julia-xyz.scm
+++ b/gnu/packages/julia-xyz.scm
@@ -148,3 +148,27 @@ binaries required by julia packages.")
     (description "@code{MbedTLS.jl} provides a wrapper around the mbed TLS and
 cryptography C libary for Julia.")
     (license license:expat)))
+
+(define-public julia-http
+  (package
+    (name "julia-http")
+    (version "0.8.8")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/JuliaWeb/HTTP.jl")
+             (commit (string-append "v" version))))
+       (file-name "HTTP")
+       (sha256
+        (base32 "0928fvncfp07i5hvqxjyj8i27xmxxllas1m5idqq2i8h7jshzq3y"))))
+    (propagated-inputs
+     `(("julia-inifile" ,julia-inifile)
+       ("julia-mbedtls" ,julia-mbedtls)
+       ("julia-compat" ,julia-compat)))
+    (build-system julia-build-system)
+    (home-page "https://juliaweb.github.io/HTTP.jl/")
+    (synopsis "HTTP support for Julia")
+    (description "@code{HTTP.jl} is a Julia library for HTTP Messages,
+implementing both a client and a server.")
+    (license license:expat)))
-- 
2.24.1