# If you already have Nix installed, try Gleam right away by using:
$ nix shell github:vic/gleam-nix
$ gleam --version
gleam 0.30.0
There exists an stable-release gleam derivation on nixpkgs. To use it, simply do:
nix shell nixpkgs#gleam
gleam --version
The flake provided on this repo is most likely to be used by people hacking on gleam itself or willing to build some experimental branches.
For using this flake 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:vic/gleam-nix --override-input gleam github:gleam-lang/gleam/main
gleam --help
Using the overlay provided by this flake you can add Gleam to any NixOS system or flake-controlled project environment of yours.
{
inputs.gleam-nix.url = "github:vic/gleam-nix";
outputs = { gleam-nix, nixpkgs, ... }:
let
system = "aarch64-darwin"; # or anything you use.
pkgs = import nixpkgs {
inherit system;
overlays = [ gleam-nix.overlays.default ];
};
in {
packages.${system}.gleam = pkgs.gleam;
};
}
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:vic/gleam-nix --override-input gleam path:$PWD
# open your editor and hack hack hack..
cargo run # build dependencies are loaded in your shell
Gleam maintainers can also use this to try PR experimental features from other contributors. Just override where the Gleam source comes from by specifying the repository/branch name.
# running gleam to try other people branches:
nix shell github:vic/gleam-nix --override-input gleam github:<someone>/gleam/<cool-branch> -c gleam --help
Most of the time this flake should be able to build the latest Gleam source.
# Test that the main branch or any other commit is buildable.
nix flake run --override-input gleam github:gleam-lang/gleam/main -- --version
However, as Gleam development progresses, this flake might get outdated since dependencies to build Gleam might have changed. Most of the time, this should be fixed by regenerating the Cargo.nix file as instructed bellow.
If you contribute a PR, be sure to also update the latest Gleam version known to build at the first section of this document, so that people can use the git history if the need to find the commit that can build older versions.
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.
Also run nix run '.#fmt'
to keep al nix files formatted before sending a PR.
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.
This is needed when Gleam introduces new dependencies or their versions get updated.
nix run '.#genCargoNix'
By default this package will build using the latest stable nixpkgs release.
If you need to update to a most recent release, edit the nixpkgs.url
line on flake.nix.
By default this package will build using the latest rust-stable version.
If you need to update it, edit the rustChannel
version at flake.nix.