nixpkgs/pkgs/tools/security/bitwarden/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

165 lines
3.8 KiB
Nix
Raw Normal View History

2023-01-26 05:09:10 +00:00
{ lib
, applyPatches
2023-01-26 05:09:10 +00:00
, buildNpmPackage
, dbus
, electron_24
2023-01-26 05:09:10 +00:00
, fetchFromGitHub
, glib
, gnome
, gtk3
, jq
2019-08-02 04:48:20 +00:00
, libsecret
, makeDesktopItem
, makeWrapper
2023-01-26 05:09:10 +00:00
, moreutils
, nodejs_18
2023-01-26 05:09:10 +00:00
, pkg-config
, python3
, rustPlatform
2019-08-02 04:48:20 +00:00
, wrapGAppsHook
}:
2023-01-26 05:09:10 +00:00
let
description = "A secure and free password manager for all of your devices";
icon = "bitwarden";
buildNpmPackage' = buildNpmPackage.override { nodejs = nodejs_18; };
electron = electron_24;
2023-01-26 05:09:10 +00:00
2023-06-22 02:34:05 +00:00
version = "2023.5.1";
src = applyPatches {
src = fetchFromGitHub {
owner = "bitwarden";
repo = "clients";
rev = "desktop-v${version}";
2023-06-22 02:34:05 +00:00
sha256 = "sha256-dD9C6+GRjCMcfBse2Qq0ot8bVGyhjnd8VvpdNlrjRs4=";
};
2023-06-03 12:16:57 +00:00
patches = [ ];
2023-01-26 05:09:10 +00:00
};
desktop-native = rustPlatform.buildRustPackage {
2023-01-26 05:09:10 +00:00
pname = "bitwarden-desktop-native";
inherit src version;
sourceRoot = "${src.name}/apps/desktop/desktop_native";
2023-06-22 02:34:05 +00:00
cargoSha256 = "sha256-8U4E5q2OSZGXy2ZRn0y4Skm5Y+FiOJVU1mtzObO9UqY=";
2023-01-26 05:09:10 +00:00
nativeBuildInputs = [
pkg-config
wrapGAppsHook
];
2019-08-02 04:48:20 +00:00
2023-01-26 05:09:10 +00:00
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
'';
2019-08-02 04:48:20 +00:00
};
2021-11-03 19:37:50 +00:00
desktopItem = makeDesktopItem {
name = "bitwarden";
exec = "bitwarden %U";
2023-01-26 05:09:10 +00:00
inherit icon;
comment = description;
2021-11-03 19:37:50 +00:00
desktopName = "Bitwarden";
categories = [ "Utility" ];
2021-11-03 19:37:50 +00:00
};
2019-08-02 04:48:20 +00:00
2023-01-26 05:09:10 +00:00
in
2019-08-02 04:48:20 +00:00
2023-01-26 05:09:10 +00:00
buildNpmPackage' {
pname = "bitwarden";
inherit src version;
2019-08-02 04:48:20 +00:00
2023-01-26 05:09:10 +00:00
makeCacheWritable = true;
npmBuildFlags = [
"--workspace apps/desktop"
];
2023-06-22 02:34:05 +00:00
npmDepsHash = "sha256-USXWA/7wuu3i9/+/pMXREgcB+4yOpQGG5RGuUyJvuQw=";
2019-08-02 04:48:20 +00:00
2023-01-26 05:09:10 +00:00
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
2019-08-02 04:48:20 +00:00
2023-01-26 05:09:10 +00:00
nativeBuildInputs = [
jq
makeWrapper
moreutils
2023-02-16 17:45:31 +00:00
python3
2023-01-26 05:09:10 +00:00
];
preBuild = ''
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-01-26 05:09:10 +00:00
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
2021-11-03 19:37:50 +00:00
'';
2019-08-02 04:48:20 +00:00
2023-01-26 05:09:10 +00:00
postBuild = ''
pushd apps/desktop
npm exec electron-builder -- \
2023-01-26 05:09:10 +00:00
--dir \
-c.electronDist=${electron}/lib/electron \
-c.electronVersion=${electron.version}
popd
'';
installPhase = ''
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
mkdir -p $out/share/applications
cp ${desktopItem}/share/applications/* $out/share/applications
2019-08-02 04:48:20 +00:00
2023-01-26 05:09:10 +00:00
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
2021-11-03 19:37:50 +00:00
'';
2019-08-02 04:48:20 +00:00
2021-11-03 19:37:50 +00:00
meta = with lib; {
2023-01-26 05:09:10 +00:00
inherit description;
2021-11-03 19:37:50 +00:00
homepage = "https://bitwarden.com";
2023-01-26 05:09:10 +00:00
license = lib.licenses.gpl3;
maintainers = with maintainers; [ amarshall kiwi ];
2021-11-03 19:37:50 +00:00
platforms = [ "x86_64-linux" ];
2019-08-02 04:48:20 +00:00
};
2021-11-03 19:37:50 +00:00
}