nixpkgs-suyu/pkgs/servers/mattermost/default.nix

95 lines
2.7 KiB
Nix
Raw Normal View History

{ lib, stdenv, fetchurl, fetchFromGitHub, buildGo117Package, buildEnv
# 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 }:
2016-08-15 03:17:05 +02:00
2018-02-23 18:50:33 +01:00
let
version = "6.3.0";
2018-02-23 18:50:33 +01:00
goPackagePath = "github.com/mattermost/mattermost-server";
mattermost-server-build = buildGo117Package rec {
2019-08-13 23:52:01 +02:00
pname = "mattermost-server";
inherit version goPackagePath;
2016-08-15 03:17:05 +02:00
2018-05-16 19:09:19 +02:00
src = fetchFromGitHub {
owner = "mattermost";
repo = "mattermost-server";
2018-05-16 19:09:19 +02:00
rev = "v${version}";
sha256 = "y3VTDl01UrMpgoN06lf98C+uTu2N9u0EAWYADPpOI3w=";
2018-05-16 19:09:19 +02:00
};
2021-08-26 05:31:57 +02:00
ldflags = [
"-s" "-w"
"-X ${goPackagePath}/model.BuildNumber=${version}${lib.optionalString (versionSuffix != null) "-${versionSuffix}"}"
"-X ${goPackagePath}/model.BuildDate=${buildDate}"
"-X ${goPackagePath}/model.BuildEnterpriseReady=false"
2021-08-26 05:31:57 +02:00
];
2016-08-15 03:17:05 +02: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;
2018-05-16 19:09:19 +02:00
mattermost-webapp = stdenv.mkDerivation {
2019-08-13 23:52:01 +02:00
pname = "mattermost-webapp";
inherit version;
2018-05-16 19:09:19 +02:00
src = fetchurl {
url = "https://releases.mattermost.com/${version}/mattermost-${version}-linux-amd64.tar.gz";
sha256 = "PqinkPC7J6Ng1fjTrcAa6ZqiyB2JKkGRdvJ6h2wNS5w=";
2018-05-16 19:09:19 +02:00
};
installPhase = ''
mkdir -p $out
tar --strip 1 --directory $out -xf $src \
mattermost/client \
mattermost/i18n \
mattermost/fonts \
mattermost/templates \
mattermost/config
'';
2016-08-15 03:17:05 +02:00
};
2018-05-16 19:09:19 +02:00
in
buildEnv {
name = "mattermost-${version}";
paths = [ mattermost-server mattermost-webapp ];
meta = with lib; {
2018-05-16 19:09:19 +02:00
description = "Open-source, self-hosted Slack-alternative";
homepage = "https://www.mattermost.org";
2018-05-16 19:09:19 +02:00
license = with licenses; [ agpl3 asl20 ];
maintainers = with maintainers; [ fpletz ryantm numinit ];
2018-05-16 19:09:19 +02:00
platforms = platforms.unix;
};
}