nix is a purely functional package manager with fully-cacheable, to-the-byte reproducible builds.
This guide documents how people using the Nix package manager or NixOS systems can easily build every version of Gleam with just a single command.
For using this guide you'll need nix
version 2.8
or latter which must have the flakes
feature enabled.
See nix quick-install or the install-nix tutorial for more in depth instructions.
# This will install gleam from latest commit on main branch.
nix profile install github:dhnaranjo/gleam-nix --override-input gleam github:gleam-lang/gleam/main
gleam --help
The following command runs gleam --help
on the build from
the latest commit on main
branch.
# The latest commit from Gleam's main branch. (can be a commit hash, tag or branch name)
nix shell github:dhnaranjo/gleam-nix --override-input gleam github:gleam-lang/gleam/main -c gleam --help
Gleam maintainers can also use this to try PR experimental features from other contributors just by overriding where the Gleam source comes from specifying the repository/branch name.
# running gleam to try other people branches:
nix shell github:dhnaranjo/gleam-nix --override-input gleam github:<someone>/gleam/<cool-feature> -c gleam --help
Also, for Gleam developers, using Nix ensures we get the same development environment in an instant, all you have to do is checkout the Gleam repo and run:
nix develop github:dhnaranjo/gleam-nix --override-input gleam path:$PWD # -c fish # you might use your preferred shell
# open your editor and hack hack hack..
cargo build # build dependencies are loaded in your shell
# or
nix run github:dhnaranjo/gleam-nix --override-input gleam path:$PWD -- --help # runs your local `gleam --help`
[Nix flakes] are the secret sauce for nix reproducible builds.
Since all build dependencies get hashed, even the source code.
Every external dependency such external repos (e.g. nixpkgs),
external utilities (e.g. cargo llvm make), and any Cargo.toml
workspace dependency (read from Cargo.nix
) gets hashed so that
nix only builds what has actually changed.
If you edit the flake.nix
file, for example to change the rust
toolchain or the nixpkgs revision, run nix flake udpate
afterwards
to regenerate the lock file.
From time to time the Cargo.nix
file needs to be re-generated
by using cargo2nix
in order to keep Gleam's cargo deps nix-controlled.
make generate