• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

codedownio/julia2nix: Generate Nix expressions for building a Julia depot with a ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

codedownio/julia2nix

开源软件地址:

https://github.com/codedownio/julia2nix

开源编程语言:

Shell 45.1%

开源软件介绍:

julia2nix

Package a Julia environment using the Nix package manager!

Recommended: Julia 1.3+ (so we can get package dependencies from Artifacts.toml)

Quick start

Step 1: create Project.toml and Manifest.toml

Go to a folder and create a Julia Project.toml and Manifest.toml containing the desired packages, using the normal Pkg interface.

Important: make sure you use the same Julia version you're going to be specifying in Nix! If you use different versions, the package set you create may not be compatible. It's best to just launch the Nix-provided Julia directly, i.e. $(nix-build '<nixpkgs>' -A julia_15)/bin/julia

mkdir depot
cd depot
$(nix-build '<nixpkgs>' -A julia_15)/bin/julia

julia> # Press "]" to enter package mode
pkg> activate .
pkg> add SomePackage
pkg> add SomeOtherPackage
pkg> [Ctrl+D to exit]

Step 2: run julia2nix to generate the Nix files

git clone [email protected]:codedownio/julia2nix.git ~/julia2nix
# Still in the "depot" folder from before:
~/julia2nix/julia2nix

This will create a few files:

  • packages.nix: Nix expressions for the packages and artifacts.
  • common.nix: common code for building your environment. Please don't edit this by hand.
  • default.nix: the main entry point. You can edit some settings in here.
  • fetchgit: this contains a patched version of the Nix fetchgit function, necessary until this PR lands.

You should make sure the baseJulia in default.nix matches the Julia version you used in Step 1.

Step 3: build!

The following command should build your Julia environment and drop you into a Julia session where your packages are available:

# Make sure you have a writable depot in JULIA_DEPOT_PATH.
# Our wrapped Julia will add the one we just built to the end.
export JULIA_DEPOT_PATH=${HOME}/.julia
$(nix-build . --no-out-link)/bin/julia

Updating packages

To change the package set and regenerate the Nix expressions, simply repeat steps 1 and 2 in the same folder. julia2nix will overwrite packages.nix and possibly common.nix/fetchgit, but will not replace default.nix.

How does it work?

Julia's new package manager Pkg3 learns about available packages from a "registry" repository, primarily the General registry. When you type Pkg.install("SomePackage"), it looks up the package's URL and other metadata such as the Git hash in the registry.

julia2nix looks at your Manifest.toml to find all the packages that Pkg3 will need to download and constructs Nix derivations to get the necessary versions of each. Then, it constructs a special version of the registry where those package URLs are replaced with Nix store paths. With this special registry, plus rewriting any URL paths in Manifest.toml itself, we can run Pkg.instantiate() and be sure that all clone requests will be read from Nix store paths on disk.

After the packages are cloned, some will need to obtain extra artifacts such as platform-specific library binaries. If the packages use the new Pkg.Artifacts system to specify their artifacts, then julia2nix will likewise generate derivations for these by processing the Artifacts.toml file in each package and computing an overall Overrides.toml with Nix path versions of everything.

At the end of the day, you get a declarative and reproducible Julia depot built with Nix!

Advanced notes

There are a few options you can configure in default.nix (also documented there):

  • Set whether Pkg.precompile() is called at the end to precompile all packages (defaults to true).
  • Configure makeWrapper arguments to Julia, for example to configure environment variables. The default version sets the PYTHON environment variable to a Nix-provided Python, so that Julia packages won't try to use Conda to obtain their own.

If you only want the Julia depot to use in your own derivations, it is exposed from default.nix as the depot attribute.

Specific packages

Check out the wiki for notes on specific packages that don't work out of the box but can be made to work. Wiki contributions welcome.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap