From d123fca83c9f99b5337679892a2f69cd23005cac Mon Sep 17 00:00:00 2001 From: Yevhen Shymotiuk Date: Thu, 24 Mar 2022 19:35:47 +0200 Subject: [PATCH] browserpass: add brave support --- modules/programs/browserpass.nix | 22 +++++++++++++++---- .../programs/browserpass/browserpass.nix | 9 +++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/modules/programs/browserpass.nix b/modules/programs/browserpass.nix index 10a2883c..8faf5315 100644 --- a/modules/programs/browserpass.nix +++ b/modules/programs/browserpass.nix @@ -2,7 +2,9 @@ with lib; -let browsers = [ "chrome" "chromium" "firefox" "vivaldi" ]; +let + cfg = config.programs.browserpass; + browsers = [ "brave" "chrome" "chromium" "firefox" "vivaldi" ]; in { options = { programs.browserpass = { @@ -17,10 +19,22 @@ in { }; }; - config = mkIf config.programs.browserpass.enable { + config = mkIf cfg.enable { home.file = foldl' (a: b: a // b) { } (concatMap (x: with pkgs.stdenv; - if x == "chrome" then + if x == "brave" then + let + dir = if isDarwin then + "Library/Application Support/BraveSoftware/Brave-Browser/NativeMessagingHosts" + else + ".config/BraveSoftware/Brave-Browser/NativeMessagingHosts"; + in [{ + # Policies are read from `/etc/brave/policies` only + # https://github.com/brave/brave-browser/issues/19052 + "${dir}/com.github.browserpass.native.json".source = + "${pkgs.browserpass}/lib/browserpass/hosts/chromium/com.github.browserpass.native.json"; + }] + else if x == "chrome" then let dir = if isDarwin then "Library/Application Support/Google/Chrome/NativeMessagingHosts" @@ -71,6 +85,6 @@ in { "${pkgs.browserpass}/lib/browserpass/policies/chromium/com.github.browserpass.native.json"; }] else - throw "unknown browser ${x}") config.programs.browserpass.browsers); + throw "unknown browser ${x}") cfg.browsers); }; } diff --git a/tests/modules/programs/browserpass/browserpass.nix b/tests/modules/programs/browserpass/browserpass.nix index 9189a445..2e1ca65e 100644 --- a/tests/modules/programs/browserpass/browserpass.nix +++ b/tests/modules/programs/browserpass/browserpass.nix @@ -6,11 +6,11 @@ with lib; config = { programs.browserpass = { enable = true; - browsers = [ "chrome" "chromium" "firefox" "vivaldi" ]; + browsers = [ "brave" "chrome" "chromium" "firefox" "vivaldi" ]; }; nmt.script = if pkgs.stdenv.hostPlatform.isDarwin then '' - for dir in "Google/Chrome" "Chromium" "Mozilla" "Vivaldi"; do + for dir in "BraveSoftware/Brave-Browser" "Google/Chrome" "Chromium" "Mozilla" "Vivaldi"; do assertFileExists "home-files/Library/Application Support/$dir/NativeMessagingHosts/com.github.browserpass.native.json" done @@ -18,8 +18,11 @@ with lib; assertFileExists "home-files/Library/Application Support/$dir/policies/managed/com.github.browserpass.native.json" done '' else '' - for dir in "google-chrome" "chromium" "vivaldi"; do + for dir in "BraveSoftware/Brave-Browser" "google-chrome" "chromium" "vivaldi"; do assertFileExists "home-files/.config/$dir/NativeMessagingHosts/com.github.browserpass.native.json" + done + + for dir in "google-chrome" "chromium" "vivaldi"; do assertFileExists "home-files/.config/$dir/policies/managed/com.github.browserpass.native.json" done