2023-01-26 06:09:10 +01:00
|
|
|
{ lib
|
|
|
|
, buildNpmPackage
|
2023-09-21 01:30:11 +02:00
|
|
|
, cargo
|
2023-10-22 19:32:25 +02:00
|
|
|
, copyDesktopItems
|
2023-01-26 06:09:10 +01:00
|
|
|
, dbus
|
2024-02-08 00:51:29 +01:00
|
|
|
, electron_28
|
2023-01-26 06:09:10 +01:00
|
|
|
, fetchFromGitHub
|
|
|
|
, glib
|
|
|
|
, gnome
|
|
|
|
, gtk3
|
|
|
|
, jq
|
2019-08-02 06:48:20 +02:00
|
|
|
, libsecret
|
|
|
|
, makeDesktopItem
|
|
|
|
, makeWrapper
|
2023-01-26 06:09:10 +01:00
|
|
|
, moreutils
|
2023-09-21 09:48:09 +02:00
|
|
|
, napi-rs-cli
|
2023-05-10 00:34:50 +02:00
|
|
|
, nodejs_18
|
2023-12-31 19:53:50 +01:00
|
|
|
, patchutils_0_4_2
|
2023-01-26 06:09:10 +01:00
|
|
|
, pkg-config
|
|
|
|
, python3
|
2023-12-31 19:53:50 +01:00
|
|
|
, runCommand
|
2023-09-21 01:30:11 +02:00
|
|
|
, rustc
|
2023-01-26 06:09:10 +01:00
|
|
|
, rustPlatform
|
2019-08-02 06:48:20 +02:00
|
|
|
}:
|
|
|
|
|
2023-01-26 06:09:10 +01:00
|
|
|
let
|
|
|
|
description = "A secure and free password manager for all of your devices";
|
|
|
|
icon = "bitwarden";
|
2024-02-08 00:51:29 +01:00
|
|
|
electron = electron_28;
|
2023-11-09 17:23:45 +01:00
|
|
|
in buildNpmPackage rec {
|
2024-01-19 18:51:09 +01:00
|
|
|
pname = "bitwarden-desktop";
|
2024-04-08 22:26:32 +02:00
|
|
|
version = "2024.4.1";
|
2023-09-21 01:30:11 +02:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "bitwarden";
|
|
|
|
repo = "clients";
|
|
|
|
rev = "desktop-v${version}";
|
2024-04-08 22:26:32 +02:00
|
|
|
hash = "sha256-UzVzo8tq719W2EwUE4NfvUrqhb61fvd60EGkavQmv3Q=";
|
2023-09-21 01:30:11 +02:00
|
|
|
};
|
2019-08-02 06:48:20 +02:00
|
|
|
|
2023-11-14 19:48:35 +01:00
|
|
|
patches = [
|
2024-03-07 16:30:49 +01:00
|
|
|
./electron-builder-package-lock.patch
|
2023-11-14 19:48:35 +01:00
|
|
|
];
|
|
|
|
|
2024-03-07 16:30:49 +01:00
|
|
|
# The nested package-lock.json from upstream is out-of-date, so copy the
|
|
|
|
# lock metadata from the root package-lock.json.
|
|
|
|
postPatch = ''
|
|
|
|
cat {,apps/desktop/src/}package-lock.json \
|
|
|
|
| ${lib.getExe jq} -s '
|
|
|
|
.[1].packages."".dependencies.argon2 = .[0].packages."".dependencies.argon2
|
|
|
|
| .[0].packages."" = .[1].packages.""
|
|
|
|
| .[1].packages = .[0].packages
|
|
|
|
| .[1]
|
|
|
|
' \
|
|
|
|
| ${moreutils}/bin/sponge apps/desktop/src/package-lock.json
|
|
|
|
'';
|
|
|
|
|
2023-11-09 17:23:45 +01:00
|
|
|
nodejs = nodejs_18;
|
|
|
|
|
2023-01-26 06:09:10 +01:00
|
|
|
makeCacheWritable = true;
|
2024-01-10 17:22:59 +01:00
|
|
|
npmFlags = [ "--legacy-peer-deps" ];
|
2023-09-21 01:30:11 +02:00
|
|
|
npmWorkspace = "apps/desktop";
|
2024-04-08 22:26:32 +02:00
|
|
|
npmDepsHash = "sha256-qkg1psct/ekIXB6QmJX1n/UOKUhYSD9Su7t/b4/4miM=";
|
2019-08-02 06:48:20 +02:00
|
|
|
|
2023-09-21 01:30:11 +02:00
|
|
|
cargoDeps = rustPlatform.fetchCargoTarball {
|
|
|
|
name = "${pname}-${version}";
|
2023-12-31 19:53:50 +01:00
|
|
|
inherit src;
|
|
|
|
patches = map
|
|
|
|
(patch: runCommand
|
|
|
|
(builtins.baseNameOf patch)
|
|
|
|
{ nativeBuildInputs = [ patchutils_0_4_2 ]; }
|
|
|
|
''
|
|
|
|
< ${patch} filterdiff -p1 --include=${lib.escapeShellArg cargoRoot}'/*' > $out
|
|
|
|
''
|
|
|
|
)
|
|
|
|
patches;
|
2023-11-14 19:48:35 +01:00
|
|
|
patchFlags = [ "-p4" ];
|
2023-09-21 01:30:11 +02:00
|
|
|
sourceRoot = "${src.name}/${cargoRoot}";
|
2024-04-08 22:26:32 +02:00
|
|
|
hash = "sha256-lvEJmjzhpMhm+9INYHWpdltinUOI3DMtFN/ddDQrUvo=";
|
2023-09-21 01:30:11 +02:00
|
|
|
};
|
|
|
|
cargoRoot = "apps/desktop/desktop_native";
|
|
|
|
|
|
|
|
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
|
2019-08-02 06:48:20 +02:00
|
|
|
|
2023-01-26 06:09:10 +01:00
|
|
|
nativeBuildInputs = [
|
2023-09-21 01:30:11 +02:00
|
|
|
cargo
|
2023-10-22 19:32:25 +02:00
|
|
|
copyDesktopItems
|
2023-01-26 06:09:10 +01:00
|
|
|
jq
|
|
|
|
makeWrapper
|
|
|
|
moreutils
|
2023-09-21 09:48:09 +02:00
|
|
|
napi-rs-cli
|
2023-09-21 01:30:11 +02:00
|
|
|
pkg-config
|
2023-02-16 18:45:31 +01:00
|
|
|
python3
|
2023-09-21 01:30:11 +02:00
|
|
|
rustc
|
|
|
|
rustPlatform.cargoCheckHook
|
|
|
|
rustPlatform.cargoSetupHook
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
glib
|
|
|
|
gtk3
|
|
|
|
libsecret
|
2023-01-26 06:09:10 +01:00
|
|
|
];
|
|
|
|
|
2023-12-13 01:22:42 +01:00
|
|
|
preBuild = ''
|
2023-05-10 00:34:51 +02:00
|
|
|
if [[ $(jq --raw-output '.devDependencies.electron' < package.json | grep -E --only-matching '^[0-9]+') != ${lib.escapeShellArg (lib.versions.major electron.version)} ]]; then
|
|
|
|
echo 'ERROR: electron version mismatch'
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-12-13 01:22:42 +01:00
|
|
|
'';
|
2019-08-02 06:48:20 +02:00
|
|
|
|
2023-01-26 06:09:10 +01:00
|
|
|
postBuild = ''
|
|
|
|
pushd apps/desktop
|
|
|
|
|
2023-09-21 01:30:11 +02:00
|
|
|
# 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
|
|
|
|
|
2023-05-10 00:34:50 +02:00
|
|
|
npm exec electron-builder -- \
|
2023-01-26 06:09:10 +01:00
|
|
|
--dir \
|
2023-07-30 21:42:50 +02:00
|
|
|
-c.electronDist=${electron}/libexec/electron \
|
2023-01-26 06:09:10 +01:00
|
|
|
-c.electronVersion=${electron.version}
|
|
|
|
|
|
|
|
popd
|
|
|
|
'';
|
|
|
|
|
2023-09-21 01:30:11 +02:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
2023-01-26 06:09:10 +01:00
|
|
|
installPhase = ''
|
2023-10-22 19:32:25 +02:00
|
|
|
runHook preInstall
|
|
|
|
|
2023-01-26 06:09:10 +01:00
|
|
|
mkdir $out
|
|
|
|
|
|
|
|
pushd apps/desktop/dist/linux-unpacked
|
|
|
|
mkdir -p $out/opt/Bitwarden
|
|
|
|
cp -r locales resources{,.pak} $out/opt/Bitwarden
|
|
|
|
popd
|
|
|
|
|
|
|
|
makeWrapper '${electron}/bin/electron' "$out/bin/bitwarden" \
|
|
|
|
--add-flags $out/opt/Bitwarden/resources/app.asar \
|
|
|
|
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
|
|
|
|
--set-default ELECTRON_IS_DEV 0 \
|
|
|
|
--inherit-argv0
|
|
|
|
|
|
|
|
pushd apps/desktop/resources/icons
|
|
|
|
for icon in *.png; do
|
|
|
|
dir=$out/share/icons/hicolor/"''${icon%.png}"/apps
|
|
|
|
mkdir -p "$dir"
|
|
|
|
cp "$icon" "$dir"/${icon}.png
|
|
|
|
done
|
|
|
|
popd
|
2023-10-22 19:32:25 +02:00
|
|
|
|
|
|
|
runHook postInstall
|
2021-11-03 20:37:50 +01:00
|
|
|
'';
|
2019-08-02 06:48:20 +02:00
|
|
|
|
2023-10-22 19:32:25 +02:00
|
|
|
desktopItems = [
|
|
|
|
(makeDesktopItem {
|
|
|
|
name = "bitwarden";
|
|
|
|
exec = "bitwarden %U";
|
|
|
|
inherit icon;
|
|
|
|
comment = description;
|
|
|
|
desktopName = "Bitwarden";
|
|
|
|
categories = [ "Utility" ];
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2023-09-21 01:30:11 +02:00
|
|
|
meta = {
|
|
|
|
changelog = "https://github.com/bitwarden/clients/releases/tag/${src.rev}";
|
2023-01-26 06:09:10 +01:00
|
|
|
inherit description;
|
2021-11-03 20:37:50 +01:00
|
|
|
homepage = "https://bitwarden.com";
|
2023-01-26 06:09:10 +01:00
|
|
|
license = lib.licenses.gpl3;
|
2023-09-21 01:30:11 +02:00
|
|
|
maintainers = with lib.maintainers; [ amarshall kiwi ];
|
2021-11-03 20:37:50 +01:00
|
|
|
platforms = [ "x86_64-linux" ];
|
2023-11-12 05:05:25 +01:00
|
|
|
mainProgram = "bitwarden";
|
2019-08-02 06:48:20 +02:00
|
|
|
};
|
2021-11-03 20:37:50 +01:00
|
|
|
}
|