signal-destop-from-src: 7.14.0 -> 7.16.0

upstream switched from yarn to npm, and for this kind of a package i'll seize the opportunity to use builNpmPackage instead of doing so much manually :-)
This commit is contained in:
2024-07-21 10:16:09 +00:00
parent d324a57f06
commit 88df6b30ce

View File

@@ -74,7 +74,6 @@
#
# HOW TO UPDATE
# - `nix run '.#update.pkgs.signal-desktop-from-src'`
# - delete `env.yarnOfflineCache.hash` and rebuild it
# - check signal-desktop's package.json for new ringrtc/nodejs
# - if sqlcipher fails then update sqlcipherTarball url/hash (rare)
# errors which can be safely ignored:
@@ -89,14 +88,13 @@
, atk
, autoPatchelfHook
, bash
, buildNpmPackage
, buildPackages
, cups
, electron-bin
, fetchurl
, fetchFromGitHub
, fetchYarnDeps
, flac
, fixup_yarn_lock
, gdk-pixbuf
, git
, gitUpdater
@@ -118,10 +116,9 @@
, stdenv
, wrapGAppsHook
, xdg-utils
, yarn
}:
let
version = "7.14.0";
version = "7.16.0";
ringrtcPrebuild = fetchurl {
# version is found in signal-desktop's package.json as "@signalapp/ringrtc"
@@ -168,18 +165,12 @@ let
repo = "Signal-Desktop";
leaveDotGit = true; # signal calculates the release date via `git`
rev = "v${version}";
hash = "sha256-lsINz704lEU4W17ZPC0sR40FveUzn19/6B7K7f9B7do=";
};
yarnOfflineCache = fetchYarnDeps {
yarnLock = "${src}/yarn.lock";
hash = "sha256-fAnAnpY+23T+u+HAK230/ebUhJQ+KYHK328HLL49qZA=";
hash = "sha256-HHpv+Kv7Y+653CBSpRePfWQmeRzznmdmUaU5AIxLQUw=";
};
nodejs' = mkNodeJs pkgs;
buildNodejs = mkNodeJs buildPackages;
buildYarn = buildPackages.yarn.override { nodejs = buildNodejs; };
# note that `package.json` locks the electron version, but we seem to not be strictly beholden to that.
# prefer to use the same electron version as everywhere else, and a `-bin` version to avoid 4hr rebuilds.
# the non-bin varieties *seem* to ship the wrong `electron.headers` property.
@@ -190,10 +181,12 @@ let
hostNpmArch = if stdenv.hostPlatform.isAarch64 then "arm64" else "x64";
crossNpmArchExt = if buildNpmArch == hostNpmArch then "" else "-${hostNpmArch}";
in
stdenv.mkDerivation rec {
buildNpmPackage rec {
pname = "signal-desktop-from-src";
inherit src version;
npmDepsHash = "sha256-CJTTLjP3eiJSa/ZWoeBP/9S1Krtb7ozsutRdH2HGfe8=";
patches = [
# ./debug.patch
# fix bug that signal launches in the background on wayland
@@ -220,14 +213,12 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [
autoPatchelfHook
fixup_yarn_lock
git # to calculate build date
gnused
makeShellWrapper
buildNodejs
python3
wrapGAppsHook
buildYarn
];
buildInputs = [
@@ -253,28 +244,24 @@ stdenv.mkDerivation rec {
# sqlcipher
];
env.yarnOfflineCache = yarnOfflineCache;
# env.SIGNAL_ENV = "production";
# env.NODE_ENV = "production";
# env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
env.SIGNAL_ENV = "production";
# env.NODE_ENV = "production"; #< XXX setting this causes `node_modules/protobufjs-cli/bin/pbjs` to not be fetched...
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
dontWrapGApps = true;
npmRebuildFlags = [ "--offline" "--ignore-scripts" ];
makeCacheWritable = true;
# NIX_DEBUG = 6;
configurePhase = ''
runHook preConfigure
postConfigure = ''
# XXX: Signal does not let clients connect if they're running a version that's > 90d old.
# to calculate the build date, it uses SOURCE_DATE_EPOCH (if set), else `git log`.
# nixpkgs sets SOURCE_DATE_EPOCH to 1980/01/01 by default, so unset it so Signal falls back to git date.
# see: Signal-Desktop/ts/scripts/get-expire-time.ts
export SOURCE_DATE_EPOCH=
export HOME=$NIX_BUILD_TOP
yarn config --offline set yarn-offline-mirror $yarnOfflineCache
fixup_yarn_lock yarn.lock
# prevent any attempt at downloading nodejs C headers
# see: <https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules>
tar xzf ${electron'.headers}
@@ -283,12 +270,18 @@ stdenv.mkDerivation rec {
export npm_config_arch=${buildNpmArch}
export npm_config_target_arch=${hostNpmArch}
# optional flags: --no-progress --non-interactive
# yarn install creates the node_modules/ directory
# --ignore-scripts tells yarn to not run the "install" or "postinstall" commands mentioned in dependencies' package.json
# since many of those require network access
yarn install --offline --frozen-lockfile --ignore-scripts
patchShebangs node_modules/
# npm config set electronDist ${electron'}/libexec/electron
# npm config set electronVersion ${electron'.version}
# redo parts of npmConfigHook, but with `npm_config_nodedir` properly set:
# prefetchNpmDeps --map-cache
# prefetchNpmDeps --fixup-lockfile "$PWD/package-lock.json"
npm ci --ignore-scripts $npmInstallFlags "''${npmInstallFlagsArray[@]}" $npmFlags "''${npmFlagsArray[@]}"
patchShebangs node_modules
npm rebuild $npmRebuildFlags "''${npmRebuildFlagsArray[@]}" $npmFlags "''${npmFlagsArray[@]}"
patchShebangs node_modules
patchShebangs --build --update node_modules/{bufferutil/node_modules/node-gyp-build/,node-gyp-build,utf-8-validate/node_modules/node-gyp-build}
# patch these out to remove a runtime reference back to the build bash
# (better, perhaps, would be for these build scripts to not be included in the asar...)
@@ -306,21 +299,19 @@ stdenv.mkDerivation rec {
cp ${sqlcipherTarball} node_modules/@signalapp/better-sqlite3/deps/sqlcipher.tar.gz
pushd node_modules/@signalapp/better-sqlite3
# node-gyp isn't consistently linked into better-sqlite's `node_modules` (maybe due to version mismatch with sinal-desktop's node-gyp?)
PATH="$PATH:$(pwd)/../../.bin" yarn --offline build-release
# node-gyp isn't consistently linked into better-sqlite's `node_modules` (maybe due to version mismatch with signal-desktop's node-gyp?)
PATH="$PATH:$(pwd)/../../.bin" npm --offline run build-release
popd
pushd node_modules/@signalapp/libsignal-client
yarn node-gyp-build
popd
# there are more dependencies which had install/postinstall scripts, but it seems we can safely ignore them
# pushd node_modules/@signalapp/libsignal-client
# npx node-gyp rebuild
# popd
# run signal's own `postinstall`:
yarn build:acknowledgments
yarn patch-package
# yarn electron:install-app-deps # not necessary
runHook postConfigure
# npm run build:acknowledgments
# patch-package
# npm run electron:install-app-deps
npm run postinstall || true
'';
# excerpts from package.json:
@@ -349,20 +340,21 @@ stdenv.mkDerivation rec {
# echo 'ignore-engines true' > .yarnrc
# yarn generate:
yarn build-module-protobuf --offline --frozen-lockfile
yarn build:esbuild --offline --frozen-lockfile
# yarn build:dns-fallback --offline --frozen-lockfile # requires network
yarn build:icu-types --offline --frozen-lockfile
yarn build:compact-locales --offline --frozen-lockfile
yarn sass
yarn get-expire-time
yarn copy-components
npm run build-module-protobuf --offline --frozen-lockfile
npm run build:esbuild --offline --frozen-lockfile
# npm run build:dns-fallback --offline --frozen-lockfile # requires network
npm run build:icu-types --offline --frozen-lockfile
npm run build:compact-locales --offline --frozen-lockfile
npm run sass
npm run get-expire-time
npm run copy-components
yarn build:esbuild:prod --offline --frozen-lockfile
npm run build:esbuild:prod --offline --frozen-lockfile
yarn build:release \
cp -r ${electron'}/libexec/electron electron-dist
npm exec electron-builder -- \
--linux --${hostNpmArch} \
-c.electronDist=${electron'}/libexec/electron \
-c.electronDist=electron-dist \
-c.electronVersion=${electron'.version} \
--dir
@@ -374,9 +366,9 @@ stdenv.mkDerivation rec {
# directory structure follows the original `signal-desktop` nix package
mkdir -p $out/lib
cp -R release/linux${crossNpmArchExt}-unpacked $out/lib/Signal
# cp -R release/linux-unpacked/resources $out/lib/Signal/resources
# cp -R release/linux-unpacked/locales $out/lib/Signal/locales
cp -R dist/linux${crossNpmArchExt}-unpacked $out/lib/Signal
# cp -R dist/linux-unpacked/resources $out/lib/Signal/resources
# cp -R dist/linux-unpacked/locales $out/lib/Signal/locales
mkdir $out/bin
@@ -410,7 +402,6 @@ stdenv.mkDerivation rec {
ignoredVersions = "beta";
};
nodejs = nodejs';
buildYarn = buildYarn;
buildNodejs = buildNodejs;
};