aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/programs/browserpass.nix
blob: 7af5e8f87565a67cef9a58beb976a155ccc88aad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{ config, lib, pkgs, ... }:

with lib;

let
  browsers = [
    "chrome"
    "chromium"
    "firefox"
    "vivaldi"
  ];
in {
  options = {
    programs.browserpass = {
      enable = mkEnableOption "the browserpass extension host application";

      browsers = mkOption {
        type = types.listOf (types.enum browsers);
        default = browsers;
        example = [ "firefox" ];
        description = "Which browsers to install browserpass for";
      };
    };
  };

  config = mkIf config.programs.browserpass.enable {
    home.file = builtins.concatLists (with pkgs.stdenv; map (x:
      if x == "chrome" then
        let dir = if isDarwin
          then "Library/Application Support/Google/Chrome/NativeMessagingHosts"
          else ".config/google-chrome/NativeMessagingHosts";
        in [
          {
            target = "${dir}/com.github.browserpass.native.json";
            source = "${pkgs.browserpass}/lib/browserpass/hosts/chromium/com.github.browserpass.native.json";
          }
          {
            target = "${dir}/../policies/managed/com.github.browserpass.native.json";
            source = "${pkgs.browserpass}/lib/browserpass/policies/chromium/com.github.browserpass.native.json";
          }
        ]
      else if x == "chromium" then
        let dir = if isDarwin
          then "Library/Application Support/Chromium/NativeMessagingHosts"
          else ".config/chromium/NativeMessagingHosts";
        in [
          {
            target = "${dir}/com.github.browserpass.native.json";
            source = "${pkgs.browserpass}/lib/browserpass/hosts/chromium/com.github.browserpass.native.json";
          }
          {
            target = "${dir}/../policies/managed/com.github.browserpass.native.json";
            source = "${pkgs.browserpass}/lib/browserpass/policies/chromium/com.github.browserpass.native.json";
          }
        ]
      else if x == "firefox" then
        [ {
          target = (if isDarwin
            then "Library/Application Support/Mozilla/NativeMessagingHosts"
            else ".mozilla/native-messaging-hosts")
            + "/com.github.browserpass.native.json";
          source = "${pkgs.browserpass}/lib/browserpass/hosts/firefox/com.github.browserpass.native.json";
        } ]
      else if x == "vivaldi" then
        let dir = if isDarwin
          then "Library/Application Support/Vivaldi/NativeMessagingHosts"
          else ".config/vivaldi/NativeMessagingHosts";
        in [
          {
            target = "${dir}/com.github.browserpass.native.json";
            source = "${pkgs.browserpass}/lib/browserpass/hosts/chromium/com.github.browserpass.native.json";
          }
          {
            target = "${dir}/../policies/managed/com.github.browserpass.native.json";
            source = "${pkgs.browserpass}/lib/browserpass/policies/chromium/com.github.browserpass.native.json";
          }
        ]
      else throw "unknown browser ${x}") config.programs.browserpass.browsers);
  };
}