# How to create package with multiple sources?

**URL:** https://discourse.nixos.org/t/how-to-create-package-with-multiple-sources/9308
**Category:** Help
**Created:** [October 5, 2020, 1:42pm UTC](https://discourse.nixos.org/t/how-to-create-package-with-multiple-sources/9308 "2020-10-05T13:42:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rkoe](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rkoe/32/107_2.png) [@rkoe](https://discourse.nixos.org/u/rkoe)
#### Post date: [October 5, 2020, 1:42pm UTC](https://discourse.nixos.org/t/how-to-create-package-with-multiple-sources/9308/1 "2020-10-05T13:42:32Z")

</div>

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`.

---

<div class="post-metadata">

### Author: ![tokudan](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tokudan](https://discourse.nixos.org/u/tokudan)
#### Post date: [October 5, 2020, 4:07pm UTC](https://discourse.nixos.org/t/how-to-create-package-with-multiple-sources/9308/2 "2020-10-05T16:07:19Z")

</div>

You can either look at the options for the unpackPhase (e.g. sourceRoot could be what you’re looking for, see [here](https://nixos.org/manual/nixpkgs/stable/#ssec-unpack-phase)) 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:

> **[nur/pkgs/writefreely/default.nix at master](https://codeberg.org/tokudan/nur/src/branch/master/pkgs/writefreely/default.nix)**
>
> nur - Package description for the Nix User Repositories (https://github.com/nix-community/NUR/)

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

---

<div class="post-metadata">

### Author: ![rkoe](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rkoe/32/107_2.png) [@rkoe](https://discourse.nixos.org/u/rkoe)
#### Post date: [October 5, 2020, 7:39pm UTC](https://discourse.nixos.org/t/how-to-create-package-with-multiple-sources/9308/3 "2020-10-05T19:39:13Z")

</div>

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](https://github.com/NixOS/rfcs/pull/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`):

```auto
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 = {
    ...
  };
}

```

---

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [February 1, 2024, 11:29pm UTC](https://discourse.nixos.org/t/how-to-create-package-with-multiple-sources/9308/4 "2024-02-01T23:29:23Z")

</div>

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