2022-08-22 15:56:44 -07:00
|
|
|
# Nix Flake for Zig
|
|
|
|
|
2023-08-09 22:27:27 +04:00
|
|
|
This repository is a Nix flake packaging the [Zig](https://ziglang.org)
|
2022-08-22 15:56:44 -07:00
|
|
|
compiler. The flake mirrors the binaries built officially by Zig and
|
|
|
|
does not build them from source.
|
|
|
|
|
2022-08-22 19:10:14 -07:00
|
|
|
This repository is meant to be consumed primarily as a flake but the
|
|
|
|
`default.nix` can also be imported directly by non-flakes, too.
|
2022-08-22 15:56:44 -07:00
|
|
|
|
2022-08-22 19:10:14 -07:00
|
|
|
The flake outputs are documented in `flake.nix` but an overview:
|
|
|
|
|
|
|
|
* Default package and "app" is the latest released version
|
|
|
|
* `packages.<version>` for a tagged release
|
2022-08-22 19:31:09 -07:00
|
|
|
* `packages.master` for the latest nightly release
|
|
|
|
* `packages.master-<date>` for a nightly release
|
2023-04-03 11:50:59 -04:00
|
|
|
* `overlays.default` is an overlay that adds `zigpkgs` to be the packages
|
2022-08-22 19:31:09 -07:00
|
|
|
exposed by this flake
|
2023-04-03 11:50:59 -04:00
|
|
|
* `templates.compiler-dev` to setup a development environment for Zig
|
2022-08-23 09:44:15 -07:00
|
|
|
compiler development.
|
2022-08-22 15:56:44 -07:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2022-08-23 09:44:15 -07:00
|
|
|
### Flake
|
2022-08-22 15:56:44 -07:00
|
|
|
|
|
|
|
In your `flake.nix` file:
|
|
|
|
|
|
|
|
```nix
|
|
|
|
{
|
|
|
|
inputs.zig.url = "github:mitchellh/zig-overlay";
|
2022-08-22 19:10:14 -07:00
|
|
|
|
2022-08-22 15:56:44 -07:00
|
|
|
outputs = { self, zig, ... }: {
|
|
|
|
...
|
|
|
|
};
|
|
|
|
}
|
|
|
|
```
|
|
|
|
In a shell:
|
|
|
|
|
|
|
|
```sh
|
2022-08-22 19:10:14 -07:00
|
|
|
# run the latest released version
|
2022-08-22 15:56:44 -07:00
|
|
|
$ nix run 'github:mitchellh/zig-overlay'
|
2022-08-22 19:31:09 -07:00
|
|
|
# open a shell with nightly version dated 2021-02-13 (oldest version available)
|
|
|
|
$ nix shell 'github:mitchellh/zig-overlay#master-2021-02-13'
|
|
|
|
# open a shell with latest nightly version
|
|
|
|
$ nix shell 'github:mitchellh/zig-overlay#master'
|
2022-08-22 15:56:44 -07:00
|
|
|
```
|
2024-06-26 02:13:55 +03:00
|
|
|
### Adding zig as a package
|
|
|
|
|
|
|
|
To access zig as a package:
|
|
|
|
In your `flake.nix` file:
|
|
|
|
|
|
|
|
```nix
|
|
|
|
{
|
|
|
|
inputs.zig.url = "github:mitchellh/zig-overlay";
|
2022-08-22 15:56:44 -07:00
|
|
|
|
2024-06-26 02:13:55 +03:00
|
|
|
outputs = { self, zig, ... }: {
|
|
|
|
...
|
|
|
|
modules = [
|
|
|
|
{nixpkgs.overlays = [zig.overlays.default];}
|
|
|
|
...
|
|
|
|
...
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
```
|
|
|
|
In your `configuration.nix` file :
|
|
|
|
|
|
|
|
```nix
|
|
|
|
{pkgs,inputs, ...}: {
|
|
|
|
...
|
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.zigpkgs.master # or <version>/master-<date>/
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
2022-08-23 09:44:15 -07:00
|
|
|
### Compiler Development
|
|
|
|
|
|
|
|
This flake outputs a template that makes it easy to work on the Zig
|
|
|
|
compiler itself. If you're looking to contribute to the Zig compiler,
|
|
|
|
here are the easy steps to setup a working development environment:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
# clone zig and go into that directory
|
|
|
|
$ git clone https://github.com/ziglang/zig.git
|
|
|
|
$ cd zig
|
|
|
|
# setup the template
|
2022-08-23 21:56:52 -07:00
|
|
|
$ nix flake init -t 'github:mitchellh/zig-overlay#compiler-dev'
|
2022-08-23 09:44:15 -07:00
|
|
|
# Two options:
|
|
|
|
# (1) start a shell, this forces bash
|
|
|
|
$ nix develop
|
|
|
|
# (2) If you have direnv installed, you can start the shell environment
|
|
|
|
# in your active shell (fish, zsh, etc.):
|
|
|
|
$ direnv allow
|
|
|
|
```
|
|
|
|
|
2022-09-05 21:28:07 -07:00
|
|
|
## FAQ
|
|
|
|
|
|
|
|
### Why is a Nightly Missing?
|
|
|
|
|
|
|
|
There are two possible reasons:
|
|
|
|
|
|
|
|
1. The Zig download JSON that is used to generate this overlay only shows
|
|
|
|
the latest _master_ release. It doesn't keep track of historical releases.
|
|
|
|
If this overlay wasn't running or didn't exist at the time of a release,
|
|
|
|
we could miss a day. This is why historical dates beyond a certain point
|
|
|
|
don't exist; they predate this overlay (or original overlays this derives
|
|
|
|
from).
|
|
|
|
|
|
|
|
2. The official Zig CI only generates a master release if the CI runs
|
|
|
|
full green. During certain periods of development, a full day may go by
|
|
|
|
where the master branch of the Zig compiler is broken. In this scenario,
|
|
|
|
a master build (aka "nightly") is not built or released at all.
|
|
|
|
|
2022-08-22 15:56:44 -07:00
|
|
|
## Thanks
|
|
|
|
|
2022-08-23 21:56:52 -07:00
|
|
|
The `sources.json` file was originally from another Zig overlay repository
|
|
|
|
hosted by the username `arqv`. This user and repository was deleted at some
|
|
|
|
point, so I started a new flake based on the same `sources.json` format
|
|
|
|
they used so I could inherit the history. Thank you for compiling nightly
|
|
|
|
release information since 2021!
|