diff --git a/.nvimlog b/.nvimlog new file mode 100644 index 000000000..e69de29bb diff --git a/modules/programs/qutebrowser.nix b/modules/programs/qutebrowser.nix index b6cc41ead..8d7971306 100644 --- a/modules/programs/qutebrowser.nix +++ b/modules/programs/qutebrowser.nix @@ -6,26 +6,36 @@ let cfg = config.programs.qutebrowser; + formatValue = v: + if v == null then + "None" + else if builtins.isBool v then + (if v then "True" else "False") + else if builtins.isString v then + ''"${v}"'' + else if builtins.isList v then + "[${concatStringsSep ", " (map formatValue v)}]" + else + builtins.toString v; + formatLine = o: n: v: - let - formatValue = v: - if builtins.isNull v then - "None" - else if builtins.isBool v then - (if v then "True" else "False") - else if builtins.isString v then - ''"${v}"'' - else if builtins.isList v then - "[${concatStringsSep ", " (map formatValue v)}]" - else - builtins.toString v; - in if builtins.isAttrs v then + if builtins.isAttrs v then concatStringsSep "\n" (mapAttrsToList (formatLine "${o}${n}.") v) else "${o}${n} = ${formatValue v}"; formatDictLine = o: n: v: ''${o}['${n}'] = "${v}"''; + formatDomainBlock = n: v: + let + formatDomainLine = d: o: on: ov: + if builtins.isAttrs ov then + concatStringsSep "\n" + (mapAttrsToList (formatDomainLine d "${o}${on}.") ov) + else + ''config.set("${o}${on}", ${formatValue ov}, "${d}")''; + in concatStringsSep "\n" (mapAttrsToList (formatDomainLine n "") v); + formatKeyBindings = m: b: let formatKeyBinding = m: k: c: @@ -109,6 +119,26 @@ in { ''; }; + domainSettings = mkOption { + type = types.attrsOf (types.attrsOf types.anything); + default = { }; + description = '' + Per-domain options to add to qutebrowser {file}`config.py` file. + See + for options. + ''; + example = literalExpression '' + { + "https://netflix.com" = { + content.notifications.enable = false; + }; + "https://facebook.com" = { + content.notifications.enable = false; + }; + } + ''; + }; + keyMappings = mkOption { type = types.attrsOf types.str; default = { }; @@ -277,6 +307,7 @@ in { else "config.load_autoconfig(False)") ] ++ mapAttrsToList (formatLine "c.") cfg.settings + ++ mapAttrsToList formatDomainBlock cfg.domainSettings ++ mapAttrsToList (formatDictLine "c.aliases") cfg.aliases ++ mapAttrsToList (formatDictLine "c.url.searchengines") cfg.searchEngines ++ mapAttrsToList (formatDictLine "c.bindings.key_mappings") diff --git a/tests/modules/programs/qutebrowser/default.nix b/tests/modules/programs/qutebrowser/default.nix index 20b76337b..8417138d3 100644 --- a/tests/modules/programs/qutebrowser/default.nix +++ b/tests/modules/programs/qutebrowser/default.nix @@ -3,4 +3,5 @@ qutebrowser-keybindings = ./keybindings.nix; qutebrowser-quickmarks = ./quickmarks.nix; qutebrowser-settings = ./settings.nix; + qutebrowser-domainsettings = ./domainsettings.nix; } diff --git a/tests/modules/programs/qutebrowser/domainsettings.nix b/tests/modules/programs/qutebrowser/domainsettings.nix new file mode 100644 index 000000000..dd8d66a5b --- /dev/null +++ b/tests/modules/programs/qutebrowser/domainsettings.nix @@ -0,0 +1,34 @@ +{ pkgs, ... }: + +{ + programs.qutebrowser = { + enable = true; + + domainSettings = { + "https://teams.microsoft.com".content.notifications.enabled = true; + "https://www.netflix.com".content.notifications.enabled = false; + "https://www.facebook.com".content.notifications.enabled = false; + "https://mail.google.com".content.register_protocol_handler = true; + }; + }; + + test.stubs.qutebrowser = { }; + + nmt.script = let + qutebrowserConfig = if pkgs.stdenv.hostPlatform.isDarwin then + ".qutebrowser/config.py" + else + ".config/qutebrowser/config.py"; + in '' + assertFileContent \ + home-files/${qutebrowserConfig} \ + ${ + pkgs.writeText "qutebrowser-expected-config.py" '' + config.load_autoconfig(False) + config.set("content.register_protocol_handler", True, "https://mail.google.com") + config.set("content.notifications.enabled", True, "https://teams.microsoft.com") + config.set("content.notifications.enabled", False, "https://www.facebook.com") + config.set("content.notifications.enabled", False, "https://www.netflix.com")'' + } + ''; +}