···55-->
6677# gleam2nix
88+[](https://github.com/fasterthanlime/free-of-syn)
99+
810911tools for building [gleam](https://gleam.run) projects with [nix](https://nixos.org).
1212+1313+## quickstart
1414+the general flow goes like:
1515+1. use the `gleam2nix gen-nix` tool to generate a `gleam.nix` file from your gleam project's `manifest.toml`
1616+2. call `buildGleamApplication` to produce a derivation for your project
1717+1818+to get gleam2nix important, pick one of the following based on your project structure:
1919+2020+<details>
2121+<summary>plain nix</summary>
2222+first, pull in this repo through whatever dependency management mechanism you prefer, such as [npins](https://github.com/andir/npins) or just a plain ol' `fetchTarball`. from the repo, you can import one of the following, based on how you want to use gleam2nix:
2323+2424+- `default.nix` (recommended): contains all the packages and functions you'll need
2525+- `nix/overlay.nix`: an overlay function that can be added to nixpkgs. note that if you're using this, you'll also need to have [fenix](https://github.com/nix-community/fenix) added as an overlay - check their readme for setup instructions.
2626+2727+both options will define the following:
2828+- `gleam2nix`: the `gleam2nix` cli tool
2929+- `buildGleamApplicaton`: function for building a gleam application
3030+- `buildGleam`: low-level function to compile a single gleam package
3131+</details>
3232+3333+<details>
3434+<summary>flake-based</summary>
3535+first, add this repo as a flake input:
3636+```nix
3737+inputs = {
3838+ gleam2nix.url = "git+https://git.isincredibly.gay/srxl/gleam2nix";
3939+ gleam2nix.inputs.nixpkgs.follows = "nixpkgs"; # optional
4040+}
4141+```
4242+4343+the flake will have the following relevant outputs:
4444+4545+- `packages.<system>.gleam2nix`: the `gleam2nix` cli tool
4646+- `lib.<system>.buildGleamApplicaton`: function for building a gleam application
4747+- `lib.<system>.buildGleam`: low-level function to compile a single gleam package
4848+- `overlays.gleam2nix`: a nixpkgs overlay that adds all of the above to `pkgs`. note that if you're using this, you'll also need to have [fenix](https://github.com/nix-community/fenix) added as an overlay. gleam2nix re-exports the overlay from it's input as `overlays.fenix` if you need it, otherwise you can set that up however you like.
4949+</details>
5050+5151+once setup, you can add `gleam2nix` whereever you need it, for example, in a nix shell:
5252+```nix
5353+pkgs.mkShell {
5454+ name = "devshell";
5555+ packages = [
5656+ gleam2nix
5757+ ]
5858+}
5959+```
6060+6161+run `gleam2nix gen-nix` in the root of your project (ie. the folder containing your `manifest.toml`) to get a `gleam.nix` file. you can then pass it to a `buildGleamApplication` call to get your derivation:
6262+6363+```nix
6464+buildGleamApplication {
6565+ pname = "my-gleam-application";
6666+ version = "1.0.0";
6767+ src = ./.;
6868+6969+ gleamNix = import ./gleam.nix;
7070+}
7171+```
7272+7373+## roadmap
7474+- [x] build targeting the BEAM
7575+ - [x] `gleam export erlang-shipment` style packaging
7676+ - [ ] OTP releases
7777+ - [ ] escript packaging?
7878+- [ ] build targeting JS
7979+ - [ ] nodejs
8080+ - [ ] deno
8181+ - [ ] bun
8282+- [ ] upstream to nixpkgs
8383+ - [ ] `gleam2nix` cli
8484+ - [ ] builder functions
8585+8686+## contributing
8787+the canonical home of this repo is on my [personal git forge](https://git.isincredibly.gay/srxl/gleam2nix), which doesn't have open signups. if you want to submit some changes or report bugs, you can either:
8888+8989+- open issues/PRs on the [tangled mirror](https://tangled.org/@foxgirl.engineering/gleam2nix)
9090+- send me an email at `ruby@srxl.me` with issue reports or git patches
9191+9292+## licensing
9393+all code in this repo is available under the very permissive terms of the [zero-clause bsd](./LICENSES/0BSD.txt) license.