Convert the dependencies in build.zig.zon to a Nix expression [maintainer=@figsoda] https://discourse.nixos.org/t/31468
  • Zig 91.1%
  • Nix 8.9%
Find a file
Tristan Ross 8c2ef6d376
Merge pull request #61 from Sh4pe/fix-redirects-issue-60
Follow redirects for dependency URLs
2026-02-05 16:21:46 -08:00
.github Run issue 60 integration tests with debug output 2026-02-06 00:55:43 +01:00
fixtures Add some integration tests for issue 60 and run them in CI 2026-02-06 00:55:43 +01:00
nix Run issue 60 integration tests with debug output 2026-02-06 00:55:43 +01:00
src Add some integration tests for issue 60 and run them in CI 2026-02-06 00:55:43 +01:00
.gitignore Update to zig 0.13 2024-08-24 23:32:07 +02:00
build.zig Update code and buildsystem to 0.16 2026-01-03 23:33:43 +01:00
CHANGELOG.md bump version 2023-09-03 19:26:50 -04:00
flake.lock Update used Zig version to a newer 0.16 nightly 2026-02-05 14:46:54 +01:00
flake.nix Run issue 60 integration tests with debug output 2026-02-06 00:55:43 +01:00
LICENSE initial commit 2023-08-08 15:18:39 -04:00
README.md readme: add example 2023-09-03 19:40:02 -04:00

zon2nix

Convert the dependencies in build.zig.zon to a Nix expression

Usage

zon2nix > deps.nix
zon2nix zls > deps.nix
zon2nix zls/build.zig.zon > deps.nix

To use the generated file, add this to your Nix expression:

postPatch = ''
  ln -s ${callPackage ./deps.nix { }} $ZIG_GLOBAL_CACHE_DIR/p
'';

Example

This build.zig.zon from zls

.{
    .name = "zls",
    .version = "0.11.0",

    .dependencies = .{
        .known_folders = .{
            .url = "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz",
            .hash = "122048992ca58a78318b6eba4f65c692564be5af3b30fbef50cd4abeda981b2e7fa5",
        },
        .diffz = .{
            .url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz",
            .hash = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864",
        },
        .binned_allocator = .{
            .url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz",
            .hash = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5",
        },
    },
}

produces the following nix expression

# generated by zon2nix (https://github.com/nix-community/zon2nix)

{ linkFarm, fetchzip }:

linkFarm "zig-packages" [
  {
    name = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5";
    path = fetchzip {
      url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz";
      hash = "sha256-m/kr4kmkG2rLkAj5YwvM0HmXTd+chAiQHzYK6ozpWlw=";
    };
  }
  {
    name = "122048992ca58a78318b6eba4f65c692564be5af3b30fbef50cd4abeda981b2e7fa5";
    path = fetchzip {
      url = "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz";
      hash = "sha256-U/h4bVarq8CFKbFyNXKl3vBRPubYooLxA1xUz3qMGPE=";
    };
  }
  {
    name = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864";
    path = fetchzip {
      url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz";
      hash = "sha256-3CdYo6WevT0alRwKmbABahjhFKz7V9rdkDUZ43VtDeU=";
    };
  }
]