Building Python Package with Dynamically Linked System Library, `attribute 'dev' missing`

I’m still pretty naive with Nix, but I’m trying to build and package a larger program and I’m having issues with one of the dependencies I also have to package. Namely pyzstd. I could let it use the copy of the zstd source as it mentions here, but for the sake of using system libraries if possible I decided try my hand at it.

I’m using pkgs/development/python-modules/indexed-zstd/default.nix as a reference since it also just simply needs zstd like how I do and using the documentation on packaging existing software, thus making my own version as pyzstd.nix

{ lib
, buildPythonPackage
, fetchPypi
, zstd
, cython
}:
let
  _pinData = import ./pin.nix;
  pinData = _pinData.pyzstd;
in
buildPythonPackage rec {
  pname = "pyzstd";
  version = pinData.version;

  src = fetchPypi {
    inherit pname version;
    hash = pinData.hash;
  };

  nativeBuildInputs = [
    cython
  ];

  buildInputs = [
    zstd.dev
  ];

  pythonImportsCheck = [
    "pyzstd"
  ];

  setupPyBuildFlags = [
    "--dynamic-link-zstd"
  ];
}

And the abridged pin.nix

{
  # [...] Other unrelated pins for the larger project.
  "pyzstd" = {
    "version" = "0.15.9";
    "hash" = "sha256-y/3ebFdo/6XS8UEnu8HXw8LQPAzq6wc2lGGX4GJ1zMc=";
  };
}

and abridged default.nix

let
  pkgs = import <nixpkgs> { };
in
{
  # [...] Other unrelated packages for the larger project.
  pyzstd = pkgs.python3Packages.callPackage ./pyzstd.nix { };
}

But then it throws that the dev attribute for zstd does not exist. Copying and pasting the reference also results in the same error.

error:
       … while evaluating the attribute 'drvPath'

         at /nix/store/91gykwfb9935iynbpyq0ykvr30lvb4ia-nixos/nixos/lib/customisation.nix:263:7:

          262|     in commonAttrs // {
          263|       drvPath = assert condition; drv.drvPath;
             |       ^
          264|       outPath = assert condition; drv.outPath;

       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'dev' missing

       at /home/jarrod/Workspace/XXX/pyzstd.nix:25:5:

           24|   buildInputs = [
           25|     zstd.dev
             |     ^
           26|   ];

9hp71n from the Nix Matrix chat:

You need to pass inherit (pkgs) zstd to python3Packages.callPackage because apparently there is python310Packages.zstd (python bindings to zstd) that would get picked up instead of just pkgs.zstd by default.\nhttps://github.com/NixOS/nixpkgs/blob/6e62521155cd3b4cdf6b49ecacf63db2a0cacc73/pkgs/top-level/python-packages.nix#L5488

So I added inherit (pkgs) zstd; in the let block and that seemed fix the issue.

1 Like