Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a 'zonMeta' attribute to output nix expression #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

icetan
Copy link

@icetan icetan commented Jun 11, 2024

Add a passthru attribute to the link farm derivation which contains metadata from the zon-file. Useful for setting package name and version in one place.

It doesn't break the current interface as the extra metadata is accessible on the derivation:

deps = callPackage ./deps.nix { };
pkg = mkDerivation {
  name = "${deps.zonMeta.name}-${deps.zonMeta.version}";
  postPatch = ''
    ln -s ${deps} $ZIG_GLOBAL_CACHE_DIR/p
  '';
  ...
};

Input build.zig.zon:

.{
    .name = "zink",
    .version = "0.0.2",
    .license = "MIT",
    .author = "icetan",
    .dependencies = .{
        .@"glob-zig" = .{
            .url = "https://github.com/icetan/glob-zig/archive/main.tar.gz",
            .hash = "122009122341200514961d7b8215b07ef5b9ff4db61eeb5cd2a4949716d14761373a",
        },
    },
    .paths = .{
        "build.zig",
        "build.zig.zon",
        "src",
    },
}

Results in Nix output:

{ linkFarm, fetchzip }:

(linkFarm "zig-packages" [
  {
    name = "122009122341200514961d7b8215b07ef5b9ff4db61eeb5cd2a4949716d14761373a";
    path = fetchzip {
      url = "https://github.com/icetan/glob-zig/archive/main.tar.gz";
      hash = "sha256-OVRHNvp5F/HRwAIFOah1r7aMnNNBctXpGsY7cOh3MsA=";
    };
  }
]).overrideAttrs {
  passthru.zonMeta = {
    "author" = "icetan";
    "license" = "MIT";
    "name" = "zink";
    "version" = "0.0.2";
  };
}

For now only metadata that is a string will be added. In the future .paths might be nice to convert to nix paths to use in source filters.

Hope this is useful :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant