biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / tools / security / bitwarden-directory-connector / default.nix
blob65b682a0fcf89e265c26f0f1565ad5e38e314a7c
2   lib,
3   buildNpmPackage,
4   electron,
5   fetchFromGitHub,
6   buildPackages,
7   python3,
8   pkg-config,
9   libsecret,
10   nodejs_18,
13 let
14   common = { name, npmBuildScript, installPhase }: buildNpmPackage rec {
15     pname = name;
16     version = "2024.9.0";
17     nodejs = nodejs_18;
19     src = fetchFromGitHub {
20       owner = "bitwarden";
21       repo = "directory-connector";
22       rev = "v${version}";
23       hash = "sha256-Vop5Y1prdjA5SOQsA1HNBr3IBhe9Ya8d8M6CsS9xohg=";
24     };
26     postPatch = ''
27       ${lib.getExe buildPackages.jq} 'del(.scripts.preinstall)' package.json > package.json.tmp
28       mv -f package.json{.tmp,}
30       substituteInPlace electron-builder.json \
31         --replace-fail '"afterSign": "scripts/notarize.js",' "" \
32         --replace-fail "AppImage" "dir"
33     '';
35     npmDepsHash = "sha256-8rmZSl5K2l97QHaNtcfW202TtcEa3HIjEjO/AkaZkdQ=";
37     env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
39     makeCacheWritable = true;
40     inherit npmBuildScript installPhase;
42     buildInputs = [
43       libsecret
44     ];
46     nativeBuildInputs = [
47       (python3.withPackages (ps: with ps; [ setuptools ]))
48       pkg-config
49     ];
51     meta = with lib; {
52       description = "LDAP connector for Bitwarden";
53       homepage = "https://github.com/bitwarden/directory-connector";
54       license = licenses.gpl3Only;
55       maintainers = with maintainers; [ Silver-Golden SuperSandro2000 ];
56       platforms = platforms.linux;
57       mainProgram = name;
58     };
59   };
60 in {
61   bitwarden-directory-connector = common {
62     name = "bitwarden-directory-connector";
63     npmBuildScript = "build:dist";
64     installPhase = ''
65       runHook preInstall
67       npm exec electron-builder -- \
68         --dir \
69         -c.electronDist=${electron.dist} \
70         -c.electronVersion=${electron.version} \
71         -c.npmRebuild=false
73       mkdir -p $out/share/bitwarden-directory-connector $out/bin
74       cp -r dist/*-unpacked/{locales,resources{,.pak}} $out/share/bitwarden-directory-connector
76       makeWrapper ${lib.getExe electron} $out/bin/bitwarden-directory-connector \
77         --add-flags $out/share/bitwarden-directory-connector/resources/app.asar \
78         --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
79         --set-default ELECTRON_IS_DEV 0 \
80         --inherit-argv0
82       runHook postInstall
83     '';
84   };
86   bitwarden-directory-connector-cli = common {
87     name = "bitwarden-directory-connector-cli";
88     npmBuildScript = "build:cli:prod";
89     installPhase = ''
90       runHook preInstall
92       mkdir -p $out/libexec/bitwarden-directory-connector
93       cp -R build-cli node_modules $out/libexec/bitwarden-directory-connector
95       # needs to be wrapped with nodejs so that it can be executed
96       chmod +x $out/libexec/bitwarden-directory-connector/build-cli/bwdc.js
97       mkdir -p $out/bin
98       ln -s $out/libexec/bitwarden-directory-connector/build-cli/bwdc.js $out/bin/bitwarden-directory-connector-cli
100       runHook postInstall
101     '';
102   };