bitwarden: simplify expression

We now use hooks to setup Rust dependencies, rely on upstream's
package.json to compile the Rust code, and support nix-update.
This commit is contained in:
Robert Schütz 2023-09-20 16:30:11 -07:00
parent 572fc1a5f6
commit 8aba8953dc

View file

@ -1,6 +1,7 @@
{ lib
, applyPatches
, buildNpmPackage
, cargo
, dbus
, electron_24
, fetchFromGitHub
@ -15,8 +16,8 @@
, nodejs_18
, pkg-config
, python3
, rustc
, rustPlatform
, wrapGAppsHook
}:
let
@ -26,56 +27,6 @@ let
buildNpmPackage' = buildNpmPackage.override { nodejs = nodejs_18; };
electron = electron_24;
version = "2023.8.3";
src = applyPatches {
src = fetchFromGitHub {
owner = "bitwarden";
repo = "clients";
rev = "desktop-v${version}";
hash = "sha256-ZsAc9tC087Em/VzgaVm5fU+JnI4gIsSAphxicdJWztU=";
};
patches = [ ];
};
desktop-native = rustPlatform.buildRustPackage {
pname = "bitwarden-desktop-native";
inherit src version;
sourceRoot = "${src.name}/apps/desktop/desktop_native";
cargoHash = "sha256-iBZvdBfuZtcoSgyU4B58ARIBplqUuT5bRev9qnk9LpE=";
nativeBuildInputs = [
pkg-config
wrapGAppsHook
];
buildInputs = [
glib
gtk3
libsecret
];
nativeCheckInputs = [
dbus
(gnome.gnome-keyring.override { useWrappedDaemon = false; })
];
checkFlags = [
"--skip=password::password::tests::test"
];
checkPhase = ''
runHook preCheck
export HOME=$(mktemp -d)
export -f cargoCheckHook runHook _eval _callImplicitHook
dbus-run-session \
--config-file=${dbus}/share/dbus-1/session.conf \
-- bash -e -c cargoCheckHook
runHook postCheck
'';
};
desktopItem = makeDesktopItem {
name = "bitwarden";
exec = "bitwarden %U";
@ -84,26 +35,47 @@ let
desktopName = "Bitwarden";
categories = [ "Utility" ];
};
in
buildNpmPackage' {
in buildNpmPackage' rec {
pname = "bitwarden";
inherit src version;
version = "2023.8.3";
src = fetchFromGitHub {
owner = "bitwarden";
repo = "clients";
rev = "desktop-v${version}";
hash = "sha256-ZsAc9tC087Em/VzgaVm5fU+JnI4gIsSAphxicdJWztU=";
};
makeCacheWritable = true;
npmBuildFlags = [
"--workspace apps/desktop"
];
npmWorkspace = "apps/desktop";
npmDepsHash = "sha256-ARq6iYOkL9CMyAX37g8+Wf+UQsH7hU1jCq/52I1qS9A=";
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
cargoDeps = rustPlatform.fetchCargoTarball {
name = "${pname}-${version}";
inherit src;
sourceRoot = "${src.name}/${cargoRoot}";
hash = "sha256-ABMrFXOR0IwsMv0pxvkebzCUbs18BOGwiuGcEZFntd0=";
};
cargoRoot = "apps/desktop/desktop_native";
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
nativeBuildInputs = [
cargo
jq
makeWrapper
moreutils
pkg-config
python3
rustc
rustPlatform.cargoCheckHook
rustPlatform.cargoSetupHook
];
buildInputs = [
glib
gtk3
libsecret
];
preBuild = ''
@ -111,15 +83,14 @@ buildNpmPackage' {
echo 'ERROR: electron version mismatch'
exit 1
fi
jq 'del(.scripts.postinstall)' apps/desktop/package.json | sponge apps/desktop/package.json
jq '.scripts.build = ""' apps/desktop/desktop_native/package.json | sponge apps/desktop/desktop_native/package.json
cp ${desktop-native}/lib/libdesktop_native.so apps/desktop/desktop_native/desktop_native.linux-x64-musl.node
'';
postBuild = ''
pushd apps/desktop
# desktop_native/index.js loads a file of that name regarldess of the libc being used
mv desktop_native/desktop_native.* desktop_native/desktop_native.linux-x64-musl.node
npm exec electron-builder -- \
--dir \
-c.electronDist=${electron}/libexec/electron \
@ -128,6 +99,32 @@ buildNpmPackage' {
popd
'';
doCheck = true;
nativeCheckInputs = [
dbus
(gnome.gnome-keyring.override { useWrappedDaemon = false; })
];
checkFlags = [
"--skip=password::password::tests::test"
];
checkPhase = ''
runHook preCheck
pushd ${cargoRoot}
export HOME=$(mktemp -d)
export -f cargoCheckHook runHook _eval _callImplicitHook
export cargoCheckType=release
dbus-run-session \
--config-file=${dbus}/share/dbus-1/session.conf \
-- bash -e -c cargoCheckHook
popd
runHook postCheck
'';
installPhase = ''
mkdir $out
@ -154,11 +151,12 @@ buildNpmPackage' {
popd
'';
meta = with lib; {
meta = {
changelog = "https://github.com/bitwarden/clients/releases/tag/${src.rev}";
inherit description;
homepage = "https://bitwarden.com";
license = lib.licenses.gpl3;
maintainers = with maintainers; [ amarshall kiwi ];
maintainers = with lib.maintainers; [ amarshall kiwi ];
platforms = [ "x86_64-linux" ];
};
}