# Build Julia on NixOS

**URL:** https://discourse.julialang.org/t/build-julia-on-nixos/35129
**Category:** General Usage
**Tags:** question, nixos
**Created:** [February 25, 2020, 6:14pm UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129 "2020-02-25T18:14:16Z")
**Posts on this page:** 20
**Page:** 3

<div class="post-metadata">

### Author: ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)
#### Post date: [January 26, 2021, 9:19am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/43 "2021-01-26T09:19:27Z")

</div>

The `buildFHSUserEnv` that was working for me on 1.5.3 also works on 1.6-beta1 as far as I can tell. I just built some projects of mine with tons of dependencies (including DataFrames, MLJ and Gadfly) and had no issues whatsoever. Since it uses `buildFHSUserEnv`, it is [a bit of a hack](https://sandervanderburg.blogspot.com/2011/11/on-nix-nixos-and-filesystem-hierarchy.html), but at least it works.

I put the derivation and a README at [https://github.com/rikhuijzer/julia-nixos](https://github.com/rikhuijzer/julia-nixos).

---

<div class="post-metadata">

### Author: ![idontgetoutmuch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/idontgetoutmuch/32/321_2.png) [@idontgetoutmuch](https://discourse.julialang.org/u/idontgetoutmuch)
#### Post date: [March 2, 2021, 9:08pm UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/44 "2021-03-02T21:08:42Z")

</div>

Does anyone have `julia2nix` working on macos (big sur)?

---

<div class="post-metadata">

### Author: ![idontgetoutmuch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/idontgetoutmuch/32/321_2.png) [@idontgetoutmuch](https://discourse.julialang.org/u/idontgetoutmuch)
#### Post date: [March 12, 2021, 8:31am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/45 "2021-03-12T08:31:32Z")

</div>

This is great news 😀 but I’d still like what I have in R or Python e.g. the ability to list the packages in the nix derivation itself

```julia
{ pkgs ? import <nixpkgs> { config.allowBroken = true; } }:

let

  julia = pkgs.julia_15.override {
    # stdenv = pkgs.overrideCC pkgs.stdenv pkgs.gcc;
    # blas = pkgs.openblas;
  };

in

pkgs.mkShell {
  buildInputs = [
    julia
    pkgs.python3
    pkgs.python3Packages.numpy

  ];

  MYVARIABLE = "hello";
}

```

Is that ever going to be possible?

---

<div class="post-metadata">

### Author: ![aaronjanse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aaronjanse/32/22899_2.png) [@aaronjanse](https://discourse.julialang.org/u/aaronjanse)
#### Post date: [March 14, 2021, 5:19am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/46 "2021-03-14T05:19:32Z")

</div>

In case anyone is interested, I’ve published the code I use to package Julia with a precompiled sysimage.

You can try it out via my Nix flake. Note that it takes a long time to initially compile:

```julia
nix shell github:aaronjanse/dotfiles#julia

```

[https://github.com/aaronjanse/dotfiles/tree/master/pkgs/julia](https://github.com/aaronjanse/dotfiles/tree/master/pkgs/julia)

---

<div class="post-metadata">

### Author: ![idontgetoutmuch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/idontgetoutmuch/32/321_2.png) [@idontgetoutmuch](https://discourse.julialang.org/u/idontgetoutmuch)
#### Post date: [March 14, 2021, 11:08am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/47 "2021-03-14T11:08:05Z")

</div>

FYI I now have it working with lorri / direnv / emacs so that when I enter the directory I get automatically switched to the desired environment.

---

<div class="post-metadata">

### Author: ![thomasjm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thomasjm/32/18984_2.png) [@thomasjm](https://discourse.julialang.org/u/thomasjm)
#### Post date: [March 14, 2021, 5:43pm UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/48 "2021-03-14T17:43:02Z")

</div>

Sorry for the delay, missed this question. Yes, I think it’s possible. The holy grail would be to check in a comprehensive package set to Nixpkgs (consisting of all the packages in the general registry).

It would be some work to set up the tools to build this set and update it in Nixpkgs on a recurring basis the way Python etc. do.

One difficulty I could foresee is that Julia is unusually precise about its package dependencies. When you ask Julia to install a set of packages, I think it does some complex constraint solving to find a set of versions that makes every dependency happy. So any Nix scheme would probably have to contain similar logic–you wouldn’t be able to just have a single version of each package the way some language ecosystems do.

But on the whole I think the task is straightforward, it just needs someone to put some time into it.

---

<div class="post-metadata">

### Author: ![cstich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstich/32/18665_2.png) [@cstich](https://discourse.julialang.org/u/cstich)
#### Post date: [March 16, 2021, 7:41pm UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/49 "2021-03-16T19:41:59Z")

</div>

What about trying to get your `julia FHS` merged into `nixpkgs`? Currently the user experience with `julia` and `Pkg3` is a bit abysmal on `nix`. People have taken a similar [approach](https://github.com/NixOS/nixpkgs/pull/34872) getting `conda` to work with `nix`. I think this would be good to have at least until we figure out a better way to support and build julia and the julia package ecosystem.

I also don’t mind issuing a pull request myself but I wanted to check with you first.

---

<div class="post-metadata">

### Author: ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)
#### Post date: [March 16, 2021, 7:56pm UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/50 "2021-03-16T19:56:39Z")

</div>

I thought that there was a good reason for not using this approach, so that is why I didn’t try to get it into nixpkgs. I would appreciate it very much if you could look into it and you don’t have to give me credits. 😁 I also copied parts of it from someone but unfortunately don’t know who. Also, I think he copied it from somewhere and I’ve made some changes.

---

<div class="post-metadata">

### Author: ![cstich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstich/32/18665_2.png) [@cstich](https://discourse.julialang.org/u/cstich)
#### Post date: [March 18, 2021, 3:31pm UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/51 "2021-03-18T15:31:31Z")

</div>

Sure, I can take it on. Ideally, yes, there would be more `nix` way of doing things and `julia2nix` definitely is a big step forward with respect to usability, but I still think it’s worth having something that just works.

FWIW, I also got 1.6 to build now from source, although that expression is in dire need of refactoring and fails a good chunk of it’s tests.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [March 18, 2021, 3:54pm UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/52 "2021-03-18T15:54:54Z")

</div>

> [@cstich](#):
>
> FWIW, I also got 1.6 to build now from source, although that expression is in dire need of refactoring and fails a good chunk of it’s tests.

I believe @ninjin is looking into this 👀

---

<div class="post-metadata">

### Author: ![ninjin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ninjin/32/58_2.png) [@ninjin](https://discourse.julialang.org/u/ninjin)
#### Post date: [March 19, 2021, 10:30am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/53 "2021-03-19T10:30:21Z")

</div>

Thanks for flagging this to me @giordano!

Indeed, I have cleaned-up expressions for 1.0.x and 1.5.x in the pipeline that I hope to have cleared and in PRs over the weekend. I really should make my Nixpkgs fork and Julia with Nix fork public and post them here as well in case you guys want to provide feedback and/or patches.

@cstich: If you are up for it, would you be happy to share that working 1.6rc expression? I have not yet taken a stab at the 1.6rc just yet, but I would greatly appreciate you sharing any quirks you had to deal with moving from 1.5.4. What I have done so far is to have a quick look at the 1.6rc code for Fedora a few days ago.

---

<div class="post-metadata">

### Author: ![cstich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstich/32/18665_2.png) [@cstich](https://discourse.julialang.org/u/cstich)
#### Post date: [March 25, 2021, 10:21am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/54 "2021-03-25T10:21:24Z")

</div>

That’s great news. Let me know if I can help in any way. I am happy to have a look at the (eventual) pull request as well.

Sure, no problem. Here is my working expression for 1.6:

> <https://gist.github.com/cstich/4e92beae25eced8acf6df4bf860f5fb8>

---

<div class="post-metadata">

### Author: ![colinxs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colinxs/32/9071_2.png) [@colinxs](https://discourse.julialang.org/u/colinxs)
#### Post date: [March 28, 2021, 2:34am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/55 "2021-03-28T02:34:57Z")

</div>

Late to the party, but for those interested @ninjin created the #nix channel on the [Julia Slack](https://join.slack.com/t/julialang/shared_invite/zt-nmal0i0x-LcYEtdnTameGsXmBzMzgog) for those interested. I put together a Google Doc summarizing some of the conversations around Julia + Nix that have been happening and linked it there.

---

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [March 28, 2021, 2:47am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/56 "2021-03-28T02:47:52Z")

</div>

Any chance we could move to [the Julia Zulip](https://julialang.zulipchat.com/#narrow/stream/283536-nix/topic/stream.20events/near/232135705) instead? Zulip solves the problems of named topics, searchability, and losing history into the slackhole, while retaining the chatty feel.

---

<div class="post-metadata">

### Author: ![colinxs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colinxs/32/9071_2.png) [@colinxs](https://discourse.julialang.org/u/colinxs)
#### Post date: [March 28, 2021, 3:23am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/57 "2021-03-28T03:23:42Z")

</div>

@jzr Zulip looks interesting (especially the unlimited history), but I think most of the core Julia devs (specifically those familiar with Pkg/Artifacts/BinaryBuilder) are primarily on Slack. Those folks have been super helpful thus far.

---

<div class="post-metadata">

### Author: ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)
#### Post date: [May 19, 2021, 6:38am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/58 "2021-05-19T06:38:39Z")

</div>

After a tremendous amounts of efforts _(note: non of which by me)_, Julia 1.6 is now in nixpkgs ([julia: init julia\_10-bin and julia\_16-bin by ninjin · Pull Request #123188 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/123188)). This will end up in NixOS [21.05](https://github.com/NixOS/nixpkgs/pull/117881#issuecomment-836148633). I’ve been running Pontus’ binary for more than a week now and it works great 🥳

Many many thanks to @ninjin and the other contributors

---

<div class="post-metadata">

### Author: ![ninjin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ninjin/32/58_2.png) [@ninjin](https://discourse.julialang.org/u/ninjin)
#### Post date: [May 20, 2021, 7:28am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/59 "2021-05-20T07:28:03Z")

</div>

My pleasure, although it still irks me that the v1.6.x source builds are not in a working state. Perhaps I can resume hacking on this in a few weeks if I can steal the time.

---

<div class="post-metadata">

### Author: ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)
#### Post date: [May 26, 2021, 7:26am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/60 "2021-05-26T07:26:13Z")

</div>

> [@cstich](#):
>
> Ideally, yes, there would be more `nix` way of doing things and `julia2nix` definitely is a big step forward with respect to usability, but I still think it’s worth having something that just works.

Out of curiosity: what is exactly the benefit of having a more `nix` way to manage packages in Julia? Unlike Python, Ruby and R, for example, Julia has a reliable and built-in package manager which can handle multiple versions of the same package. (The depot can even handle multiple versions of Julia.)

---

<div class="post-metadata">

### Author: ![RCHG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rchg/32/10104_2.png) [@RCHG](https://discourse.julialang.org/u/RCHG)
#### Post date: [May 26, 2021, 8:02am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/61 "2021-05-26T08:02:05Z")

</div>

I am not an expert but I think that it is not so simple to use the Julia package manager in NixOS (not like in other Linux distributions). Pkg3 of Julia sometimes is looking for external libraries, or python code etc… And, at least in the previous versions of Julia in NixOS that I tested, this can be an issue. Often these libraries are not found by Pkg3 even when they are installed in the system because NixOS has a different location of the packages. For example, if Pkg3 is trying to install/use matplotlib for Plots using conda this might not work for scratch.

There are several approaches to overcome this problem like `julia FHS` or during the compilation of Julia itself, but a julia2nix would be something nice as it could introduce the full tree of dependences of each package to ensure that everything is working smoothly in NixOS.

---

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [May 26, 2021, 8:28am UTC](https://discourse.julialang.org/t/build-julia-on-nixos/35129/62 "2021-05-26T08:28:02Z")

</div>

@rikh There are issues with some individual binaries, as @RCHG alludes to. There’s also the more general point that once you’ve found Nix nirvana, you don’t want to go back to every little thing having its own package manager.

[Previous page](https://discourse.julialang.org/t/build-julia-on-nixos/35129.md?page=2)

[Next page](https://discourse.julialang.org/t/build-julia-on-nixos/35129.md?page=4)
