2023-03-04 12:14:45 +00:00
|
|
|
{ lib
|
|
|
|
, buildNpmPackage
|
2023-10-09 19:29:22 +00:00
|
|
|
, cargo
|
2023-11-16 04:20:00 +00:00
|
|
|
, copyDesktopItems
|
2023-03-04 12:14:45 +00:00
|
|
|
, dbus
|
2024-09-26 11:04:55 +00:00
|
|
|
, electron_32
|
2023-03-04 12:14:45 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, glib
|
2024-07-27 06:49:29 +00:00
|
|
|
, gnome-keyring
|
2023-03-04 12:14:45 +00:00
|
|
|
, gtk3
|
|
|
|
, jq
|
2020-04-24 23:36:52 +00:00
|
|
|
, libsecret
|
|
|
|
, makeDesktopItem
|
|
|
|
, makeWrapper
|
2023-10-09 19:29:22 +00:00
|
|
|
, napi-rs-cli
|
2024-09-19 14:19:46 +00:00
|
|
|
, nix-update-script
|
2024-06-20 14:57:18 +00:00
|
|
|
, nodejs_20
|
2024-01-13 08:15:51 +00:00
|
|
|
, patchutils_0_4_2
|
2023-03-04 12:14:45 +00:00
|
|
|
, pkg-config
|
|
|
|
, python3
|
2024-01-13 08:15:51 +00:00
|
|
|
, runCommand
|
2023-10-09 19:29:22 +00:00
|
|
|
, rustc
|
2023-03-04 12:14:45 +00:00
|
|
|
, rustPlatform
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
let
|
2024-06-20 14:57:18 +00:00
|
|
|
description = "Secure and free password manager for all of your devices";
|
2023-03-04 12:14:45 +00:00
|
|
|
icon = "bitwarden";
|
2024-09-26 11:04:55 +00:00
|
|
|
electron = electron_32;
|
2023-11-16 04:20:00 +00:00
|
|
|
in buildNpmPackage rec {
|
2024-02-29 20:09:43 +00:00
|
|
|
pname = "bitwarden-desktop";
|
2024-09-26 11:04:55 +00:00
|
|
|
version = "2024.9.0";
|
2023-10-09 19:29:22 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "bitwarden";
|
|
|
|
repo = "clients";
|
|
|
|
rev = "desktop-v${version}";
|
2024-09-26 11:04:55 +00:00
|
|
|
hash = "sha256-o5nRG2j73qheDOyeFfSga64D8HbTn1EUrCiN0W+Xn0w=";
|
2023-10-09 19:29:22 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
patches = [
|
2024-04-21 15:54:59 +00:00
|
|
|
./electron-builder-package-lock.patch
|
2023-11-16 04:20:00 +00:00
|
|
|
];
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
postPatch = ''
|
2024-09-19 14:19:46 +00:00
|
|
|
# remove code under unfree license
|
|
|
|
rm -r bitwarden_license
|
2024-04-21 15:54:59 +00:00
|
|
|
'';
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
nodejs = nodejs_20;
|
2023-11-16 04:20:00 +00:00
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
makeCacheWritable = true;
|
2024-06-20 14:57:18 +00:00
|
|
|
npmFlags = [ "--engine-strict" "--legacy-peer-deps" ];
|
2023-10-09 19:29:22 +00:00
|
|
|
npmWorkspace = "apps/desktop";
|
2024-09-26 11:04:55 +00:00
|
|
|
npmDepsHash = "sha256-L7/frKCNlq0xr6T+aSqyEQ44yrIXwcpdU/djrhCJNNk=";
|
2023-10-09 19:29:22 +00:00
|
|
|
|
|
|
|
cargoDeps = rustPlatform.fetchCargoTarball {
|
|
|
|
name = "${pname}-${version}";
|
2024-01-13 08:15:51 +00: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-16 04:20:00 +00:00
|
|
|
patchFlags = [ "-p4" ];
|
2023-10-09 19:29:22 +00:00
|
|
|
sourceRoot = "${src.name}/${cargoRoot}";
|
2024-09-26 11:04:55 +00:00
|
|
|
hash = "sha256-y+6vaESiOeVrFJpZoOJ75onOpldqSsT2kqkMMzTDUmM=";
|
2023-10-09 19:29:22 +00:00
|
|
|
};
|
|
|
|
cargoRoot = "apps/desktop/desktop_native";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
nativeBuildInputs = [
|
2023-10-09 19:29:22 +00:00
|
|
|
cargo
|
2023-11-16 04:20:00 +00:00
|
|
|
copyDesktopItems
|
2023-03-04 12:14:45 +00:00
|
|
|
jq
|
|
|
|
makeWrapper
|
2023-10-09 19:29:22 +00:00
|
|
|
napi-rs-cli
|
|
|
|
pkg-config
|
2024-09-19 14:19:46 +00:00
|
|
|
(python3.withPackages (ps: with ps; [ setuptools ]))
|
2023-10-09 19:29:22 +00:00
|
|
|
rustc
|
|
|
|
rustPlatform.cargoCheckHook
|
|
|
|
rustPlatform.cargoSetupHook
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
glib
|
|
|
|
gtk3
|
|
|
|
libsecret
|
2023-03-04 12:14:45 +00:00
|
|
|
];
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
# node-argon2 builds with LTO, but that causes missing symbols. So disable it
|
|
|
|
# and rebuild. Then we need to copy it into the build output for
|
|
|
|
# electron-builder, as `apps/desktop/src/package.json` specifies `argon2` as
|
|
|
|
# a dependency and electron-builder will otherwise install a fresh (and
|
|
|
|
# broken) argon2. See https://github.com/ranisalt/node-argon2/pull/415
|
|
|
|
preConfigure = ''
|
|
|
|
pushd node_modules/argon2
|
|
|
|
substituteInPlace binding.gyp --replace-fail '"-flto", ' ""
|
|
|
|
"$npm_config_node_gyp" rebuild
|
|
|
|
popd
|
|
|
|
mkdir -p apps/desktop/build/node_modules
|
|
|
|
cp -r ./{,apps/desktop/build/}node_modules/argon2
|
|
|
|
'';
|
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
preBuild = ''
|
2023-05-24 13:37:59 +00: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
|
2024-09-19 14:19:46 +00:00
|
|
|
|
|
|
|
pushd apps/desktop/desktop_native/napi
|
|
|
|
npm run build
|
|
|
|
popd
|
2021-12-06 16:07:01 +00:00
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
postBuild = ''
|
|
|
|
pushd apps/desktop
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
# desktop_native/index.js loads a file of that name regarldess of the libc being used
|
2024-09-19 14:19:46 +00:00
|
|
|
mv desktop_native/napi/desktop_napi.* desktop_native/napi/desktop_napi.linux-x64-musl.node
|
2023-10-09 19:29:22 +00:00
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
npm exec electron-builder -- \
|
2023-03-04 12:14:45 +00:00
|
|
|
--dir \
|
2024-09-19 14:19:46 +00:00
|
|
|
-c.electronDist=${electron.dist} \
|
2023-03-04 12:14:45 +00:00
|
|
|
-c.electronVersion=${electron.version}
|
|
|
|
|
|
|
|
popd
|
|
|
|
'';
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
doCheck = true;
|
|
|
|
|
|
|
|
nativeCheckInputs = [
|
|
|
|
dbus
|
2024-07-27 06:49:29 +00:00
|
|
|
(gnome-keyring.override { useWrappedDaemon = false; })
|
2023-10-09 19:29:22 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
checkFlags = [
|
|
|
|
"--skip=password::password::tests::test"
|
|
|
|
];
|
|
|
|
|
|
|
|
checkPhase = ''
|
|
|
|
runHook preCheck
|
|
|
|
|
|
|
|
pushd ${cargoRoot}
|
|
|
|
export HOME=$(mktemp -d)
|
2024-07-27 06:49:29 +00:00
|
|
|
export -f cargoCheckHook runHook _eval _callImplicitHook _logHook
|
2023-10-09 19:29:22 +00:00
|
|
|
export cargoCheckType=release
|
|
|
|
dbus-run-session \
|
|
|
|
--config-file=${dbus}/share/dbus-1/session.conf \
|
|
|
|
-- bash -e -c cargoCheckHook
|
|
|
|
popd
|
|
|
|
|
|
|
|
runHook postCheck
|
|
|
|
'';
|
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
installPhase = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
runHook preInstall
|
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
mkdir $out
|
|
|
|
|
|
|
|
pushd apps/desktop/dist/linux-unpacked
|
|
|
|
mkdir -p $out/opt/Bitwarden
|
|
|
|
cp -r locales resources{,.pak} $out/opt/Bitwarden
|
|
|
|
popd
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
makeWrapper '${lib.getExe electron}' "$out/bin/bitwarden" \
|
2023-03-04 12:14:45 +00:00
|
|
|
--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-11-16 04:20:00 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
2021-12-06 16:07:01 +00:00
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
desktopItems = [
|
|
|
|
(makeDesktopItem {
|
|
|
|
name = "bitwarden";
|
|
|
|
exec = "bitwarden %U";
|
|
|
|
inherit icon;
|
|
|
|
comment = description;
|
|
|
|
desktopName = "Bitwarden";
|
|
|
|
categories = [ "Utility" ];
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
passthru = {
|
|
|
|
updateScript = nix-update-script {
|
|
|
|
extraArgs = [ "--commit" "--version=stable" "--version-regex=^desktop-v(.*)$" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
meta = {
|
|
|
|
changelog = "https://github.com/bitwarden/clients/releases/tag/${src.rev}";
|
2023-03-04 12:14:45 +00:00
|
|
|
inherit description;
|
2021-12-06 16:07:01 +00:00
|
|
|
homepage = "https://bitwarden.com";
|
2023-03-04 12:14:45 +00:00
|
|
|
license = lib.licenses.gpl3;
|
2024-06-24 18:47:55 +00:00
|
|
|
maintainers = with lib.maintainers; [ amarshall ];
|
2021-12-06 16:07:01 +00:00
|
|
|
platforms = [ "x86_64-linux" ];
|
2023-11-16 04:20:00 +00:00
|
|
|
mainProgram = "bitwarden";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-12-06 16:07:01 +00:00
|
|
|
}
|