# Zig2nix: nix flake for packaging, building and running Zig projects

**URL:** <https://ziggit.dev/t/zig2nix-nix-flake-for-packaging-building-and-running-zig-projects/2830>\
**Category:** Showcase\
**Created:** [January 12, 2024, 3:12am UTC](https://ziggit.dev/t/zig2nix-nix-flake-for-packaging-building-and-running-zig-projects/2830 "2024-01-12T03:12:17Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Cloudef](https://ziggit.dev/user_avatar/ziggit.dev/cloudef/32/1370_2.png) [@Cloudef](https://ziggit.dev/u/Cloudef)\
**Post date:** [June 12, 2024, 5:49am UTC](https://ziggit.dev/t/zig2nix-nix-flake-for-packaging-building-and-running-zig-projects/2830/8 "2024-06-12T05:49:22Z")

</div>

Inspired by [GitHub Actions: mlugg/setup-zig](https://ziggit.dev/t/github-actions-mlugg-setup-zig/4659)  
To have good caching on github actions for your zig2nix projects, you can use these 2 actions:

```zig
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main

```

The first one installs `nix`, the second one caches the `/nix/store`.  
The action automatically avoids caching anything that’s already cached in the official binary cache of nixpkgs.  
All `build.zig.zon` dependencies will be cached as well if you use zig2nix’s package functions.

The caching can be seen in in action for example in the zig2nix repository itself:  
[https://github.com/Cloudef/zig2nix/actions/caches](https://github.com/Cloudef/zig2nix/actions/caches)

One caveat is this currently caches even small outputs, which I’ve filled a issue:  
[https://github.com/DeterminateSystems/magic-nix-cache-action/issues/31](https://github.com/DeterminateSystems/magic-nix-cache-action/issues/31)  
PR fixing it [https://github.com/DeterminateSystems/magic-nix-cache/pull/69](https://github.com/DeterminateSystems/magic-nix-cache/pull/69)

---

_[View the full topic](https://ziggit.dev/t/zig2nix-nix-flake-for-packaging-building-and-running-zig-projects/2830)._
