Home Explore Blog CI



nixpkgs

2nd chunk of `nixos/doc/manual/configuration/mattermost.chapter.md`
dd2947645b5449e6807fdd2c6c67e23a330697c1dfe59b730000000100000cfc
## Using the Mattermost derivation {#sec-mattermost-derivation}

The nixpkgs `mattermost` derivation runs the entire test suite during the
`checkPhase`. This test suite is run with a live MySQL and Postgres database
instance in the sandbox. If you are building Mattermost, this can take a while,
especially if it is building on a resource-constrained system.

The following passthrus are designed to assist with enabling or disabling
the `checkPhase`:

- `mattermost.withTests`
- `mattermost.withoutTests`

The default (`mattermost`) is an alias for `mattermost.withTests`.

## Using Mattermost plugins {#sec-mattermost-plugins}

You can configure Mattermost plugins by either using prebuilt binaries or by
building your own. We test building and using plugins in the NixOS test suite.

Mattermost plugins are tarballs containing a system-specific statically linked
Go binary and webapp resources.

Here is an example with a prebuilt plugin tarball:

```nix
{
  services.mattermost = {
    plugins = with pkgs; [
      /*
       * todo
       * 0.7.1
       * https://github.com/mattermost/mattermost-plugin-todo/releases/tag/v0.7.1
       */
      (fetchurl {
        # Note: Don't unpack the tarball; the NixOS module will repack it for you.
        url = "https://github.com/mattermost-community/mattermost-plugin-todo/releases/download/v0.7.1/com.mattermost.plugin-todo-0.7.1.tar.gz";
        hash = "sha256-P+Z66vqE7FRmc2kTZw9FyU5YdLLbVlcJf11QCbfeJ84=";
      })
    ];
  };
}
```

Once the plugin is installed and the config rebuilt, you can enable this plugin
in the System Console.

## Building Mattermost plugins {#sec-mattermost-plugins-build}

The `mattermost` derivation includes the `buildPlugin` passthru for building
plugins that use the "standard" Mattermost plugin build template at
[mattermost-plugin-demo](https://github.com/mattermost/mattermost-plugin-demo).

Since this is a "de facto" standard for building Mattermost plugins that makes
assumptions about the build environment, the `buildPlugin` helper tries to fit
these assumptions the best it can.

Here is how to build the above Todo plugin. Note that we rely on
package-lock.json being assembled correctly, so must use a version where it is!
If there is no lockfile or the lockfile is incorrect, Nix cannot fetch NPM build
and runtime dependencies for a sandbox build.

```nix
{
  services.mattermost = {
    plugins = with pkgs; [
      (mattermost.buildPlugin {
        pname = "mattermost-plugin-todo";
        version = "0.8-pre";
        src = fetchFromGitHub {
          owner = "mattermost-community";
          repo = "mattermost-plugin-todo";
          # 0.7.1 didn't work, seems to use an older set of node dependencies.
          rev = "f25dc91ea401c9f0dcd4abcebaff10eb8b9836e5";
          hash = "sha256-OM+m4rTqVtolvL5tUE8RKfclqzoe0Y38jLU60Pz7+HI=";
        };
        vendorHash = "sha256-5KpechSp3z/Nq713PXYruyNxveo6CwrCSKf2JaErbgg=";
        npmDepsHash = "sha256-o2UOEkwb8Vx2lDWayNYgng0GXvmS6lp/ExfOq3peyMY=";
        extraGoModuleAttrs = {
          npmFlags = [ "--legacy-peer-deps" ];
        };
      })
    ];
  };
}
```

See `pkgs/by-name/ma/mattermost/build-plugin.nix` for all the options.
As in the previous example, once the plugin is installed and the config rebuilt,
you can enable this plugin in the System Console.

Title: Using and Building Mattermost Plugins in NixOS
Summary
This section details how to use Mattermost plugins with NixOS, covering both prebuilt binaries and custom builds. It provides an example of using a prebuilt plugin tarball and explains how to enable the plugin via the System Console. Furthermore, it elaborates on using the `buildPlugin` passthru for building plugins, emphasizing the importance of a correct package-lock.json file for fetching NPM dependencies. A practical example of building the Todo plugin is included, along with a reference to `build-plugin.nix` for available options.