From 41bb263d28f1a3a3c4dbc6ce21d462cebd94ac71 Mon Sep 17 00:00:00 2001 From: Winter Date: Mon, 22 May 2023 18:20:22 -0400 Subject: [PATCH] thelounge: fix build Upstream switched to using TypeScript in v4.4.0, which broke the patch. This fixes that issue by migrating to building The Lounge from source, instead of having to patch the minified JavaScript. --- .../networking/irc/thelounge/default.nix | 71 +++++++++++++++++++ .../irc/thelounge/packages-path.patch | 13 ++++ pkgs/development/node-packages/aliases.nix | 1 + .../node-packages/node-packages.json | 1 - pkgs/development/node-packages/overrides.nix | 10 --- .../thelounge-packages-path.patch | 15 ---- pkgs/top-level/all-packages.nix | 2 +- 7 files changed, 86 insertions(+), 27 deletions(-) create mode 100644 pkgs/applications/networking/irc/thelounge/default.nix create mode 100644 pkgs/applications/networking/irc/thelounge/packages-path.patch delete mode 100644 pkgs/development/node-packages/thelounge-packages-path.patch diff --git a/pkgs/applications/networking/irc/thelounge/default.nix b/pkgs/applications/networking/irc/thelounge/default.nix new file mode 100644 index 00000000000..bee360d55e6 --- /dev/null +++ b/pkgs/applications/networking/irc/thelounge/default.nix @@ -0,0 +1,71 @@ +{ lib, stdenv, fetchFromGitHub, fetchYarnDeps, yarn, fixup_yarn_lock, nodejs, npmHooks, nixosTests }: + +stdenv.mkDerivation (finalAttrs: { + pname = "thelounge"; + version = "4.4.0"; + + src = fetchFromGitHub { + owner = "thelounge"; + repo = "thelounge"; + rev = "v${finalAttrs.version}"; + hash = "sha256-2MHq71lKkFe1uHEENgUiYsO99bPyLmEZZIdcdgsZfSM="; + }; + + # Allow setting package path for the NixOS module. + patches = [ ./packages-path.patch ]; + + # Use the NixOS module's state directory by default. + postPatch = '' + echo /var/lib/thelounge > .thelounge_home + ''; + + offlineCache = fetchYarnDeps { + yarnLock = "${finalAttrs.src}/yarn.lock"; + hash = "sha256-OKLsNGl94EDyLgP2X2tiwihgRQFXGvf5XgXwgX+JEpk="; + }; + + nativeBuildInputs = [ nodejs yarn fixup_yarn_lock npmHooks.npmInstallHook ]; + + configurePhase = '' + runHook preConfigure + + export HOME="$PWD" + + fixup_yarn_lock yarn.lock + yarn config --offline set yarn-offline-mirror ${finalAttrs.offlineCache} + yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive + patchShebangs node_modules + + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + + NODE_ENV=production yarn build + + runHook postBuild + ''; + + # `npm prune` doesn't work and/or hangs for whatever reason. + preInstall = '' + rm -rf node_modules + yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive --production + ''; + + dontNpmPrune = true; + + # Takes way, way, way too long. + dontStrip = true; + + passthru.tests = nixosTests.thelounge; + + meta = with lib; { + description = "Modern, responsive, cross-platform, self-hosted web IRC client"; + homepage = "https://thelounge.chat"; + changelog = "https://github.com/thelounge/thelounge/releases/tag/v${finalAttrs.version}"; + maintainers = with maintainers; [ winter raitobezarius ]; + license = licenses.mit; + inherit (nodejs.meta) platforms; + }; +}) diff --git a/pkgs/applications/networking/irc/thelounge/packages-path.patch b/pkgs/applications/networking/irc/thelounge/packages-path.patch new file mode 100644 index 00000000000..eb1ded07053 --- /dev/null +++ b/pkgs/applications/networking/irc/thelounge/packages-path.patch @@ -0,0 +1,13 @@ +diff --git a/server/config.ts b/server/config.ts +index 543a8135..9744f00d 100644 +--- a/server/config.ts ++++ b/server/config.ts +@@ -145,7 +145,7 @@ class Config { + } + + getPackagesPath() { +- return path.join(this.#homePath, "packages"); ++ return process.env.THELOUNGE_PACKAGES || path.join(this.#homePath, "packages"); + } + + getPackageModulePath(packageName: string) { diff --git a/pkgs/development/node-packages/aliases.nix b/pkgs/development/node-packages/aliases.nix index 04c8da00646..62f0d1aa672 100644 --- a/pkgs/development/node-packages/aliases.nix +++ b/pkgs/development/node-packages/aliases.nix @@ -43,5 +43,6 @@ mapAliases { "@google/clasp" = pkgs.google-clasp; # Added 2023-05-07 "@nestjs/cli" = pkgs.nest-cli; # Added 2023-05-06 manta = pkgs.node-manta; # Added 2023-05-06 + thelounge = pkgs.thelounge; # Added 2023-05-22 triton = pkgs.triton; # Added 2023-05-06 } diff --git a/pkgs/development/node-packages/node-packages.json b/pkgs/development/node-packages/node-packages.json index 75b7e49bcdc..8f0eae5820d 100644 --- a/pkgs/development/node-packages/node-packages.json +++ b/pkgs/development/node-packages/node-packages.json @@ -319,7 +319,6 @@ , "textlint-rule-terminology" , "textlint-rule-unexpanded-acronym" , "textlint-rule-write-good" -, "thelounge" , "thelounge-plugin-closepms" , "thelounge-plugin-giphy" , "thelounge-plugin-shortcuts" diff --git a/pkgs/development/node-packages/overrides.nix b/pkgs/development/node-packages/overrides.nix index 59b0a010c6d..71546bb7aef 100644 --- a/pkgs/development/node-packages/overrides.nix +++ b/pkgs/development/node-packages/overrides.nix @@ -502,16 +502,6 @@ final: prev: { ''; }; - thelounge = prev.thelounge.override (oldAttrs: { - buildInputs = [ final.node-pre-gyp ]; - postInstall = '' - echo /var/lib/thelounge > $out/lib/node_modules/thelounge/.thelounge_home - patch -d $out/lib/node_modules/thelounge -p1 < ${./thelounge-packages-path.patch} - ''; - passthru.tests = { inherit (nixosTests) thelounge; }; - meta = oldAttrs.meta // { maintainers = with lib.maintainers; [ winter ]; }; - }); - thelounge-plugin-closepms = prev.thelounge-plugin-closepms.override { nativeBuildInputs = [ final.node-pre-gyp ]; }; diff --git a/pkgs/development/node-packages/thelounge-packages-path.patch b/pkgs/development/node-packages/thelounge-packages-path.patch deleted file mode 100644 index c0a9ad80be2..00000000000 --- a/pkgs/development/node-packages/thelounge-packages-path.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/src/helper.js b/src/helper.js -index 27352b53..7078e4c5 100644 ---- a/src/helper.js -+++ b/src/helper.js -@@ -110,6 +110,10 @@ function setHome(newPath) { - userLogsPath = path.join(homePath, "logs"); - clientCertificatesPath = path.join(homePath, "certificates"); - -+ if (process.env.THELOUNGE_PACKAGES !== undefined) { -+ packagesPath = process.env.THELOUNGE_PACKAGES; -+ } -+ - // Reload config from new home location - if (fs.existsSync(configPath)) { - const userConfig = require(configPath); diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 09fb4c56823..2b213f19c3c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -12968,7 +12968,7 @@ with pkgs; theharvester = callPackage ../tools/security/theharvester { }; - inherit (nodePackages) thelounge; + thelounge = callPackage ../applications/networking/irc/thelounge { }; theLoungePlugins = with lib; let pkgs = filterAttrs (name: _: hasPrefix "thelounge-" name) nodePackages;