From e7f7bea447aece8b945ac40f69ef1481cabccd0f Mon Sep 17 00:00:00 2001 From: Morgan Jones Date: Sat, 11 Jan 2025 20:33:55 -0800 Subject: [PATCH] mattermostLatest: init at 10.3.1 --- pkgs/by-name/ma/mattermost/generic.nix | 169 +++++++++++++++++ pkgs/by-name/ma/mattermost/package.nix | 179 ++----------------- pkgs/by-name/ma/mattermostLatest/package.nix | 20 +++ 3 files changed, 204 insertions(+), 164 deletions(-) create mode 100644 pkgs/by-name/ma/mattermost/generic.nix create mode 100644 pkgs/by-name/ma/mattermostLatest/package.nix diff --git a/pkgs/by-name/ma/mattermost/generic.nix b/pkgs/by-name/ma/mattermost/generic.nix new file mode 100644 index 00000000000000..59553a95bcb4c7 --- /dev/null +++ b/pkgs/by-name/ma/mattermost/generic.nix @@ -0,0 +1,169 @@ +{ + lib, + buildGoModule, + fetchFromGitHub, + buildNpmPackage, + nix-update-script, + npm-lockfile-fix, + fetchNpmDeps, + jq, + nixosTests, + + versionInfo, +}: + +buildGoModule rec { + pname = "mattermost"; + inherit (versionInfo) version; + + src = fetchFromGitHub { + owner = "mattermost"; + repo = "mattermost"; + rev = "v${version}"; + hash = versionInfo.srcHash; + postFetch = '' + cd $out/webapp + + # Remove "+..." suffixes on versions. + ${lib.getExe jq} ' + def desuffix(version): version | gsub("^(?[^\\+]+)\\+.*$"; "\(.prefix)"); + .packages |= map_values(if has("version") then .version = desuffix(.version) else . end) + ' < package-lock.json > package-lock.fixed.json + ${lib.getExe npm-lockfile-fix} package-lock.fixed.json + + rm -f package-lock.json + mv package-lock.fixed.json package-lock.json + ''; + }; + + # 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 + ''; + } + ); + + npmDeps = fetchNpmDeps { + inherit src; + sourceRoot = "${src.name}/webapp"; + hash = versionInfo.npmDepsHash; + makeCacheWritable = true; + forceGitDeps = true; + }; + + webapp = buildNpmPackage rec { + pname = "mattermost-webapp"; + inherit version src; + + sourceRoot = "${src.name}/webapp"; + + # Remove deprecated image-webpack-loader causing build failures + # See: https://github.com/tcoopman/image-webpack-loader#deprecated + postPatch = '' + substituteInPlace channels/webpack.config.js \ + --replace-fail 'options: {}' 'options: { disable: true }' + ''; + + npmDepsHash = npmDeps.hash; + makeCacheWritable = true; + forceGitDeps = true; + + npmRebuildFlags = [ "--ignore-scripts" ]; + + buildPhase = '' + runHook preBuild + + npm run build --workspace=platform/types + npm run build --workspace=platform/client + npm run build --workspace=platform/components + npm run build --workspace=channels + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out + cp -a channels/dist/* $out + + runHook postInstall + ''; + }; + + inherit (versionInfo) vendorHash; + + modRoot = "./server"; + preBuild = '' + make setup-go-work + ''; + + subPackages = [ "cmd/mattermost" ]; + + 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 = '' + shopt -s extglob + mkdir -p $out/{i18n,fonts,templates,config} + + # Link in the client and copy the language packs. + ln -sf $webapp $out/client + cp -a $src/server/i18n/* $out/i18n/ + + # Fonts have the execute bit set, remove it. + cp --no-preserve=mode $src/server/fonts/* $out/fonts/ + + # Don't copy the Makefile. + cp -a $src/server/templates/!(Makefile) $out/templates/ + + # Generate the config. + OUTPUT_CONFIG=$out/config/config.json \ + go run -tags production ./scripts/config_generator + ''; + + passthru = { + updateScript = nix-update-script { + extraArgs = [ + "--version-regex" + versionInfo.regex + "--override-filename" + versionInfo.autoUpdate + ]; + }; + tests.mattermost = nixosTests.mattermost; + }; + + 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; [ + agpl3Only + asl20 + ]; + maintainers = with maintainers; [ + ryantm + numinit + kranzes + mgdelacroix + fsagbuya + ]; + mainProgram = "mattermost"; + }; +} diff --git a/pkgs/by-name/ma/mattermost/package.nix b/pkgs/by-name/ma/mattermost/package.nix index 61036a0fdb9ef9..2aa489aa11e90c 100644 --- a/pkgs/by-name/ma/mattermost/package.nix +++ b/pkgs/by-name/ma/mattermost/package.nix @@ -1,169 +1,20 @@ { - lib, - buildGoModule, - fetchFromGitHub, - buildNpmPackage, - nix-update-script, - npm-lockfile-fix, - fetchNpmDeps, - jq, - nixosTests, + callPackage, }: -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.11.6"; - - src = fetchFromGitHub { - owner = "mattermost"; - repo = "mattermost"; - rev = "v${version}"; - hash = "sha256-G9RYktnnVXdhNWp8q+bNbdlHB9ZOGtnESnZVOA7lDvE="; - postFetch = '' - cd $out/webapp - - # Remove "+..." suffixes on versions. - ${lib.getExe jq} ' - def desuffix(version): version | gsub("^(?[^\\+]+)\\+.*$"; "\(.prefix)"); - .packages |= map_values(if has("version") then .version = desuffix(.version) else . end) - ' < package-lock.json > package-lock.fixed.json - ${lib.getExe npm-lockfile-fix} package-lock.fixed.json - - rm -f package-lock.json - mv package-lock.fixed.json package-lock.json - ''; - }; - - # 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 - ''; - } - ); - - npmDeps = fetchNpmDeps { - inherit src; - sourceRoot = "${src.name}/webapp"; - hash = "sha256-ysz38ywGxJ5DXrrcDmcmezKbc5Y7aug9jOWUzHRAs/0="; - makeCacheWritable = true; - forceGitDeps = true; - }; - - webapp = buildNpmPackage rec { - pname = "mattermost-webapp"; - inherit version src; - - sourceRoot = "${src.name}/webapp"; - - # Remove deprecated image-webpack-loader causing build failures - # See: https://github.com/tcoopman/image-webpack-loader#deprecated - postPatch = '' - substituteInPlace channels/webpack.config.js \ - --replace-fail 'options: {}' 'options: { disable: true }' - ''; - - npmDepsHash = npmDeps.hash; - makeCacheWritable = true; - forceGitDeps = true; - - npmRebuildFlags = [ "--ignore-scripts" ]; - - buildPhase = '' - runHook preBuild - - npm run build --workspace=platform/types - npm run build --workspace=platform/client - npm run build --workspace=platform/components - npm run build --workspace=channels - - runHook postBuild - ''; - - installPhase = '' - runHook preInstall - - mkdir -p $out - cp -a channels/dist/* $out - - runHook postInstall - ''; - }; - - vendorHash = "sha256-Gwv6clnq7ihoFC8ox8iEM5xp/us9jWUrcmqA9/XbxBE="; - - modRoot = "./server"; - preBuild = '' - make setup-go-work - ''; - - subPackages = [ "cmd/mattermost" ]; - - 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 = '' - shopt -s extglob - mkdir -p $out/{i18n,fonts,templates,config} - - # Link in the client and copy the language packs. - ln -sf $webapp $out/client - cp -a $src/server/i18n/* $out/i18n/ - - # Fonts have the execute bit set, remove it. - cp --no-preserve=mode $src/server/fonts/* $out/fonts/ - - # Don't copy the Makefile. - cp -a $src/server/templates/!(Makefile) $out/templates/ - - # Generate the config. - OUTPUT_CONFIG=$out/config/config.json \ - go run -tags production ./scripts/config_generator - ''; - - passthru = { - updateScript = nix-update-script { - extraArgs = [ - "--version-regex" - "^v(9\.11\.[0-9]+)$" - ]; - }; - tests.mattermost = nixosTests.mattermost; - }; - - 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; [ - agpl3Only - asl20 - ]; - maintainers = with maintainers; [ - ryantm - numinit - kranzes - mgdelacroix - fsagbuya - ]; - mainProgram = "mattermost"; +callPackage ./generic.nix { + versionInfo = { + # 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 here as well. + # + # Ensure you also check ../mattermostLatest/package.nix. + regex = "^v(9\.11\.[0-9]+)$"; + version = "9.11.6"; + srcHash = "sha256-G9RYktnnVXdhNWp8q+bNbdlHB9ZOGtnESnZVOA7lDvE="; + vendorHash = "sha256-Gwv6clnq7ihoFC8ox8iEM5xp/us9jWUrcmqA9/XbxBE="; + npmDepsHash = "sha256-ysz38ywGxJ5DXrrcDmcmezKbc5Y7aug9jOWUzHRAs/0="; + autoUpdate = ./package.nix; }; } diff --git a/pkgs/by-name/ma/mattermostLatest/package.nix b/pkgs/by-name/ma/mattermostLatest/package.nix new file mode 100644 index 00000000000000..1d0110f7f7e2ac --- /dev/null +++ b/pkgs/by-name/ma/mattermostLatest/package.nix @@ -0,0 +1,20 @@ +{ + callPackage, +}: + +callPackage ../mattermost/generic.nix { + versionInfo = { + # Latest, non-RC releases only. + # If the latest is an ESR (Extended Support Release), + # duplicate it here to facilitate the update script. + # See https://docs.mattermost.com/about/mattermost-server-releases.html + # and make sure the version regex is up to date here. + # Ensure you also check ../mattermost/package.nix for ESR releases. + regex = "^v(10\.3\.[0-9]+)$"; + version = "10.3.1"; + srcHash = "sha256-nghwf9FgdqEDLkm8dKqhvY1SvALSZ8dasTDwMwbL5AI="; + vendorHash = "sha256-G2IhU8/XSITjJKNu1Iwwoabm+hG9r3kLPtZnlzuKBD8="; + npmDepsHash = "sha256-Dc+ZFQzRQoUnsZDnPs55gr6O82WwyuBEmCZYFAwW50M="; + autoUpdate = ./package.nix; + }; +}