Best way to observe $src $out in mkDerivation

Hi there,

I have been using something like the following when I install a prebuilt binary from GitHub Releases.

{ lib, pkgs, ... }:
# https://github.com/dagger/dagger/releases
let version = "0.9.5";
in pkgs.stdenv.mkDerivation {
  name = "dagger";
  dontConfigue = true;
  src = pkgs.fetchzip {
    url =
      "https://github.com/dagger/dagger/releases/download/v${version}/dagger_v${version}_linux_amd64.tar.gz";
    sha256 = "sha256-RipH7gy9IL/xRlZy+KHIz8WfK1vrRUOdmY0G/rbc19c=";
    stripRoot = true;
  };
  phases = [ "installPhase" ];
  installPhase = ''
    mkdir -p $out/bin
    cp -r $src $out/bin/dagger
    chmod +x $out/bin/dagger
  '';

  meta = with lib; {
    description = "dagger - https://docs.dagger.io/.";
    maintainers = [ bashfulrobot ];
  };
}

Now, one of the things I always seem to have to muck around with, is figuring out what ends up in $src (structure wise), where the binary is, so I know how to copy it out into $out/bin.

My current process is to get it working to a point, and then use find in the results and adjust as needed. It feels wrong (likely is), and I assume there has to be a better way.

How are others doing this?

Thank you.

To get the result of fetchzip, you can use:

$ nix-build '<nixpkgs>' -A pkgs.hello.src
$ readlink ./result

(I am using the hello package as the example. Adjust your commands accordingly.)

But you would like to know $src, or $sourceRoot:

/tmp/test $ nix-shell '<nixpkgs>' -A pkgs.hello

[nix-shell:/tmp/test]$ echo $out
/nix/store/zhl06z4lrfrkw5rp0hnjjfrgsclzvxpm-hello-2.12.1

[nix-shell:/tmp/test]$ echo $src
/nix/store/pa10z4ngm0g83kx9mssrqzz30s84vq7k-hello-2.12.1.tar.gz

[nix-shell:/tmp/test]$ unpackPhase 
unpacking source archive /nix/store/pa10z4ngm0g83kx9mssrqzz30s84vq7k-hello-2.12.1.tar.gz
source root is hello-2.12.1
setting SOURCE_DATE_EPOCH to timestamp 1653865426 of file hello-2.12.1/ChangeLog

[nix-shell:/tmp/test]$ find $sourceRoot | head
hello-2.12.1
hello-2.12.1/build-aux
hello-2.12.1/build-aux/missing
hello-2.12.1/build-aux/gnupload
hello-2.12.1/build-aux/prefix-gnulib-mk
hello-2.12.1/build-aux/compile
hello-2.12.1/build-aux/texinfo.tex
hello-2.12.1/build-aux/config.rpath
hello-2.12.1/build-aux/useless-if-before-free
hello-2.12.1/build-aux/gnu-web-doc-update

[nix-shell:/tmp/test]$ 

HTH

2 Likes

Thank you so much!

Yeah, that definitely will help me in the future. Currently my process had been a little bit of trial and air.