From e12cc7dbf57e66960ae6b6fa1133103ffeeb0731 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Wed, 21 Feb 2024 17:38:40 +0100 Subject: [PATCH] =?UTF-8?q?mattermost:=208.1.10=20=E2=86=92=209.5.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This jumps Mattermost ESR Versions (see [1] for their release cycle). The new version makes use of Go's workspace feature, which unfortunately the buildGoModule function does not (yet?) support [2], and unfortunately this breaks the previous build process for mattermost. Further, the new release also makes use of private modules only included in the (non-free) enterprise version of mattermost which makes it impossible to build in the usual way even outside of nixpkgs's build abstractions [3]. Both issues can be solved by using Go 1.22, which has added support for vendoring when using workspaces, and instructing it to ignore errors with the -e flag. This requires overriding the go-modules derivation's buildPhase. Finally, this now also build the commands/mmctl subpackage, which contains a cli utility to administrate mattermost. This currently has its own nixpkgs package for no reason i can see at all (it also has a version mismatch between nixpkgs's mattermost and nixpkgs's mmctl). [1] https://docs.mattermost.com/upgrade/extended-support-release.html [2] https://github.com/NixOS/nixpkgs/issues/203039 [3] https://github.com/mattermost/mattermost/issues/26221 --- flake.lock | 36 +++++++++---- flake.nix | 5 +- pkgs/default.nix | 6 ++- pkgs/mattermost.nix | 127 ++++++++++++++++++++++++-------------------- 4 files changed, 102 insertions(+), 72 deletions(-) diff --git a/flake.lock b/flake.lock index 11cf819..c272251 100644 --- a/flake.lock +++ b/flake.lock @@ -57,31 +57,31 @@ "mattermost-server": { "flake": false, "locked": { - "lastModified": 1707502341, - "narHash": "sha256-eloO83koCNZOR/NYzUCdKOtVdF7rk+VrZ9U2bKWkxNU=", + "lastModified": 1707498729, + "narHash": "sha256-w+VF8VoS7oIcDlYS5kCFzSX4rgD9l1B99XBHeJDB6JI=", "owner": "mattermost", - "repo": "mattermost-server", - "rev": "674f549daf0e74933845be0ae32827e498137b63", + "repo": "mattermost", + "rev": "e9f10761eef2f9ed83fcf0be8205424bcc8df9f3", "type": "github" }, "original": { "owner": "mattermost", - "ref": "v8.1.10", - "repo": "mattermost-server", + "ref": "v9.5.1", + "repo": "mattermost", "type": "github" } }, "mattermost-webapp": { "flake": false, "locked": { - "lastModified": 1707771700, - "narHash": "sha256-5PYPNcUGcQmn9RgUbtv3U/s+pRB1a2CgZwxDnunuToA=", + "lastModified": 1707772650, + "narHash": "sha256-zOHWY0T1eM0PKBcNhAtMK3sNCYkSnmH7+o4aVu34dKg=", "type": "tarball", - "url": "https://releases.mattermost.com/8.1.10/mattermost-8.1.10-linux-amd64.tar.gz" + "url": "https://releases.mattermost.com/9.5.1/mattermost-9.5.1-linux-amd64.tar.gz" }, "original": { "type": "tarball", - "url": "https://releases.mattermost.com/8.1.10/mattermost-8.1.10-linux-amd64.tar.gz" + "url": "https://releases.mattermost.com/9.5.1/mattermost-9.5.1-linux-amd64.tar.gz" } }, "nixos-mailserver": { @@ -162,6 +162,21 @@ "type": "github" } }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1708475490, + "narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0e74ca98a74bc7270d28838369593635a5db3260", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1708294118, @@ -201,6 +216,7 @@ "nixos-mailserver": "nixos-mailserver", "nixpkgs": "nixpkgs_2", "nixpkgs-oldstable": "nixpkgs-oldstable", + "nixpkgs-unstable": "nixpkgs-unstable", "sops-nix": "sops-nix", "tracktrain": "tracktrain" } diff --git a/flake.nix b/flake.nix index b986d53..8261d6b 100644 --- a/flake.nix +++ b/flake.nix @@ -2,12 +2,13 @@ description = "hacc infra stuff"; inputs = { - mattermost-webapp.url = "https://releases.mattermost.com/8.1.10/mattermost-8.1.10-linux-amd64.tar.gz"; + mattermost-webapp.url = "https://releases.mattermost.com/9.5.1/mattermost-9.5.1-linux-amd64.tar.gz"; mattermost-webapp.flake = false; - mattermost-server.url = "github:mattermost/mattermost-server?ref=v8.1.10"; + mattermost-server.url = "github:mattermost/mattermost?ref=v9.5.1"; mattermost-server.flake = false; nixpkgs.url = "nixpkgs/nixos-23.11"; + nixpkgs-unstable.url = "nixpkgs/nixos-unstable"; nixpkgs-oldstable.url = "github:/NixOS/nixpkgs?rev=c4aec3c021620d98861639946123214207e98344"; nixos-mailserver.url = "gitlab:simple-nixos-mailserver/nixos-mailserver/nixos-23.11"; diff --git a/pkgs/default.nix b/pkgs/default.nix index 3c14078..ea2c71b 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -3,12 +3,16 @@ let pkgs = import sources.nixpkgs args; oldstable = import sources.nixpkgs-oldstable args; + unstable = import sources.nixpkgs-unstable args; callPackage = pkgs.lib.callPackageWith (pkgs // newpkgs); newpkgs = { - mattermost = callPackage ./mattermost.nix {inherit sources;}; + mattermost = callPackage ./mattermost.nix { + inherit sources; + buildGoModule = unstable.buildGo122Module; + }; tracktrain = import sources.tracktrain { nixpkgs = pkgs; diff --git a/pkgs/mattermost.nix b/pkgs/mattermost.nix index 0bea4d8..5fa8508 100644 --- a/pkgs/mattermost.nix +++ b/pkgs/mattermost.nix @@ -1,65 +1,74 @@ -{ stdenv, fetchurl, fetchFromGitHub, buildGoModule, buildEnv, lib, sources }: +{ lib +, sources +, buildGoModule +, fetchFromGitHub +, nix-update-script +, fetchurl +, nixosTests +}: -let - version = "8.1.10"; +buildGoModule rec { + pname = "mattermost"; + # ESR releases only. + # See https://docs.mattermost.com/upgrade/extended-support-release.html + # When a new ESR version is available (e.g. 8.1.x -> 9.5.x), update + # the version regex in passthru.updateScript as well. + version = "9.5.1"; - mattermost-server = buildGoModule rec { - pname = "mattermost-server"; - inherit version; + src = sources.mattermost-server; + webapp = sources.mattermost-webapp; - src = "${sources.mattermost-server}/server"; - - # TODO: this should not be needed after the next update, assuming they don't - # again push a release without running `go mod tidy` - overrideModAttrs = (_: { - preBuild = '' - go mod tidy - ''; - }); - - vendorHash = "sha256-ZbLSxG9Gyhk7PBC2V6sMtrQNXvm+ugMfliFIHWO1VLs="; - - subPackages = [ "cmd/mattermost" ]; - - ldflags = [ - "-s" - "-w" - "-X github.com/mattermost/mattermost/server/public/model.Version=${version}" - "-X github.com/mattermost/mattermost/server/public/model.BuildNumber=${version}-haccfiles" - "-X github.com/mattermost/mattermost/server/public/model.BuildDate=1970-01-01" - "-X github.com/mattermost/mattermost/server/public/model.BuildHash=v${version}" - "-X github.com/mattermost/mattermost/server/public/model.BuildHashEnterprise=none" - "-X github.com/mattermost/mattermost/server/public/model.BuildEnterpriseReady=false" - "-X github.com/mattermost/mattermost/server/public/model.MockCWS=false" - ]; - }; - - mattermost-webapp = stdenv.mkDerivation { - pname = "mattermost-webapp"; - inherit version; - - src = sources.mattermost-webapp; - - installPhase = '' - mkdir -p $out - cp -r client $out - cp -r i18n $out - cp -r fonts $out - cp -r templates $out - cp -r config $out + # Needed because buildGoModule does not support go workspaces yet. + # We use go 1.22's workspace vendor command, which is not yet available + # in the default version of go used in nixpkgs, nor is it used by upstream: + # https://github.com/mattermost/mattermost/issues/26221#issuecomment-1945351597 + overrideModAttrs = (_: { + buildPhase = '' + make setup-go-work + go work vendor -e ''; + }); + + vendorHash = "sha256-TJCtgNf56A1U0EbV5gXjTro+YudVBRWiSZoBC3nJxnE="; + + modRoot = "./server"; + preBuild = '' + make setup-go-work + ''; + + subPackages = [ "cmd/mattermost" "cmd/mmctl" ]; + + tags = [ "production" ]; + + ldflags = [ + "-s" + "-w" + "-X github.com/mattermost/mattermost/server/public/model.Version=${version}" + "-X github.com/mattermost/mattermost/server/public/model.BuildNumber=${version}-nixpkgs" + "-X github.com/mattermost/mattermost/server/public/model.BuildDate=1970-01-01" + "-X github.com/mattermost/mattermost/server/public/model.BuildHash=v${version}" + "-X github.com/mattermost/mattermost/server/public/model.BuildHashEnterprise=none" + "-X github.com/mattermost/mattermost/server/public/model.BuildEnterpriseReady=false" + ]; + + postInstall = '' + cp -r $webapp/{client,i18n,fonts,templates,config} $out + # For some reason a bunch of these files are executable + find $out/{client,i18n,fonts,templates,config} -type f -exec chmod -x {} \; + ''; + + passthru = { + updateScript = nix-update-script { + extraArgs = [ "--version-regex" "^v(9\.5\.([0-9.]+))" ]; + }; + tests.mattermost = nixosTests.mattermost; }; -in - buildEnv { - name = "mattermost-${version}"; - paths = [ mattermost-server mattermost-webapp ]; - - meta = with lib; { - description = "Open-source, self-hosted Slack-alternative"; - homepage = "https://www.mattermost.org"; - license = with licenses; [ agpl3 asl20 ]; - maintainers = with maintainers; [ fpletz ryantm ]; - platforms = platforms.unix; - }; - } + meta = with lib; { + description = "Mattermost is an open source platform for secure collaboration across the entire software development lifecycle"; + homepage = "https://www.mattermost.org"; + license = with licenses; [ agpl3 asl20 ]; + maintainers = with maintainers; [ ryantm numinit kranzes mgdelacroix ]; + mainProgram = "mattermost"; + }; +}