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:

("src","/nix/store/zn6z7w70bnmqavxgvhxz926i721jh36q-status-react")

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

("src","/nix/store/3kk4h02cm848s77smi5ahh1x9n2fmrai-linux")

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: https://github.com/NixOS/nix/issues/1305

workaround: use builtins.path

4 Likes