session-desktop: 1.17.5 -> 1.17.12

This commit is contained in:
Ulysses Zhan
2026-03-01 14:02:22 -08:00
parent e23c5076d2
commit 6b2ab686a3
2 changed files with 99 additions and 187 deletions
+94 -163
View File
@@ -8,14 +8,14 @@
makeWrapper,
fetchpatch,
replaceVars,
fetchYarnDeps,
yarnConfigHook,
yarnBuildHook,
yarnInstallHook,
pnpm,
fetchPnpmDeps,
pnpmConfigHook,
rustPlatform,
nodejs,
electron,
jq,
tsx,
python3,
git,
cmake,
@@ -29,93 +29,16 @@
let
fake-git = writeShellScriptBin "git" (lib.readFile ./fake-git.sh);
sqlcipher-src = stdenv.mkDerivation (finalAttrs: {
pname = "sqlcipher-src";
# when updating: look for the version in deps/download.js of @signalapp/better-sqlite3, whose version is in turn found in yarn.lock
version = "4.6.1";
src = fetchFromGitHub {
owner = "signalapp";
repo = "sqlcipher";
tag = "v${finalAttrs.version}-f_barrierfsync";
hash = "sha256-3fGRPZpJmLbY95DLJ34BK53ZTzJ1dWEzislXsOrTc8k=";
};
patches = [
# Needed to reproduce the build artifact from Signal's CI.
# TODO: find the actual CI workflow that produces
# https://build-artifacts.signal.org/desktop/sqlcipher-v2-4.6.1-signal-patch2--0.2.1-asm2-6253f886c40e49bf892d5cdc92b2eb200b12cd8d80c48ce5b05967cfd01ee8c7.tar.gz
# See also: https://github.com/signalapp/better-sqlite3/blob/v9.0.13/deps/defines.gypi#L33
# Building @signalapp/better-sqlite3 will require openssl without this patch.
(fetchpatch {
name = "sqlcipher-crypto-custom.patch";
url = "https://github.com/sqlcipher/sqlcipher/commit/702af1ff87528a78f5a9b2091806d3a5642e1d4a.patch";
hash = "sha256-OKh6qCGHBQWZyzXfyEveAs71wrNwlWLuG9jNqDeKNG4=";
})
];
buildInputs = [
openssl
tcl
];
# see https://github.com/signalapp/node-sqlcipher/blob/v2.4.4/deps/sqlcipher/update.sh
configureFlags = [ "--enable-update-limit" ];
makeFlags = [
"sqlite3.h"
"sqlite3.c"
"sqlite3ext.h"
"shell.c"
];
installPhase = ''
runHook preInstall
mkdir -p $out
cp sqlite3.h sqlite3.c sqlite3ext.h shell.c $out
runHook postInstall
'';
meta = {
homepage = "https://github.com/signalapp/sqlcipher";
license = lib.licenses.bsd3;
};
});
signal-sqlcipher-extension = rustPlatform.buildRustPackage (finalAttrs: {
pname = "signal-sqlcipher-extension";
# when updating: look for the version in deps/download.js of @signalapp/better-sqlite3, whose version is in turn found in yarn.lock
version = "0.2.1";
src = fetchFromGitHub {
owner = "signalapp";
repo = "Signal-Sqlcipher-Extension";
rev = "v${finalAttrs.version}";
hash = "sha256-INSkm7ZuetPASuIqezzzG/bXoEHClUb9XpxWbxLVXRc=";
};
cargoHash = "sha256-qT4HM/FRL8qugKKNlMYM/0zgUsC6cDOa9fgd1d4VIrc=";
postInstall = ''
mkdir -p $out/include
cp target/*.h $out/include
'';
meta = {
homepage = "https://github.com/signalapp/Signal-Sqlcipher-Extension";
license = lib.licenses.agpl3Only;
};
});
libsession-util-nodejs = stdenv.mkDerivation (finalAttrs: {
pname = "libsession-util-nodejs";
version = "0.6.5"; # find version in yarn.lock
version = "0.6.12"; # find version in pnpm-lock.yaml
src = fetchFromGitHub {
owner = "session-foundation";
repo = "libsession-util-nodejs";
tag = "v${finalAttrs.version}";
fetchSubmodules = true;
deepClone = true; # need git rev for all submodules
hash = "sha256-T6qjpXZPGkRfBcJCd/4XGNEBZILEG2Py2zN8W2c1Tlc=";
hash = "sha256-6+eAofi4uapRKqJvCrekP7MWTfdd4VhOnSbc/8rsFic=";
# fetchgit is not reproducible with deepClone + fetchSubmodules:
# https://github.com/NixOS/nixpkgs/issues/100498
postFetch = ''
@@ -133,20 +56,21 @@ let
'';
nativeBuildInputs = [
yarnConfigHook
yarnBuildHook
yarnInstallHook
pnpmConfigHook
pnpm
nodejs
cmake
python3
fake-git # used in update_version.sh, libsession-util/external/oxen-libquic/cmake/check_submodule.cmake, etc.
jq
];
dontUseCmakeConfigure = true;
yarnOfflineCache = fetchYarnDeps {
yarnLock = "${finalAttrs.src}/yarn.lock";
hash = "sha256-0pH88EOqxG/kg7edaWnaLEs3iqhIoRCJxDdBn4JxYeY=";
pnpmDeps = fetchPnpmDeps {
inherit (finalAttrs) pname version src;
inherit pnpm;
fetcherVersion = 3;
hash = "sha256-oadNQJsSmwR/ADWO6Zu+Ji3CwkwupmQFX8OfUgKDtEU=";
};
preBuild = ''
@@ -156,16 +80,22 @@ let
'';
# The install script is the build script.
# `yarn install` may be better than `yarn run install`.
# However, the former seems to use /bin/bash while the latter uses stdenv.shell,
# and the former simply cannot find the cmake-js command, which is pretty weird,
# and using `yarn config set script-shell` does not help.
yarnBuildScript = "run";
yarnBuildFlags = "install";
buildPhase = ''
runHook preBuild
postInstall = ''
# build is not installed by default because it is in .gitignore
cp -r build $out/lib/node_modules/libsession_util_nodejs
pnpm run install
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/lib/node_modules
cp -r . $out/lib/node_modules/libsession_util_nodejs
# TODO: clean up unnecessary files
runHook postInstall
'';
meta = {
@@ -179,36 +109,45 @@ let
in
stdenv.mkDerivation (finalAttrs: {
pname = "session-desktop";
version = "1.17.5";
src = fetchFromGitHub {
owner = "session-foundation";
repo = "session-desktop";
tag = "v${finalAttrs.version}";
leaveDotGit = true;
hash = "sha256-qx5e3HfmhB7Edr+KYK+SJfQhF19ct/40v6eIqExw+iU=";
postFetch = ''
pushd $out
git rev-parse HEAD > .gitrev
rm -rf .git
popd
'';
};
version = "1.17.12";
src =
(fetchFromGitHub {
owner = "session-foundation";
repo = "session-desktop";
tag = "v${finalAttrs.version}";
fetchSubmodules = true;
leaveDotGit = true;
postFetch = ''
pushd $out
git rev-parse HEAD > .gitrev
rm -rf .git
popd
'';
hash = "sha256-+ZLTIBXXjqX1TAGboXU4OYQPBDXMm7epfY3tsi3zOfk=";
}).overrideAttrs
(oldAttrs: {
# https://github.com/NixOS/nixpkgs/issues/195117#issuecomment-1410398050
env = oldAttrs.env or { } // {
GIT_CONFIG_COUNT = 1;
GIT_CONFIG_KEY_0 = "url.https://github.com/.insteadOf";
GIT_CONFIG_VALUE_0 = "git@github.com:";
};
});
postPatch = ''
jq '
del(.engines) # too restrictive Node version requirement
# control what files are packed in the install phase
+ {files: ["**/*.js", "**/*.html", "**/*.node", "_locales", "config", "fonts", "images", "mmdb", "mnemonic_languages", "protos", "sound", "stylesheets"]}
' package.json > package.json.new
# too restrictive Node version requirement
jq 'del(.engines)' package.json > package.json.new
mv package.json.new package.json
# use tsx from nixpkgs instead of using pnpx to download it
substituteInPlace package.json --replace-fail 'pnpx tsx' '${lib.getExe tsx}'
'';
nativeBuildInputs = [
copyDesktopItems
makeWrapper
yarnConfigHook
yarnBuildHook
yarnInstallHook
pnpmConfigHook
pnpm
nodejs
jq
python3
@@ -226,60 +165,49 @@ stdenv.mkDerivation (finalAttrs: {
};
dontUseCmakeConfigure = true;
yarnOfflineCache = fetchYarnDeps {
# Future maintainers: keep in mind that sometimes the upstream deduplicates dependencies
# (see the `dedup` script in package.json) before committing yarn.lock,
# which may unfortunately break the offline cache (and may not).
# If that happens, clone the repo and run `yarn install --ignore-scripts` yourself,
# copy the modified yarn.lock here, and use `./yarn.lock` instead of `"${finalAttrs.src}/yarn.lock"`,
# and also add `cp ${./yarn.lock} yarn.lock` to postPatch.
yarnLock = "${finalAttrs.src}/yarn.lock";
hash = "sha256-5MqCwXe/BflIymZiggtAE6XgBa/S4Qoh7KzWokU+L5c=";
pnpmDeps = fetchPnpmDeps {
inherit (finalAttrs) pname version src;
inherit pnpm;
fetcherVersion = 3;
hash = "sha256-rusUkqokhhmbqTgzIQIbqFCNbI1pmIxO5USy7mmOzxs=";
};
preBuild = ''
# prevent downloading
pushd node_modules/@signalapp/better-sqlite3/deps
tar -czf sqlcipher.tar.gz \
-C ${signal-sqlcipher-extension} lib include \
-C ${sqlcipher-src} . \
--transform="s,^lib,./signal-sqlcipher-extension/${stdenv.targetPlatform.rust.cargoShortTarget}," \
--transform="s,^include,./signal-sqlcipher-extension/include,"
hash=$(sha256sum sqlcipher.tar.gz | cut -d' ' -f1)
sed -i "s/^const HASH = '.*';/const HASH = '$hash';/" download.js
popd
buildPhase = ''
runHook preBuild
export NODE_ENV=production
# rebuild native modules except libsession_util_nodejs
rm -rf node_modules/libsession_util_nodejs
npm rebuild --verbose --offline --no-progress --release # why doesn't yarn have `rebuild`?
cp -r ${libsession-util-nodejs}/lib/node_modules/libsession_util_nodejs node_modules
chmod -R +w node_modules/libsession_util_nodejs
rm -rf node_modules/libsession_util_nodejs/node_modules
libsession_util_nodejs_path=$(readlink -f node_modules/libsession_util_nodejs)
rm -r $libsession_util_nodejs_path
pnpm rebuild --verbose
rm -r $libsession_util_nodejs_path
cp -r "${finalAttrs.passthru.libsession-util-nodejs}/lib/node_modules/libsession_util_nodejs" $libsession_util_nodejs_path
chmod -R +w $libsession_util_nodejs_path
rm -r $libsession_util_nodejs_path/node_modules
# some important things that did not run because of --ignore-scripts
yarn run postinstall
pnpm run postinstall
pnpm run build
runHook postBuild
'';
preInstall = ''
# Do not want yarn prune to remove native modules that we just built.
mv node_modules node_modules.dev
'';
installPhase = ''
runHook preInstall
postInstall = ''
find node_modules.dev -mindepth 2 -maxdepth 3 -type d -name build | while read -r buildDir; do
packageDir=$(dirname ''${buildDir#node_modules.dev/})
installPackageDir="$out/lib/node_modules/session-desktop/node_modules/$packageDir"
if [ -d "$installPackageDir" ]; then
cp -r "$buildDir" "$installPackageDir"
fi
done
phome=$out/lib/node_modules/session-desktop
mkdir -p $(dirname $phome)
cp -r app $phome
cp -r node_modules $phome # TODO: exclude unnecessary files
cp package.json $phome
makeWrapper ${lib.getExe electron} $out/bin/session-desktop \
--add-flags $out/lib/node_modules/session-desktop \
--add-flags $phome \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \
--set NODE_ENV production \
--suffix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ stdenv.cc.cc ]}" \
--inherit-argv0
for f in build/icons/icon_*.png; do
@@ -287,8 +215,11 @@ stdenv.mkDerivation (finalAttrs: {
size=''${base#icon_}
install -Dm644 $f $out/share/icons/hicolor/$size/apps/session-desktop.png
done
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
runHook postInstall
'';
postInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
mkdir -p $out/Applications/Session.app/Contents/{MacOS,Resources}
ln -s $out/bin/session-desktop $out/Applications/Session.app/Contents/MacOS/Session
install -Dm644 build/icon-mac.icns $out/Applications/Session.app/Contents/Resources/icon.icns
@@ -313,7 +244,7 @@ stdenv.mkDerivation (finalAttrs: {
];
passthru = {
inherit sqlcipher-src signal-sqlcipher-extension libsession-util-nodejs;
inherit libsession-util-nodejs;
updateScript = ./update.sh;
};
+5 -24
View File
@@ -1,33 +1,14 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq common-updater-scripts
#!nix-shell -i bash -p nix-update yq
set -euo pipefail
currentVersion="$(nix-instantiate --eval --raw -A session-desktop.version)"
latestVersion="$(
curl -s https://api.github.com/repos/session-foundation/session-desktop/releases/latest \
${GITHUB_TOKEN:+--user ":$GITHUB_TOKEN"} \
| jq -r .tag_name | sed 's/^v//'
)"
if [ "$currentVersion" = "$latestVersion" ]; then
echo "Already up-to-date"
exit 0
fi
nix-update session-desktop
yarnLock="$(curl -s https://raw.githubusercontent.com/session-foundation/session-desktop/v$latestVersion/yarn.lock)"
pnpmLock="$(nix-build -A session-desktop.src --no-out-link)/pnpm-lock.yaml"
depVersion() {
name="$(echo "$1" | sed 's/\//\\&/g')"
echo "$yarnLock" | awk '/^"?'"$name"'@/ {flag=1; next} flag && /^ version "[^"]+"/ {match($0, /^ version "([^"]+)"/, a); print a[1]; exit}' -
yq -r ".packages | with_entries(select(.key | startswith(\"$name@\"))) | .[].version" "$pnpmLock"
}
update-source-version session-desktop.passthru.libsession-util.nodejs "$(depVersion libsession_util_nodejs)"
downloadJs="$(curl -s https://raw.githubusercontent.com/signalapp/better-sqlite3/v$(depVersion @signalapp/better-sqlite3)/deps/download.js)"
sqlDepVersion() {
echo "$downloadJs" | awk "match(\$0, /^const ${1}_VERSION = '([0-9.]+)['-]/, a) {print a[1]}" -
}
update-source-version session-desktop.passthru.sqlcipher-src "$(sqlDepVersion SQLCIPHER)"
update-source-version session-desktop.passthru.signal-sqlcipher-extension "$(sqlDepVersion EXTENSION)"
update-source-version session-desktop "$latestVersion"
nix-update session-desktop.passthru.libsession-util-nodejs --version "$(depVersion libsession_util_nodejs)"