# How to "merge" several derivation outputs for plugin system?

**URL:** https://discourse.nixos.org/t/how-to-merge-several-derivation-outputs-for-plugin-system/537
**Category:** Development
**Created:** [July 18, 2018, 6:03pm UTC](https://discourse.nixos.org/t/how-to-merge-several-derivation-outputs-for-plugin-system/537 "2018-07-18T18:03:53Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![zimbatm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/zimbatm/32/4_2.png) [@zimbatm](https://discourse.nixos.org/u/zimbatm)
#### Post date: [July 19, 2018, 9:29am UTC](https://discourse.nixos.org/t/how-to-merge-several-derivation-outputs-for-plugin-system/537/4 "2018-07-19T09:29:52Z")

</div>

In this scenario there are usually two derivations, the package itself and a wrapper derivation that joins the package with the plugins. The general pattern goes like this:

```nix
{ stdenv, runCommand... }:
let
  # creates a new derivation that wraps the package binary and attaches to the plugins somehow.
  withPlugins = plugins:
    # some time it's possible to reference all the plugins individually
    # if they all need to live in a folder then use symlinkJoin
    let pluginsRef = symlinkJoin { name = "${pkg.name}-plugins"; paths = plugins; }; in
    runCommand "${pkg.name}-with-plugins" {
      buildInputs = [makeWrapper];
      passthru.withPlugins = moarPlugins: withPlugins (moarPlugins ++ plugins);
    } ''
      makeWrapper ${package}/bin/whatever $out/bin/whatever \
        --set PLUGIN_PATH ${pluginsRef}
    '';

  pkg = stdenv.mkDerivation {
    # ...
    passthru = inherit withPlugins;
  };
in
  pkg

```

Like this it’s then possible to invoke `thepackage.withPlugins` with a list of plugins and get a new version of the package bound to those plugins.

---

_[View the full topic](https://discourse.nixos.org/t/how-to-merge-several-derivation-outputs-for-plugin-system/537)._
