Export dependencies of a derivation

Given a package defined like this:

stdenv.mkDerivation {
  pname = "mypackage";
  version = "1.0";
  src = ./.;

  buildInputs = [
    nodejs
  ];

  buildPhase = ''
    ln -s ${npmDeps}/node_modules

    export PATH="$PATH:./node_modules/.bin"
    export NODE_ENV="production"

    vue-cli-service build --mode=${env}
  '';

  installPhase = ''
    cp -r dist $out/
  '';
}

Using the Nix CLI, I’m trying to get the list of build dependencies for this package, so that I can nix-store --export them to store them in the Gitlab CI cache. Here’s what I tried:

  • nix build it then nix-store -q -R --include-outputs (which has a promising description in the docs: “A cache deployment (combined source/binary deployment, including binaries of build-time-only dependencies) is obtained by distributing the closure of a store derivation and specifying the option –include-outputs.”). This only returns the final output of the derivation, without any inputs.
  • nix build it then nix-store -q -d ./result to get the path to the .drv, pass it to nix-store -q --references --include-outputs, then pass it nix-store -q --outputsto get the list of outputs instead of derivations, and finally pass this to nix-store --export. I’m a bit surprised I need all these steps, but it seems to work. However, when I use this on another package in my project (a Python package that uses dependencies from python3Packages), I get a weird error:
don't know how to build these paths:
  /nix/store/akfpvxfbsafn93jh915cf9zzqy3d7pqc-python3.12-django-structlog-9.1.1-dist
  /nix/store/ashy8hvywl1wvrwqqs8fjvpd5gmxrvgd-python3.12-celery-5.5.2-dist

My questions are:

  • Is there an easier way using CLI tools to get the list of dependencies for a given derivation?
  • Is there a way to get this list of dependencies without building the derivation itself?
  • What’s causing the error don’t know how to build these paths?

(please don’t respond with “use Cachix” :folded_hands: I’d like to understand what’s going on here)

1 Like