From 8aba8953dc6c4814022748eea02eece4002adcd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Wed, 20 Sep 2023 16:30:11 -0700 Subject: [PATCH] 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. --- pkgs/tools/security/bitwarden/default.nix | 130 +++++++++++----------- 1 file changed, 64 insertions(+), 66 deletions(-) diff --git a/pkgs/tools/security/bitwarden/default.nix b/pkgs/tools/security/bitwarden/default.nix index fae9848f482f..54ded5913b5f 100644 --- a/pkgs/tools/security/bitwarden/default.nix +++ b/pkgs/tools/security/bitwarden/default.nix @@ -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" ]; }; }