1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 11:39:46 +01:00

Qutebrowser: Way to define settings for each domain

This commit adds a way to define per-domain settings in config.py.
The option is called domainSettings and contains an attribute set
of attribute sets with the base domain as the name.
This commit is contained in:
William Boulanger 2024-05-20 16:12:12 -04:00
parent 2f3367769a
commit 6d2711f813
4 changed files with 79 additions and 13 deletions

0
.nvimlog Normal file
View file

View file

@ -6,10 +6,8 @@ let
cfg = config.programs.qutebrowser;
formatLine = o: n: v:
let
formatValue = v:
if builtins.isNull v then
if v == null then
"None"
else if builtins.isBool v then
(if v then "True" else "False")
@ -19,13 +17,25 @@ let
"[${concatStringsSep ", " (map formatValue v)}]"
else
builtins.toString v;
in if builtins.isAttrs v then
formatLine = o: n: v:
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 <https://qutebrowser.org/doc/help/settings.html>
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")

View file

@ -3,4 +3,5 @@
qutebrowser-keybindings = ./keybindings.nix;
qutebrowser-quickmarks = ./quickmarks.nix;
qutebrowser-settings = ./settings.nix;
qutebrowser-domainsettings = ./domainsettings.nix;
}

View file

@ -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")''
}
'';
}