anchor.diff:      }) cfg.plugins;
   
     mattermostPlugins = with pkgs;
  -    if cfg.plugins == null then null
  +    if mattermostPluginDerivations == null then null
       else stdenv.mkDerivation {
         name = "${cfg.package.name}-plugins";
         nativeBuildInputs = [
           autoPatchelfHook
  -        postgresPackage
         ] ++ mattermostPluginDerivations;
         buildInputs = [
           cfg.package
         ];
         installPhase = ''
  -        # Create a temporary Mattermost install to unpack plugins
  -        ln -sf ${cfg.package}/{bin,fonts,i18n,templates,client} .
  -        mkdir -p ./{data,logs}
  -
  -        # Create the database
  -        db_dir="$(pwd)/db"
  -        db_socket_dir="$db_dir/run"
  -        initdb --no-locale --encoding=utf8 --pgdata="$db_dir"
  -        mkdir -p "$db_socket_dir"
  -        echo "unix_socket_directories = '$db_socket_dir'" >> db/postgresql.conf
  -        echo "listen_addresses = '''" >> db/postgresql.conf
  -
  -        # Start it
  -        pg_ctl start --pgdata="$db_dir"
  -        cleanup() {
  -          pg_ctl stop --pgdata="$db_dir"
  -        }
  -        trap cleanup EXIT
  -
  -        # Create the Mattermost user
  -        export PGHOST="$db_socket_dir"
  -        ${createDb {
  -          statePath = ".";
  -          localDatabaseUser = "mattermost";
  -          localDatabasePassword = "mattermost";
  -          localDatabaseName = "mattermost";
  -          useSudo = false;
  -        }}
  -
  -        # Create destination paths for client and server plugins
  -        mkdir -p $out/client $out/server
  -
  -        # Create the Mattermost config
  -        ${jq}/bin/jq -s \
  -          --arg serverPlugins $out/server \
  -          --arg clientPlugins $out/client \
  -          --arg socketDir "$db_socket_dir" \ '
  -          .[0] |
  -          .PluginSettings.Directory = $serverPlugins |
  -          .PluginSettings.ClientDirectory = $clientPlugins |
  -          .SqlSettings.DriverName = "postgres" |
  -          .SqlSettings.DataSource = "postgres://mattermost:mattermost@/mattermost?host=" + $socketDir
  -        ' ${cfg.package}/config/config.json > $out/config.json
  -
  -        # Add the plugins
  +        mkdir -p $out/data/plugins
           plugins=(${escapeShellArgs (map (plugin: "${plugin}/share/plugin.tar.gz") mattermostPluginDerivations)})
  -        if [ ''${#plugins[@]} -gt 0 ]; then
  -          mattermost plugin add "''${plugins[@]}" --config $out/config.json
  -        fi
  +        for plugin in "''${plugins[@]}"; do
  +          hash="$(sha256sum "$plugin" | cut -d' ' -f1)"
  +          mkdir -p "$hash"
  +          tar -C "$hash" -xzf "$plugin"
  +          autoPatchelf "$hash"
  +          GZIP_OPT=-9 tar -C "$hash" -cvzf "$out/data/plugins/$hash.tar.gz" .
  +          rm -rf "$hash"
  +        done
         '';
   
         dontUnpack = true;
  
positive.code:             touch ${cfg.statePath}/config/.initial-created
            fi
          '' + lib.optionalString (cfg.mutableConfig && cfg.preferNixConfig) ''
            newConfig="$(${pkgs.jq}/bin/jq -s '.[0] * .[1]' ${cfg.statePath}/config/config.json ${mattermostConfJSON})"
  
            rm -f ${cfg.statePath}/config/config.json
            echo "$newConfig" > ${cfg.statePath}/config/config.json
          '' + lib.optionalString cfg.localDatabaseCreate (createDb {}) + ''
            chown ${cfg.user}:${cfg.group} -R ${cfg.statePath}
            chmod u+rw,g+r,o-rwx -R ${cfg.statePath}
          '';
  
          serviceConfig = {
  
negative.code:         PluginSettings = {
            Enable = true;
            EnableUploads = false;
            Directory = "${cfg.statePath}/plugins/server";
            ClientDirectory = "${cfg.statePath}/plugins/client";
          };
        }
      );
  