Skip to content

Instantly share code, notes, and snippets.

@mnacamura
Created February 12, 2018 07:37
Show Gist options
  • Save mnacamura/83a26e5da7c01c4379439f1056c31fa4 to your computer and use it in GitHub Desktop.
Save mnacamura/83a26e5da7c01c4379439f1056c31fa4 to your computer and use it in GitHub Desktop.
Julia in nixpkgs: an impure road to IJulia
{ stdenv, makeWrapper, writeText,
cacert, git, mbedtls, zlib, zeromq3, julia, jupyterEnv }:
let
extraLibs = [ mbedtls zlib zeromq3 ];
majorMinor = version:
with stdenv.lib;
concatStringsSep "." (take 2 (splitString "." version));
patches = with stdenv.lib; {
ZMQ = writeText "ZMQ.jl.patch" (readFile ./ZMQ.jl.patch);
MbedTLS = writeText "MbedTLS.jl.patch" (readFile ./MbedTLS.jl.patch);
};
in
stdenv.mkDerivation rec {
name = "julia-${version}-env";
version = julia.version;
nativeBuildInputs = [
makeWrapper
cacert
git
# pkgconfig
# which
jupyterEnv
];
buildInputs = [ julia ] ++ extraLibs;
phases = [ "installPhase" ];
installPhase = ''
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
export LD_LIBRARY_PATH=${stdenv.lib.makeLibraryPath extraLibs}
export JULIA_PKGDIR=$out/share/julia/site
mkdir -p $JULIA_PKGDIR
julia -e "Pkg.init()"
pushd $JULIA_PKGDIR/v${majorMinor version}
# Install ZMQ.jl manually to remove dependnecy to Homebrew.jl
git clone https://github.com/JuliaInterop/ZMQ.jl.git ZMQ
pushd ZMQ
patch -p1 < ${patches.ZMQ}
julia -e "Pkg.resolve(); Pkg.build(\"ZMQ\")"
popd
# Install MbedTLS.jl manually to remove dependnecy to Homebrew.jl
git clone https://github.com/JuliaWeb/MbedTLS.jl.git MbedTLS
pushd MbedTLS
patch -p1 < ${patches.MbedTLS}
julia -e "Pkg.resolve(); Pkg.build(\"MbedTLS\")"
popd
export JUPYTER=${jupyterEnv}/bin/jupyter
export HOME=.
julia -e "Pkg.add(\"IJulia\")"
# Modify IJulia kernel
kspec=$out/share/jupyter/kernels/julia-${majorMinor version}
mkdir -p $kspec
cat << JSON > $kspec/kernel.json
{
"argv": [
"$out/bin/julia", "-i", "--startup-file=yes", "--color=yes",
"$out/share/julia/site/v${majorMinor version}/IJulia/src/kernel.jl",
"{connection_file}"
],
"display_name": "${name} (IJulia)",
"language": "julia"
}
JSON
chmod 444 $kspec/kernel.json
ln -s $JULIA_PKGDIR/v${majorMinor version}/IJulia/deps/logo-32x32.png $kspec/
ln -s $JULIA_PKGDIR/v${majorMinor version}/IJulia/deps/logo-64x64.png $kspec/
popd
makeWrapper ${julia}/bin/julia $out/bin/julia \
--prefix LD_LIBRARY_PATH : "$LD_LIBRARY_PATH" \
--set JULIA_LOAD_PATH $JULIA_PKGDIR/v${majorMinor version}
'';
}
diff --git a/REQUIRE b/REQUIRE
index a7c2269..597a7cf 100644
--- a/REQUIRE
+++ b/REQUIRE
@@ -1,4 +1,3 @@
julia 0.6
BinDeps
-@osx Homebrew
Compat 0.41.0
diff --git a/deps/build.jl b/deps/build.jl
index e710313..713ba2f 100644
--- a/deps/build.jl
+++ b/deps/build.jl
@@ -51,9 +51,9 @@ if need_to_build_manually
# make sure we delete the old deps.jl
isfile("deps.jl") && read("deps.jl", String) == systemlibs && rm("deps.jl")
- mbed = library_dependency("libmbedtls", aliases=["libmbedtls", "libmbedtls.2.1.1"])
- mbed_crypto = library_dependency("libmbedcrypto", aliases=["libmbedcrypto", "libmbedcrypto.2.1.1"], validate=validate_mbed)
- mbed_x509 = library_dependency("libmbedx509", aliases=["libmbedx509", "libmbedx509.2.1.1"])
+ mbed = library_dependency("libmbedtls", aliases=["libmbedtls", "libmbedtls.so", "libmbedtls.2.1.1"])
+ mbed_crypto = library_dependency("libmbedcrypto", aliases=["libmbedcrypto", "libmbedcrypto.so", "libmbedcrypto.2.1.1"], validate=validate_mbed)
+ mbed_x509 = library_dependency("libmbedx509", aliases=["libmbedx509", "libmbedx509.so", "libmbedx509.2.1.1"])
mbed_all = [mbed, mbed_crypto, mbed_x509]
@@ -87,11 +87,6 @@ if need_to_build_manually
end
if Compat.Sys.isapple()
- if Pkg.installed("Homebrew") === nothing
- error("Homebrew package not installed, please run Pkg.add(\"Homebrew\")")
- end
- using Homebrew
- provides(Homebrew.HB, "mbedtls", mbed_all)
end
if Compat.Sys.iswindows()
diff --git a/REQUIRE b/REQUIRE
index 60d25d1..6ea9e39 100644
--- a/REQUIRE
+++ b/REQUIRE
@@ -1,5 +1,4 @@
julia 0.6
BinDeps 0.3.21
-@osx Homebrew
Compat 0.41.0
@windows WinRPM
diff --git a/deps/build.jl b/deps/build.jl
index 4fbd7ae..987f585 100644
--- a/deps/build.jl
+++ b/deps/build.jl
@@ -30,8 +30,6 @@ if Compat.Sys.iswindows()
using WinRPM
provides(WinRPM.RPM, "zeromq", [zmq], os = :Windows)
elseif Compat.Sys.isapple()
- using Homebrew
- provides(Homebrew.HB, "zeromq@3.2", zmq, os = :Darwin)
end
@BinDeps.install Dict(:zmq => :zmq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment