How to create package with multiple sources?

Is there any documentation for creating a package with multiple source-repositories?

I’m trying to create a package from 2 github-repositories.
I’ve already used srcs in the nix-file, but no matter what I define as unpackPhase, I always get the error unpacker produced multiple directories.

2 Likes

You can either look at the options for the unpackPhase (e.g. sourceRoot could be what you’re looking for, see here) or…

You can set src to your “main” source or just set it to one of them and just define additional variables like:
datasrc = fetchurl { ... };
Since you probably have to provide some manual build instructions anyway, you can just refer to the other source through the variable $datasrc in them.
What exactly you call those other sources depends on their purpose.

One example can be found here:

The two sources are at the top (src and assets) and i’m using the assets in the postInstall phase.

Ok, I’ve succeeded now. The important points are:

  • Invoking unpackPhase in a nix-shell does not work as expected; I have to use eval $unpackPhase, see RFC 32
  • Undocumented attribute “name” for fetchFromGitHub (and probably others):
    If srcs is used to use several source-files, the name-attribute for fetchFromGitHub etc. is essential – but unfortunately, this is not documented.
    (I guess I have to create a bugreport to fix this documentation-bug.)
  • Setting sourceRoot

Template for a simple solution with multiple sources (here: test and src2):

stdenv.mkDerivation rec {
  pname = "test";
  version = "1.0";

  srcs = [
    (fetchFromGitHub {
      owner = "...";
      repo = "...";
      rev = version;
      name = pname;
      sha256 = "...";
    })
    (fetchFromGitHub {
      owner = "...";
      repo = "...";
      rev = "...";
      name = "src2";
      sha256 = "...";
    })

  ];

  sourceRoot = pname;

  buildInputs = [ ... ];

  preBuild = ''
    chmod -R u+w ../src2
    ln -s ../src2 .
    make ../src2
  '';

  meta = {
    ...
  };
}
6 Likes

Note that sourceRoot = "."; is valid if you want the buildPhase to start at the parent folder of all sources.