Skip to content

Convert the dependencies in `build.zig.zon` to a Nix expression [maintainer=@figsoda]

License

Notifications You must be signed in to change notification settings

xvzls/zon2nix

 
 

Repository files navigation

zon2nix

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

Usage

zon2nix help
Usage: zon2nix [subcommand]

Input:
  <stdin>  Zon file contents

Subcommands:
  help  Print help

Examples:
  Convert `build.zig.zon` to a nix file
  > zon2nix < build.zig.zon > build.zig.zon.nix
zon2nix < build.zig.zon > build.zig.zon.nix
cat build.zig.zon.nix
# Generated by a zon2nix fork
# repo: (https://github.com/xvzls/zon2nix)

{ linkFarm, fetchzip }:
{
	# A sha512 checksum of the contents of
	# build.zig.zon
	checksum = "fa4269d5f32b52c2444bef1d6948784d2799f8304331dc4569e0ab9f76f78da58eb9a5d767492e62ebc569bb61285ff64056e9ba45d114928964790897b8703a";
	
	name = "zls";
	version = "0.11.0";
	dependencies = 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=";
			};
		}
	];
}

To use the generated file, add this to your default.nix:

{
	pkgs ? import <nixpkgs>,
	zon ? pkgs.callPackage ./build-zig-zon.nix { },
}:
pkgs.stdenv.mkDerivarion {
	patchPhase = ''
		
		# Sha512 sum check
		
		checksum="$(sha512sum build.zig.zon | awk "{print \$1}")"
		if [ "${zon.checksum}" != "$checksum" ]; then
			>&2 echo "
				sha512 checksums don't match for build.zig.zon
				expected: ${zon.checksum}
				actual:   $checksum
			"
			exit 1
		fi
		
		# Storing cache
		
		export HOME="$TMPDIR"
		export ZIG_GLOBAL_CACHE_DIR="$HOME/.cache/zig"
		mkdir -p "$ZIG_GLOBAL_CACHE_DIR"
		
		ln -s ${zon.dependencies} "$ZIG_GLOBAL_CACHE_DIR/p"
	'';
}

Example

This build.zig.zon from dir-tree.

.{
	.name = "dir-tree",
	.version = "0.1.0",
	.paths = .{ "." },
	.dependencies = .{
		.clap = .{
			.url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.9.1.tar.gz",
			.hash = "122062d301a203d003547b414237229b09a7980095061697349f8bef41be9c30266b",
		},
	},
}

Produces the following nix expression:

# Generated by a zon2nix fork
# repo: (https://github.com/xvzls/zon2nix)

{ linkFarm, fetchzip }:
{
	# A sha512 checksum of the contents of
	# build.zig.zon
	checksum = "9cf0cb1f88e6e24d0caa38270a0ac255213f359815e7adfdd19e5f629db47e5f3874ba29745d6680b3113e08aee45ddfb8cc7f3aaf0795c937a878a3d0619889";
	
	name = "dir-tree";
	version = "0.1.0";
	dependencies = linkFarm "zig-packages" [
		{
			name = "122062d301a203d003547b414237229b09a7980095061697349f8bef41be9c30266b";
			path = fetchzip {
				url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.9.1.tar.gz";
				hash = "sha256-pscDsE1jJK1Nktq7rv/ScvsDqvvklFvtiGqOFf2eWvY=";
			};
		}
	];
}

About

Convert the dependencies in `build.zig.zon` to a Nix expression [maintainer=@figsoda]

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Zig 89.9%
  • Nix 10.1%