How to include a local derivation into a new application?

I want to write a new derivation for a new application (foo) that is not packaged yet.
I cloned nixpkgs and added a new folder as documented in the wiki.
(Nixpkgs/Create and debug packages - NixOS Wiki)
My application depends on a library (bar) that is not included in nixpkgs. I added it to nixpkgs/pkgs/development/libraries/bar and was able to build and install it the nix-store using the manuals and help-pages.

But how do I import the local library into my application’s ‘default.nix’ as a buildinput?
The answer seems to be overlays, but I cannot figure out the details.

Any advice or pointers appreciated.

Ah, and a happy new year.

If you’re working in a nixpkgs checkout, there’s no need for overlays. You need to link your package into the appropriate package set. If you’re not trying to use one of the ecosystem scopes, that means adding it to pkgs/top-level/all-packages.nix so it makes its way into the nixpkgs attrset, as well as being available as an argument to callPackaged files.

If you’re not aiming to submit a PR to nixpkgs, however, there are less annoying ways to have your package available than keeping a local fork, such as overlays, or just inlining your package expression where you use it, as packages don’t particularly need to come from pkgs.

Thank you, Jeff, for this answer. I’ll try to do as you suggested.