How to read a symlink before using it with builtins.path?

I’m passing src to a buildGoPackage derivation from builtins.path because I want to use a local source, but when I do I get back an error:

unpacking sources
unpacking source archive /nix/store/1v1382x47pd8aiky5waxdam6dazrb7w1-status-go-source-unknown
do not know how to unpack source archive /nix/store/1v1382x47pd8aiky5waxdam6dazrb7w1-status-go-source-unknown

But the source isn’t an archive, it’s a symlink to a folder:

 caspair > ls -l /nix/store/1v1382x47pd8aiky5waxdam6dazrb7w1-status-go-source-unknown
lrwxrwxrwx 1 root root 50 Jan  1  1970 /nix/store/1v1382x47pd8aiky5waxdam6dazrb7w1-status-go-source-unknown -> /home/sochan/go/src/

What am I supposed to do? How can I do readlink for the path before I give it to builtins.path?

I’m probably missing something but linking to files outside nix store is problematic, not least because it will cause builds not to work with sandbox enabled. Can’t you use src = /home/sochan/...;? It will copy to nix store every time the directory contents change but it should work.

Also, adding dontUnpack = true; to the derivation should skip the unpacking step but not sure it’s the right thing here. What do you want to achieve?

I’m using builtins.path because I also want to use the filter argument.
The issue is that the directory I’m pointing at is a symlink:
/home/sochan/work/status-go links to /home/sochan/go/src/
Now, if I provide builtins.path with path set to /home/sochan/go/src/ real path) it works just fine, BUT if I use /home/sochan/work/status-go(the symlink) it fails with the do not know how to unpack source archive error because the Nix store entry becomes a symlink to /home/sochan/go/src/

My question is simple:
How can I use the symlink to the real directory and have Nix resolve it as the real path?

Something like:

src = builtins.path {
  path = lib.readlink "/home/sochan/work/status-go";
  filter = someFilter;

Thanks for clarification. I can’t offer any advice except perhaps changing the thread title to include nix store and symlinks?

There are couple related issues but none seems to hint at solution:

Override unpackPhase

You’re right, I updated the title. But I don’t really see a hit at the solution there.

Override unpackPhase

Seems ugly, also, the user is providing the path, so I don’t know when it’s a symlink and when it’s not. Having to add a custom unpackPhase every time a user can provide an src override for a build seems ugly. I guess if that’s the only way I’ll do it that way.

Though I do find it really weird that Nix doesn’t have something like builtins.readlink considering how often they are utilized in build environments.

Thanks for the suggestions.

Would that work if sandboxing is enabled? Can’t access /home in a sandboxed build…

How does that matter if I’m using builtins.path which creates an entry in /nix/store?

I was referring to @domenkozar’s suggestion of overriding unpackPhase. If builtins.path is copying a symlink pointing to /home, then builds won’t be able to read the files the symlink points to.

Ah, yes, you’re right.