Path for src in derivation file is created with captured directory name as suffix

I’ve been working on integrating Nix in a project and so far everything has been running smoothly. Recently though, I added a derivation which includes a source that looks like src = ./. (some filtering logic left out of the example for simplicity). The problem is that in the resulting .drv file, the path to src includes the name of the folder. Since the CI server uses a different checkout folder name (<some-path>/linux), this means that e.g. the nix cache is not usable since the derivation hash will change accordingly.

As an example, this is what I see locally in the .drv:


and this is what I see on the CI server’s .drv:


Is there a way to set the suffix for that directory so that it is reproducible, regardless of where in the user’s machine it ends up getting checked out to?

This is a really good question, and I’m unable to find a solution. Setting src to a symlink just copies the symlink so we can’t do that. I feel like the right solution is to have a builtin that lets you copy a path into the store with a custom suffix, but I don’t see any existing builtin that does this (even without the custom suffix part).

Upstream issue: Basename of current directory goes into derivation for filterSource on ./. · Issue #1305 · NixOS/nix · GitHub

workaround: use builtins.path