Best way to install and use julia on Nix/NixoS

Hi there,

I am a julia user new to Nix environment. And I am wondering what is the best way to install julia and use it under this platform. I see 3 ways :

  • using julia package from Nix pkgs;

  • using julia-bin package from Nix pkgs;

  • using the classic downloadable file of julia and using some FHS tools or other approach to use it under Nix.

I am wondering because julia’s packages from linux distributions have often bad reputation concerning julia (I experienced it), but with nix it is not possible to use it out of the box after download.

I don’t know if this topic is more suitable for here, a julia discourse, or nix/nixos one.

If you are on nixos-unstable, you can just install julia-bin to get the latest Julia (1.10.0 currently).

If you’re on a stable nixos release like 23.11, julia-bin is Julia 1.9, so you’ll want to use an overlay to get the newer Julia 1.10. Read the nixpkgs docs to learn about using overlays. When the next Julia release comes out you can (hopefully) just bump the version and specify the new sha256.

Ok. So basically what you say is that julia-bin is ok but need an overlay just to get the latest version ?

Why not just using the unstable.julia-bin package in a stable nix ?

I know it is not recommended but using 1.9 does not disturb me. I am not bleeding edge in my use of julia.

If you have unstable nixpkgs, then sure, you can use unstable.julia-bin to get the latest Julia release.

1 Like

I would say that Julia 1.10 is worth it even if you aren’t using any new features. 1.10 has package loading (e.g. time for using X) roughly 2x faster than 1.9.


Ok noted. Thanks !

Is julia-bin and installing packages inside Julia more stable right now than using Nix to build a Julia with all bundled packages, i.e. julia.withPackages?

yes. Do not use your OS to install Julia packages.

1 Like

Thanks, can you elaborate on this? Previously using julia-bin had quite a few glitches, e.g. Gadfly + Cairo were unable to find local fonts and PDFs were therefore broken (on Nix/NixOS).

I think @thomasjm wrote julia.withPackages, maybe he can explain the state of that project.

I’ve been able to get julia running using the julia-bin package, but I’ve had no joy getting Plots.jl with GR (on either X11 or Wayland) to work. Has anyone got this working?

julia> using Plots

julia> plot(1:100)
env: ‘/home/stephen/.julia/artifacts/7f59a0ec3d19c98dce30a3ba8ea9cbd8824ce4a6/bin/gksqt’: No such file or directory
connect: Connection refused
GKS: can't connect to GKS socket application

GKS: Open failed in routine OPEN_WS

I haven’t tried this code but it purports to fix GR.

Fwiw I have no problems with CairoMakie or WGLMakie.

Thank you for sharing that code on github. I found that with a small tweak to account for the change in pathname of whether the gksqt is stored, it now works on both X11 and Wayland.

This is likely because you need to patchelf the binaries installed from Artifacts.jl. The script below should also allow you to use juliaup to install Julia versions. You just need to run this anytime you install/update a binary from Julia.

#!/usr/bin/env nix-shell
#! nix-shell -i bash -p patchelf parallel

# Based on scripts by cstich, et. al.
# Fixes up Julia Artifacts on NixOS
# Discussion:


patchelf_job() {
  chmod +w $ARTIFACT
  patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $ARTIFACT

export -f patchelf_job

echo "Patching..."
find ~/src/julia/usr/* $PKG_DIR/artifacts/*/bin $PKG_DIR/juliaup/*  -type f | parallel patchelf_job {} > /dev/null 2>&1

You can also use the following patchset to get a shell.nix which will build Julia on NixOS:

I also realized since 22.05 you can use: GitHub - Mic92/nix-ld: Run unpatched dynamic binaries on NixOS

This seems to be a much smoother experience.