about summary refs log tree commit diff stats
path: root/modules/by-name/qu/qutebrowser/module.nix
blob: 20ab8e4b73c840c4ff9b6d004ac3098ccd789373 (plain) (blame)
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
81
82
83
84
85
86
87
{
  config,
  lib,
  pkgs,
  self,
  ...
}: let
  cfg = config.soispha.programs.qutebrowser;

  qutebrowsersWithProfiles = let
    xdg_data_home = config.home-manager.users.soispha.xdg.dataHome;
    xdg_config_home = config.home-manager.users.soispha.xdg.configHome;

    mkQutebrowser = name:
      pkgs.runCommandLocal "qutebrowser-${name}" {
        nativeBuildInputs = [
          pkgs.makeBinaryWrapper
        ];
      }
      ''
        makeWrapper ${pkgs.qutebrowser-patched} "$out/bin/qutebrowser-${name}" \
          --add-flags --no-err-windows \
          --add-flags --basedir \
          --add-flags "${xdg_data_home}/qutebrowser/${name}" \
          --add-flags --config \
          --add-flags "${xdg_config_home}/qutebrowser/config.py" \
      '';
  in
    builtins.filter (val: val != null) (lib.mapAttrsToList (name: value:
      if value.enable
      then mkQutebrowser name
      else null)
    cfg.profiles);
in {
  options.soispha.programs.qutebrowser = {
    enable = lib.mkEnableOption "qutebrowser";

    key = lib.mkOption {
      type = lib.types.str;
      description = ''
        The gpg key, used when decrypting the keepassxc connection key.
      '';
    };

    profiles = lib.mkOption {
      type = lib.types.attrsOf (lib.types.submodule {
        options = {
          enable =
            (lib.mkEnableOption "this profile")
            // {
              default = true;
            };
        };
      });

      description = "A name enable map of profies to create besides the default `default` profile.";
      default = {};
    };
  };

  config = lib.mkIf cfg.enable {
    home-manager.users.soispha = {
      disabledModules = [
        "${self.inputs.home-manager}/modules/programs/qutebrowser.nix"
      ];
      imports = [
        ./module.hm.nix
      ];

      home.packages = qutebrowsersWithProfiles;

      programs.qutebrowser = {
        enable = true;
        package = pkgs.hello; # TODO: Set to null, once supported <2025-06-06>

        settings = import ./settings {
          inherit lib pkgs;
          cfg = config.soispha.programs.qutebrowser;
        };

        extraConfig = {
          "redirects" = ./include/redirects.py;
        };
      };
    };
  };
}