1# Julia {#language-julia} 2 3## Introduction {#julia-introduction} 4 5Nixpkgs includes Julia as the `julia` derivation. 6You can get specific versions by looking at the other `julia*` top-level derivations available. 7For example, `julia_19` corresponds to Julia 1.9. 8We also provide the current stable version as `julia-stable`, and an LTS version as `julia-lts`. 9 10Occasionally, a Julia version has been too difficult to build from source in Nixpkgs and has been fetched prebuilt instead. 11These Julia versions are differentiated with the `*-bin` suffix; for example, `julia-stable-bin`. 12 13## julia.withPackages {#julia-withpackage} 14 15The basic Julia derivations only provide the built-in packages that come with the distribution. 16 17You can build Julia environments with additional packages using the `julia.withPackages` command. 18This function accepts a list of strings representing Julia package names. 19For example, you can build a Julia environment with the `Plots` package as follows. 20 21```nix 22julia.withPackages [ "Plots" ] 23``` 24 25Arguments can be passed using `.override`. 26For example: 27 28```nix 29(julia.withPackages.override { 30 precompile = false; # Turn off precompilation 31}) 32 [ "Plots" ] 33``` 34 35Here's a nice way to run a Julia environment with a shell one-liner: 36 37```sh 38nix-shell -p 'julia.withPackages ["Plots"]' --run julia 39``` 40 41### Arguments {#julia-withpackage-arguments} 42 43* `precompile`: Whether to run `Pkg.precompile()` on the generated environment. 44 45 This will make package imports faster, but may fail in some cases. 46 For example, there is an upstream issue with `Gtk.jl` that prevents precompilation from working in the Nix build sandbox, because the precompiled code tries to access a display. 47 Packages like this will work fine if you build with `precompile=false`, and then precompile as needed once your environment starts. 48 49 Defaults: `true` 50 51* `extraLibs`: Extra library dependencies that will be placed on the `LD_LIBRARY_PATH` for Julia. 52 53 Should not be needed as we try to obtain library dependencies automatically using Julia's artifacts system. 54 55* `makeWrapperArgs`: Extra arguments to pass to the `makeWrapper` call which we use to wrap the Julia binary. 56* `setDefaultDepot`: Whether to automatically prepend `$HOME/.julia` to the `JULIA_DEPOT_PATH`. 57 58 This is useful because Julia expects a writable depot path as the first entry, which the one we build in Nixpkgs is not. 59 If there's no writable depot, then Julia will show a warning and be unable to save command history logs etc. 60 61 Default: `true` 62 63* `packageOverrides`: Allows you to override packages by name by passing an alternative source. 64 65 For example, you can use a custom version of the `LanguageServer` package by passing `packageOverrides = { "LanguageServer" = fetchFromGitHub {...}; }`. 66 67* `augmentedRegistry`: Allows you to change the registry from which Julia packages are drawn. 68 69 This normally points at a special augmented version of the Julia [General packages registry](https://github.com/JuliaRegistries/General). 70 If you want to use a bleeding-edge version to pick up the latest package updates, you can plug in a later revision than the one in Nixpkgs. 71 72* `juliaCpuTarget`: Allows you to set `JULIA_CPU_TARGET` when precompiling. Has no effect if `precompile=false`. 73 74 You may want to use this if you're building a Julia depot that will end up in a Nix cache and used on machines with 75 different CPUs. 76 77 Why? Julia will detect the CPU microarchitecture of the build machine and include this information in the precompiled 78 `*.ji` files. Starting in 1.10, Julia became more strict about checking the CPU target compatibility, so it may reject 79 your precompiled files if they were compiled on a different machine. 80 A good option to provide wide compatibility is to set this to `"generic"`, although this may reduce performance. 81 You can also set a semicolon-separated list of multiple different targets. See the Julia documentation for details.