Package builds with `nix-build` but not as overlay

I’ve been trying to debug a bluetooth issue I have which may have been resolved in the last version of the bluez package, v5.76. The latest version in nixpkgs is v5.75 so I thought this would be a good opportunity to learn how to package software in general.

First I copied the bluez package.nix file from nixpkgs and built it using nix-build -A bluez and the following default.nix:

  nixpkgs = fetchTarball "";
  pkgs = import nixpkgs {
    config = { };
    overlays = [ ];
  bluez = pkgs.callPackage ./package.nix { };

As expected, it built just fine. Next, I tried to add this current version of the package as an overlay to make sure that works before updating the actual package. I want to use an overlay so that other packages (like pipewire) also use my custom bluez package. I do that by importing the following module into my config:

{pkgs, ...}:
  nixpkgs.overlays = [
    (self: super: {
      bluez = pkgs.callPackage ./package.nix {};

where package.nix is again the current version of the bluez package. However, when I try to rebuild the config with nixos-rebuild pipewire fails to build.

Is this the way to do it? Can someone point me in the right direction?