$out in passthru

I’d like to define a passthru containing the path of some files in the $out derivation. How could I do that? I tried

stdenv.mkDerivation { pname = "aa"; version="1.0"; src = /tmp/test; passthru = { bla = "${out}/some/path";};} 

but it fails saying that out is not defined.

You could never access $out on nix level, just on (mostly bash) code that’s being run during the build. Instead you can do stuff like

let
  self = stdenv.mkDerivation {
    ...
    passthru.bla = "${self.out}/some/path";
  };
in self
1 Like

Though that will not work with overrideAttrs. For that they will need to use finalAttrs.finalPackage.

3 Likes

Great, thanks a lot! I think I prefer the finalAttrs.finalPackage as it is more general and I don’t need to name the derivation but they are great tricks. For reference, here is the final code:

$ nix repl '<nixpkgs>'  
nix-repl> x = stdenv.mkDerivation (finalAttrs: { pname = "aa"; version="1.0"; src = /tmp/test; passthru = { bla = "${finalAttrs.finalPackage.out}/some/path";};} )

nix-repl> x.bla                                                                                                                                                    
"/nix/store/89s51bgks4vrfdsh117kx5sw9wmm17kj-aa-1.0/some/path"

Sadly this idiom isn’t available on all builders yet :frowning:

1 Like

This will probably not do what you expect it to do. It will likely always point towards “/1rz4g4znpzjwh1xymhjpm42vipw92pr73vdgl6xs1hycac8kf2n9/some/path” instead of that actual store path you want it to point to.

1 Like

This will probably not do what you expect it to do. It will likely always point towards “/1rz4g4znpzjwh1xymhjpm42vipw92pr73vdgl6xs1hycac8kf2n9/some/path” instead of that actual store path you want it to point to.

You are right, I stand corrected.