element-desktop: use fetchYarnDeps, add update script

This commit is contained in:
Yureka 2021-10-12 23:58:14 +02:00 committed by Yuka
parent 84e02be598
commit 0f59dba39f
6 changed files with 67 additions and 5566 deletions

View file

@ -4,6 +4,7 @@
, makeWrapper
, makeDesktopItem
, mkYarnPackage
, fetchYarnDeps
, electron
, element-web
, callPackage
@ -13,27 +14,28 @@
, useWayland ? false
}:
# Notes for maintainers:
# * versions of `element-web` and `element-desktop` should be kept in sync.
# * the Yarn dependency expression must be updated with `./update-element-desktop.sh <git release tag>`
let
pinData = (builtins.fromJSON (builtins.readFile ./pin.json));
executableName = "element-desktop";
version = "1.9.2";
electron_exec = if stdenv.isDarwin then "${electron}/Applications/Electron.app/Contents/MacOS/Electron" else "${electron}/bin/electron";
in
mkYarnPackage rec {
pname = "element-desktop";
inherit (pinData) version;
name = "${pname}-${version}";
src = fetchFromGitHub {
owner = "vector-im";
repo = "element-desktop";
rev = "v${version}";
sha256 = "sha256-F1uyyBbs+U7tQzRtn+p923Z/BY8Nwxr/JTMYwsak8W8=";
sha256 = pinData.desktopSrcHash;
};
electron_exec = if stdenv.isDarwin then "${electron}/Applications/Electron.app/Contents/MacOS/Electron" else "${electron}/bin/electron";
in
mkYarnPackage rec {
name = "element-desktop-${version}";
inherit version src;
packageJSON = ./element-desktop-package.json;
yarnNix = ./element-desktop-yarndeps.nix;
offlineCache = fetchYarnDeps {
yarnLock = src + "/yarn.lock";
sha256 = pinData.desktopYarnHash;
};
nativeBuildInputs = [ makeWrapper ];
@ -102,6 +104,8 @@ mkYarnPackage rec {
'';
};
passthru.updateScript = ./update.sh;
meta = with lib; {
description = "A feature-rich client for Matrix.org";
homepage = "https://element.io/";

View file

@ -1,9 +1,7 @@
{ lib, stdenv, fetchurl, writeText, jq, conf ? {} }:
# Note for maintainers:
# Versions of `element-web` and `element-desktop` should be kept in sync.
let
pinData = (builtins.fromJSON (builtins.readFile ./pin.json));
noPhoningHome = {
disable_guests = true; # disable automatic guest account registration at matrix.org
piwik = false; # disable analytics
@ -12,11 +10,11 @@ let
in stdenv.mkDerivation rec {
pname = "element-web";
version = "1.9.2";
inherit (pinData) version;
src = fetchurl {
url = "https://github.com/vector-im/element-web/releases/download/v${version}/element-v${version}.tar.gz";
sha256 = "sha256-Qkn0vyZGvBAeOfTzxydWzjFQJwY39INAhwZNX4xsM7U=";
sha256 = pinData.webHash;
};
installPhase = ''

View file

@ -0,0 +1,6 @@
{
"version": "1.9.2",
"desktopSrcHash": "F1uyyBbs+U7tQzRtn+p923Z/BY8Nwxr/JTMYwsak8W8=",
"desktopYarnHash": "0iwbszhaxaxggymixljzjb2gqrsij67fwakxhd3yj9g1zds49ghh",
"webHash": "1d9kdj65yk86hx087x1p0qkm0cffaqkwgwzl74g11g264szz8ja2"
}

View file

@ -1,17 +0,0 @@
#!/usr/bin/env nix-shell
#!nix-shell -I nixpkgs=../../../../../ -i bash -p wget yarn2nix nix-prefetch-git
set -euo pipefail
if [ "$#" -ne 1 ] || [[ "$1" == -* ]]; then
echo "Regenerates the Yarn dependency lock files for the element-desktop package."
echo "Usage: $0 <git release tag>"
exit 1
fi
RIOT_WEB_SRC="https://raw.githubusercontent.com/vector-im/element-desktop/$1"
wget "$RIOT_WEB_SRC/package.json" -O element-desktop-package.json
wget "$RIOT_WEB_SRC/yarn.lock" -O element-desktop-yarndeps.lock
yarn2nix --no-patch --lockfile=element-desktop-yarndeps.lock > element-desktop-yarndeps.nix
rm element-desktop-yarndeps.lock

View file

@ -0,0 +1,43 @@
#!/usr/bin/env nix-shell
#!nix-shell -I nixpkgs=../../../../../ -i bash -p nix wget prefetch-yarn-deps nix-prefetch-github
if [ "$#" -gt 1 ] || [[ "$1" == -* ]]; then
echo "Regenerates packaging data for the element packages."
echo "Usage: $0 [git release tag]"
exit 1
fi
version="$1"
set -euo pipefail
if [ -z "$version" ]; then
version="$(wget -O- "https://api.github.com/repos/vector-im/element-desktop/releases?per_page=1" | jq -r '.[0].tag_name')"
fi
# strip leading "v"
version="${version#v}"
desktop_src="https://raw.githubusercontent.com/vector-im/element-desktop/v$version"
desktop_src_hash=$(nix-prefetch-github vector-im element-desktop --rev v${version} | jq -r .sha256)
web_hash=$(nix-prefetch-url "https://github.com/vector-im/element-web/releases/download/v$version/element-v$version.tar.gz")
wget "$desktop_src/package.json" -O element-desktop-package.json
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
pushd $tmpdir
wget "$desktop_src/yarn.lock"
desktop_yarn_hash=$(prefetch-yarn-deps yarn.lock)
popd
cat > pin.json << EOF
{
"version": "$version",
"desktopSrcHash": "$desktop_src_hash",
"desktopYarnHash": "$desktop_yarn_hash",
"webHash": "$web_hash"
}
EOF