julia-purifier full guide
Detailed setup, dependency management, build commands, and troubleshooting. Start with the overview for the initial commands; use the sections below for the complete setup and behavior. julia-purifier is classified at maturity tier 3 (see tier assessment for details).
Contents
- Setup and activation
- Version compatibility
- Development loop
- Using locked dependencies
- Working offline
- Language tooling integration
- Nix builds
- Supported scope
- Troubleshooting
- Examples
Setup and activation
Use the overview’s Quickstart for the initial command sequence. The setup details below apply to that workflow.
Commit the lockfiles that the lock command writes, including the build tool’s own lockfile when it has one. Keep using the project’s usual build, test and editor commands with this setup. Nix provides the locked dependencies; the development commands above run outside the Nix sandbox. No project Nix files are needed for this workflow.
Sandboxed builds are an optional next step.
The required wrapper is julia-purifier julia; pass your usual tool
arguments after it. With no purifier lockfile, it warns on standard error
and runs the ordinary tool with impure resolution.
Install these packages through your usual Nix configuration.
Version compatibility
| Tool or language | Packaged defaults | Tested versions |
|---|---|---|
| Julia distribution (provides Pkg) | 1.13.2 | — |
| Julia | 1.13.2 | — |
Operating systems and architectures
| OS | CPU architecture | Packaged toolchain | Recorded workflow |
|---|---|---|---|
| macOS | ARM64 | Yes | Not recorded |
| Linux | ARM64 | Yes | Not recorded |
| Linux | x86-64 | Yes | Tested |
Choosing versions
| Component | Selected by |
|---|---|
| Project runtime: Julia | The manifest’s julia_version selects the project runtime; the packaged Julia is used when there is no manifest.Manifest.toml |
Requirements
- Manifest format 2 is required. The builder selects the pinned Julia package matching the manifest’s major/minor version; a version absent from that package set requires an explicit julia override.
Development loop
The development loop goes through Julia itself, on the locked downloads.
Pkg has no plugin mechanism for tasks, so the julia-purifier command is a
program that runs Pkg and records what Pkg downloaded:
julia-purifier julia [args...]runs Julia withJULIA_PKG_OFFLINE=trueand the project active. Edit the code of the project and run it this way; the depot of dependencies stays as it is. Without a lockfile, or withJULIA_PURIFIER=0, it is plain Julia.- To add or upgrade a dependency, run Pkg with the network:
JULIA_PKG_OFFLINE=false julia-purifier julia -e 'using Pkg; Pkg.add("X")'. The next run says the lockfile is stale, andjulia-purifier lockrenews it. julia-purifier update [package...]updates the named packages, or every package, withPkg.update, and then locks the result.lockkeeps the resolution of the manifest as it is.julia-purifier envprints the environment ofjuliaas shell exports (JULIA_DEPOT_PATH,JULIA_PKG_OFFLINE,JULIA_PROJECTandPATH). A tool that startsjuliaitself gets the locked dependencies this way, for example witheval "$(julia-purifier env)"in an.envrc.julia-purifier publish <registry> [--push] [dir]builds and tests the committed tree of the project with Nix, and then registers the version of each package with LocalRegistry.jl.registryis the name or URL of a registry. A Julia package has no archive to upload: a version is an entry in a registry that names a git tree. Thereleasetherefore holds the source and tree hash that Nix built and tested, andpublishregisters that tree. The command stops if the released tree differs from the committed one. For the General registry, which accepts versions through its Registrator bot, register the commit that this command has built.
A build can instead keep its lockfiles outside the repository. The
purifier lockfile is then named by --lockfile <path>, right after the name
of the command, or by the environment variable JULIA_PURIFIER_LOCKFILE.
The Manifest.toml is named by --tool-lockfile <path> or by
JULIA_PURIFIER_TOOL_LOCKFILE. With either one, lock and update read and
write the file there and leave the copy in the tree as it is. When the file
does not exist yet, they start from the copy in the tree. A flag takes
precedence over its variable, and both take precedence over the files in the
tree.
Using locked dependencies
julia-purifier keeps Julia’s development workflow on locked, Nix-resolved dependencies. Use the normal build and test commands in your working tree; building the project itself in the Nix sandbox is an optional next step.
Working offline
julia-purifier prefetch
prefetch realizes in the Nix store everything development needs for the
current system: the dependency sources, the test dependencies, the
registries, the Julia the manifest names and the language server. It keeps
them alive with a garbage-collector root at .julia-purifier/prefetch, next
to the lockfile. Add .julia-purifier/ to .gitignore. After a prefetch,
julia, Pkg.instantiate(), Pkg.test() and the editor work with the
network cut off. Pkg.test resolves its environment against the registry
snapshot in the lockfile, so it needs no network either.
Anything that is not in the lockfile still needs the network: a new
dependency, or a version that Pkg has to resolve against a newer registry.
Such a command stops with the own error of Pkg, and julia-purifier lock or
julia-purifier update records the new download.
Language tooling integration
julia-purifier language-server runs LanguageServer.jl
on standard input and output for the project, from the environment that
prefetch realized. Point the Julia language-server setting of the editor at
this command, in the directory of the project. The server finds the
dependencies in the prefetched depot and needs no network; its index goes
under $XDG_CACHE_HOME/julia-purifier.
For a tool that wants to start Julia itself, eval "$(julia-purifier env)"
puts the locked environment on its PATH.
Nix builds
Once the native development workflow is working, you can also build and test the whole project in the Nix sandbox. For this step, keep a flake or another Nix build definition in the project’s repository, or maintain an external packaging repository that points at its sources and lockfiles. The builder consumes the same lockfiles as the development workflow.
The overlay adds one attribute to the package set, the scope
pkgs.julia-purifier, which holds the builder buildJuliaProject and the
command julia-purifier. The result of the build has bin/<app> for each
entry of the [apps] table of the package.
A project whose authors want a flake packages it with the same builder. The flake can live in the repository of the project or in another repository:
{
inputs.julia-purifier.url =
"github:nix-purifiers/julia-purifier";
inputs.nixpkgs.follows = "julia-purifier/nixpkgs";
outputs =
{ nixpkgs, julia-purifier, ... }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
overlays = [ julia-purifier.overlays.default ];
};
project = pkgs.julia-purifier.buildJuliaProject {
src = ./.;
};
in
{
packages.${system}.default =
project.packages.MyPackage;
checks.${system}.tests = project.tests;
};
}
julia-purifier.overrideScope replaces what the scope shares, and
buildJuliaProject.override replaces the packages that the builder takes
from the package set, such as julia_113-bin. The builder takes
src, the project root: the directory with the manifest (the root of a workspace)lockFile, which defaults tojulia-purifier.lock.jsoninsrc. A lockfile outsidesrctakes the place of any lockfile in itmanifest, which defaults to theManifest.tomlinsrc. A copy kept outsidesrctakes the place of the one insrcfor the buildfetchers, which goes unchanged tofetchEntryandtreeof the shared library. A company mirror or credentials go intofetchers.fetchurljulia, the Julia to build with. The default is thejulia_1XY-binof the package set for the major and minor version the manifest namesdoCheck, which makes building each package run its testsprecompile, which defaults to true. Julia stamps every precompiled cache with a build identifier, so two builds with precompiled caches differ in those files.precompile = falsemakes every output reproducible, and Julia then compiles on first use
The result has these attributes, all known at evaluation time:
packages.<Name>: one per project that is a Julia package, which is the root and each package in the[workspace]of a workspace. It hasbin/<app>for each entry of the[apps]table of the package, which runs themainof the package (Julia 1.12 and newer), andshare/julia-purifier/project, the source of the package.packages.<Name>.testsis the run of the tests of that package, or null when it has nonetests: the run of the tests of every package, offline. A package whose test dependencies are in[extras]or atest/Project.tomlruns in the environment the lock recorded fromPkg.test; a test project in the workspace runs as itselfrelease: whatjulia-purifier publishregisters, which is the source of each package with its git tree hash. It depends ontests, so only a tested source is releasedfetches: the entries of the lock, as download entries of the shared purifier library. SBOM, license and vulnerability tools read this listenvironment:bin/juliawith the project activedepot: the depot of the dependencies, with their sources, artifacts, registries, the output of theirdeps/build.jlscripts and their precompiled caches. It depends only on the manifest and the lockfilecompiled: the precompiled caches of the packages of the projecteditor: the environment of the language server (see Editor)
The library of the flake holds
lib.julia-purifier.readLock { src, lockFile ? ..., manifest ? null },
which reads the manifest and the lockfile into the shared shape
{ purifier; entries; outputs; problems; }. A stale, tampered, malformed or
incomplete lockfile shows up in problems, and the builder fails
evaluation with it.
nix shell 'github:nix-purifiers/julia-purifier' gives a shell with the
julia-purifier command.
One-off builds without a project Nix file
For an ad hoc build, the builder can also be evaluated directly from the project root. Replace the example package name with one from your project:
nix build --impure --expr 'let
purifier = builtins.getFlake "github:nix-purifiers/julia-purifier";
pkgs = import purifier.inputs.nixpkgs {
system = builtins.currentSystem;
overlays = [ purifier.overlays.default ];
};
in
(pkgs.julia-purifier.buildJuliaProject { src = ./.; })
.packages.MyPackage'
This uses the purifier’s pinned nixpkgs, matching the lock command above.
To build with ambient <nixpkgs> from your Nix search path instead,
replace import purifier.inputs.nixpkgs with import <nixpkgs>.
Both forms need no Nix files in your project. The build tool and language
versions must match the lockfile; with ambient nixpkgs, lock with the
purifier from that package set or pass a compatible toolchain to the builder.
Supported scope
Supported language repositories
Supported:
- Packages from the Julia package server, as tarballs, with the storage
server as a mirror when the server is the public one.
JULIA_PKG_SERVERnames another server - Packages with a
repo-urlin the manifest, and packages of a registry that the package server does not serve, as a git checkout of the commit whose tree is the tree of the package, including a package in a subdirectory - Artifacts, including lazy ones, from the URL and hash in the Artifacts.toml of the package, for x86_64-linux, aarch64-linux and aarch64-darwin
- Workspaces, test environments in
[extras],[targets]or atest/Project.toml, packages with adeps/build.jl, and a manifest kept outside the source
Refused, with a message from the lock run:
- A git dependency with a local path as its URL, which Nix cannot fetch
- A manifest older than format 2, or one for a Julia that nixpkgs lacks
(1.10 to 1.13 today) unless
juliais passed - A registry that Pkg keeps as a git clone in the fresh depot of the lock
SSH URLs are recorded as the HTTPS URL of the same host, since the sandbox
has no SSH keys. A private repository then needs a fetchers entry with
credentials.
Target systems
- x86_64-linux
- aarch64-linux
- aarch64-darwin
Platform limitations and validation
- Apple Silicon macOS support is contributor-reported from unsandboxed builds; no macOS CI is configured
- Sandboxed Darwin –check rebuilds have not been verified
- Reported CLI validation used nixpkgs-unstable for julia_113-bin; an older machine registry may not contain that package
Troubleshooting
Each of these fails the command and the Nix evaluation with a message that names the file and the command to run:
| Problem | Message says | Fix |
|---|---|---|
| A lockfile older than the project: the manifest or a Project.toml changed | <file> changed since the lockfile was made |
julia-purifier lock |
| A lockfile edited by hand, truncated, or not JSON | does not match the hash of its own content |
julia-purifier lock |
| A lockfile of another format version | has format N |
julia-purifier lock |
| A package the manifest pins has no hash in the lockfile | has no hash for <Name> |
julia-purifier lock |
| No lockfile | does not exist |
julia-purifier lock |
| A lockfile without artifacts for the system | records no artifacts for <system> |
Build on a system the lock covers (x86_64-linux, aarch64-linux or aarch64-darwin) |
A changed hash with a correct content hash (the lockfile was written by a
tool other than lock) fails the download of that file with the hash
mismatch error of Nix. A deps/build.jl that downloads files itself fails in
the sandbox, because Pkg records nothing of such downloads. Current packages
fetch binaries as artifacts instead, which the lock records.
Precompiled caches are not reproducible bit for bit, because Julia stamps
each one with a build identifier. precompile = false makes every output
reproducible, and Julia then compiles on first use.
Examples
For day-to-day work on these projects, use the native-tool setup and commands in Quickstart and Development loop. The Nix expressions below show optional sandboxed packaging of those projects.
This example builds and tests JSON3.jl,
a package that commits no Manifest.toml. In a clone of the repository, lock
the project:
nix shell 'github:nix-purifiers/julia-purifier'
git clone https://github.com/quinnj/JSON3.jl
cd JSON3.jl
julia-purifier lock
The lock resolves the project, and writes Manifest.toml and
julia-purifier.lock.json into the clone. Then build the package from the
directory of the clone:
nix build --impure --expr 'let
purifier = builtins.getFlake "github:nix-purifiers/julia-purifier";
pkgs = import purifier.inputs.nixpkgs {
system = builtins.currentSystem;
overlays = [ purifier.overlays.default ];
};
in
(pkgs.julia-purifier.buildJuliaProject { src = ./.; })
.packages.JSON3'
To run the test suite of JSON3.jl in the sandbox, build .tests in place of
.packages.JSON3.