vic / 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.

 
  # If you already have Nix installed, try Gleam right away by using:
  $ nix shell github:vic/gleam-nix
  $ gleam --version
  gleam 0.30.0
 

Build history

Stable releases at nixpkgs#gleam

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.

Requirements

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.

Installing Gleam locally (~/.nix-profile)

# 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

Installing Gleam on a flake.

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;
     };
}

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: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

Contributing

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.

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.

This is needed when Gleam introduces new dependencies or their versions get updated.

nix run '.#genCargoNix'

Updating nixpkgs version

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.

Updating the rust toolchain.

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.

About

Build Gleam with Nix.

https://gleam.run

License:Apache License 2.0


Languages

Language:Nix 99.8%Language:Makefile 0.2%