How to create package with multiple sources?

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 = {
    ...
  };
}
11 Likes