Referring to another derivation (dependency) in the build step

Let’s say some package foo depends on a package abc such that when foo is built, it expects abc to be under /usr/local/bin or at a location referred by an environment variable, ABC_BIN_DIR. How can one access the location of abc (under /nix/store/...) in order to set the ABC_BIN_DIR env var in the builder script.

The following derivation snippet can be used as an example:

with import <nixpkgs> {};

stdenv.mkDerivation {
  name = "foo";
  src = fetchFromGitHub {
    owner = "xyz";
    repo = "foo";
    rev = "zzz...";
    sha256 = "aaa...";
    fetchSubmodules = true;
  buildInputs = [ (import ./abc.nix { }) ];
  builder = ./;

Can abc's location be access via the outPath attribute (as suggested in NixOS - Nix Pills)?

Does one need to set an attribute such as in:

  abc =  import ./abc.nix { };
  stdenv.mkDerivation {
    # ...
   inherit abc;

and then in

source $stdenv/setup

export ABC_BIN_DIR=$abc.outPath

when you interpolate a derivation, you get the store path:

  buildPhase = ''
    export ABC_BIN_DIR=${abc}/bin

I go over some basic nix usage in some of my videos:

I’m planning to do a more “refined” series once the 20.09 release is done