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
, cargo
2023-01-26 05:09:10 +00:00
, dbus
, electron_25
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
, napi-rs-cli
, nodejs_18
2023-01-26 05:09:10 +00:00
, pkg-config
, python3
, rustc
2023-01-26 05:09:10 +00:00
, rustPlatform
2019-08-02 04:48:20 +00:00
}:
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_25;
2023-01-26 05:09:10 +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
};
in buildNpmPackage' rec {
2023-01-26 05:09:10 +00:00
pname = "bitwarden";
version = "2023.9.3";
src = fetchFromGitHub {
owner = "bitwarden";
repo = "clients";
rev = "desktop-v${version}";
hash = "sha256-NiMJmtCx+yD24BCyMgHLpRApNwoIJRps5qmmlVdB0G0=";
};
2019-08-02 04:48:20 +00:00
2023-01-26 05:09:10 +00:00
makeCacheWritable = true;
npmWorkspace = "apps/desktop";
npmDepsHash = "sha256-HQPxmATA9bUc4NTfvYsL6fGuicU9baySCmNHahs8EF4=";
2019-08-02 04:48:20 +00:00
cargoDeps = rustPlatform.fetchCargoTarball {
name = "${pname}-${version}";
inherit src;
sourceRoot = "${src.name}/${cargoRoot}";
hash = "sha256-mFxvK9cmSBRVnUwEbzADUa5W5TCL51wcUHxuR5JZwLE=";
};
cargoRoot = "apps/desktop/desktop_native";
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
2019-08-02 04:48:20 +00:00
2023-01-26 05:09:10 +00:00
nativeBuildInputs = [
cargo
2023-01-26 05:09:10 +00:00
jq
makeWrapper
moreutils
napi-rs-cli
pkg-config
2023-02-16 17:45:31 +00:00
python3
rustc
rustPlatform.cargoCheckHook
rustPlatform.cargoSetupHook
];
buildInputs = [
glib
gtk3
libsecret
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
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
# 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 -- \
2023-01-26 05:09:10 +00:00
--dir \
-c.electronDist=${electron}/libexec/electron \
2023-01-26 05:09:10 +00:00
-c.electronVersion=${electron.version}
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
'';
2023-01-26 05:09:10 +00:00
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
meta = {
changelog = "https://github.com/bitwarden/clients/releases/tag/${src.rev}";
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 lib.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
}