gleam2nix provides an overlay for building Gleam projects.
If you're starting a new project, you can use the included template. Create a new directory for your project, then run
nix flake init --template github:mtoohey31/gleam2nix.
If you're using flakes, start by adding gleam2nix.overlays.default to your nixpkgs overlays. If you're not using flakes, you can import the overlay directly from the overlay.nix file. This overlay defines the buildGleamProgram helper, which can be used to export an Erlang shipment from your Gleam project, and create a wrapper script to its entrypoint in the output bin directory. The only required parameter is src, which should usually be a path to the root of your Gleam project, the directory containing the gleam.toml and manifest.toml files (though project-root may be useful if you have multiple related packages within your source). Package name and version are inferred from the gleam.toml file. There are three optional parameters:
bin-namecan be used to rename the binary wrapper added to the output path'sbindirectory. If not provided, it defaults to the package name inferred fromgleam.toml.project-rootcan be used when the package you want to build isn't located at the root ofsrc(but you can't just adjustsrcto be the subdirectory since your main package depends on local packages located elsewhere insidesrc). Defaults to.(the root ofsrc).doCheckindicates whethergleam testshould be run during the derivation'scheckPhase. If not provided, it is set iffsrc + "/${project-root}$/test"exists.