about summary refs log tree commit diff stats
path: root/modules/by-name/qu/qutebrowser/module.nix
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/by-name/qu/qutebrowser/module.nix106
1 files changed, 106 insertions, 0 deletions
diff --git a/modules/by-name/qu/qutebrowser/module.nix b/modules/by-name/qu/qutebrowser/module.nix
new file mode 100644
index 00000000..dab06237
--- /dev/null
+++ b/modules/by-name/qu/qutebrowser/module.nix
@@ -0,0 +1,106 @@
+{
+  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: let
+      statusbar_widgets = [
+        "keypress"
+        "text:${name}"
+        "search_match"
+        "url"
+        "scroll"
+        "history"
+        "tabs"
+        "progress"
+      ];
+
+      statusbar_widgets_str =
+        # NOTE(@bpeetz): We need either two layers of escaping or the binary wrapper, as we first inline this
+        # into the runCommand below, and then into the actual qutebrowser wrapper script. <2025-06-16>
+        lib.strings.escapeShellArg (builtins.toJSON statusbar_widgets);
+    in
+      pkgs.runCommandLocal "qutebrowser-${name}" {
+        nativeBuildInputs = [
+          pkgs.makeBinaryWrapper
+        ];
+      }
+      ''
+        makeWrapper ${lib.getExe 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" \
+          --add-flags --set \
+          --add-flags statusbar.widgets \
+          --add-flags ${statusbar_widgets_str}
+      '';
+  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;
+        };
+      };
+    };
+  };
+}