dhnaranjo / gleam-nix

Build Gleam with Nix.

Home Page:https://gleam.run

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reproducible builds for Gleam.

Build history

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.

Screen Shot 2021-12-20 at 18 31 47

Requirements

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.

Installing Gleam locally (~/.nix-profile)

# 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

Running Gleam nightly. (or any branch/commit)

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

Developing Gleam with a Nix environment.

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`

flake.nix

[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.

Regenerating Cargo.nix

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

About

Build Gleam with Nix.

https://gleam.run

License:Apache License 2.0


Languages

Language:Nix 99.8%Language:Makefile 0.2%