2022-02-10 20:34:41 +00:00
|
|
|
{ lib, stdenv, fetchurl, fetchFromGitHub, buildGoPackage, buildEnv
|
2022-01-03 16:56:52 +00:00
|
|
|
|
|
|
|
# The suffix for the Mattermost version.
|
|
|
|
, versionSuffix ? "nixpkgs"
|
|
|
|
|
|
|
|
# The constant build date.
|
|
|
|
, buildDate ? "1970-01-01"
|
|
|
|
|
|
|
|
# Set to true to set the build hash to the Nix store path.
|
|
|
|
, storePathAsBuildHash ? false }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
2022-02-10 20:34:41 +00:00
|
|
|
version = "6.3.2";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-01-03 16:56:52 +00:00
|
|
|
goPackagePath = "github.com/mattermost/mattermost-server";
|
|
|
|
|
2022-02-10 20:34:41 +00:00
|
|
|
mattermost-server-build = buildGoPackage rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "mattermost-server";
|
2022-01-03 16:56:52 +00:00
|
|
|
inherit version goPackagePath;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "mattermost";
|
2022-01-03 16:56:52 +00:00
|
|
|
repo = "mattermost-server";
|
2020-04-24 23:36:52 +00:00
|
|
|
rev = "v${version}";
|
2022-02-10 20:34:41 +00:00
|
|
|
sha256 = "+6bLkzqlcty8X+mbNkZnHzC8tK8EJwmWAYz3jZ/6q2w=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-08-27 14:25:00 +00:00
|
|
|
ldflags = [
|
2022-01-03 16:56:52 +00:00
|
|
|
"-s" "-w"
|
|
|
|
"-X ${goPackagePath}/model.BuildNumber=${version}${lib.optionalString (versionSuffix != null) "-${versionSuffix}"}"
|
|
|
|
"-X ${goPackagePath}/model.BuildDate=${buildDate}"
|
|
|
|
"-X ${goPackagePath}/model.BuildEnterpriseReady=false"
|
2021-08-27 14:25:00 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2022-01-03 16:56:52 +00:00
|
|
|
mattermost-server = if storePathAsBuildHash then mattermost-server-build.overrideAttrs (orig: {
|
|
|
|
buildPhase = ''
|
|
|
|
origGo="$(type -p go)"
|
|
|
|
|
|
|
|
# Override the Go binary to set the build hash in -ldflags to $out.
|
|
|
|
# Technically this is more accurate than a Git hash!
|
|
|
|
# nixpkgs does not appear to support environment variables in ldflags
|
|
|
|
# for go packages, so we have to rewrite -ldflags before calling go.
|
|
|
|
go() {
|
|
|
|
local args=()
|
|
|
|
local ldflags="-X ${goPackagePath}/model.BuildHash=$out"
|
|
|
|
local found=0
|
|
|
|
for arg in "$@"; do
|
|
|
|
if [[ "$arg" == -ldflags=* ]] && [ $found -eq 0 ]; then
|
|
|
|
arg="-ldflags=''${ldflags} ''${arg#-ldflags=}"
|
|
|
|
found=1
|
|
|
|
fi
|
|
|
|
args+=("$arg")
|
|
|
|
done
|
|
|
|
"$origGo" "''${args[@]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
${orig.buildPhase}
|
|
|
|
'';
|
|
|
|
}) else mattermost-server-build;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
mattermost-webapp = stdenv.mkDerivation {
|
|
|
|
pname = "mattermost-webapp";
|
|
|
|
inherit version;
|
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "https://releases.mattermost.com/${version}/mattermost-${version}-linux-amd64.tar.gz";
|
2022-02-10 20:34:41 +00:00
|
|
|
sha256 = "dxgoYFgW+KKtfNr+1pr7bA9K79gCXpKebTIWDhneuv0=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
|
|
|
tar --strip 1 --directory $out -xf $src \
|
|
|
|
mattermost/client \
|
|
|
|
mattermost/i18n \
|
|
|
|
mattermost/fonts \
|
|
|
|
mattermost/templates \
|
|
|
|
mattermost/config
|
2022-01-25 03:21:06 +00:00
|
|
|
|
|
|
|
# For some reason a bunch of these files are +x...
|
|
|
|
find $out -type f -exec chmod -x {} \;
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
buildEnv {
|
|
|
|
name = "mattermost-${version}";
|
|
|
|
paths = [ mattermost-server mattermost-webapp ];
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Open-source, self-hosted Slack-alternative";
|
|
|
|
homepage = "https://www.mattermost.org";
|
|
|
|
license = with licenses; [ agpl3 asl20 ];
|
2022-01-03 16:56:52 +00:00
|
|
|
maintainers = with maintainers; [ fpletz ryantm numinit ];
|
2020-04-24 23:36:52 +00:00
|
|
|
platforms = platforms.unix;
|
|
|
|
};
|
|
|
|
}
|