Home Explore Blog Models CI



nixpkgs

2nd chunk of `nixos/doc/manual/configuration/mattermost.chapter.md`
e33435f0d638d70d290b16b9d97abeed9b656431f838cd330000000100000d40
this will automatically be configured if your `stateVersion` is set to at least
`25.05`.

## 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: Mattermost Derivation and Plugin Management in NixOS
Summary
This document outlines aspects of managing Mattermost within NixOS, starting with the `mattermost` derivation's `checkPhase`, which runs a lengthy test suite with live databases. It introduces `mattermost.withTests` and `mattermost.withoutTests` to control this behavior. The text then delves into configuring Mattermost plugins, showing how to use prebuilt plugin tarballs with `fetchurl`. Finally, it explains how to build plugins from source using the `mattermost.buildPlugin` helper, which supports the standard Mattermost plugin build template. An example is provided for building a Todo plugin, emphasizing the reliance on `package-lock.json` for npm dependencies and the need for specific hashes (`vendorHash`, `npmDepsHash`). In both prebuilt and built plugin scenarios, the plugin must be enabled in the System Console after configuration.