Chocobozzz / PeerTube

ActivityPub-federated video streaming platform using P2P directly in your web browser
https://joinpeertube.org/
GNU Affero General Public License v3.0
13k stars 1.49k forks source link

Declarative plugin management #6428

Open OPNA2608 opened 4 months ago

OPNA2608 commented 4 months ago

Describe the problem to be solved

For the NGI-funded Summer of Nix project, we (@infinidoge and I) are looking into how peertube plugins can be managed declaratively within a NixOS module.

From our understanding, plugins can only be installed imperatively: Start the CLI & tell it to install a plugin, and peertube will trigger a state change in the database to register the plugin and look for it in its plugin directory on startup. This extra requirement on a certain database state is a major pain point for our endeavour.

A previous effort around this found a workaround by

  1. Collecting a list of every plugin that we want to have available
  2. Getting a hash of peertube's storage.plugins package.json
  3. Launching peertube
  4. Running the plugin install script for every desired plugin
  5. Comparing the list of previously-desired plugins against now-desired plugins, and running the uninstall script for every plugin that isn't desired anymore
  6. Saving the list from step 1 under storage.plugins
  7. Comparing the hash from step 2 against the current hash of that file, triggering a restart of peertube if they differ

But we think this extra plugin management around your own plugin management is very unsatisfying & hacky solution.

Describe the solution you would like

We would like to find solution that doesn't rely on us doing plugin management around your plugin management.

Maybe there could be a way to tell peertube to read a list of additional plugins from somewhere, or have it automagically find additional plugins if they're in a certain directory.

Ideal for us (I think) would be a way to completely lock down the imperative plugin management and have it be fully managed by the external mechanism, so we can ensure that only the plugins the user desires are available to peertube.

Infinidoge commented 4 months ago

As part of this, I have been working on a prototype implementation of this as a feature, found here: https://github.com/Infinidoge/PeerTube/tree/develop-nginix

How it works currently is you create a json file in the plugins directory, and it runs the internal installation/removal from there, handling the database where needed.

declarative_plugins.json format:

{
  "npm-package-name": {
    "pluginPath": "/path/to/plugin/directory"
  },
  "other-npm-package-name": {
    "version": "version.to.install"
  }
}

I also intend on adding an offlineCache option, to instruct yarn internally to use the given offline cache, allowing for pre-fetching plugins.

Something that would be worth doing is instead moving this into the PeerTube configuration, removing the need for the positional file and letting multiple config files declare plugins.