1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2025-02-17 05:35:06 +01:00

qutebrowser: add special "__isDict" attr

Add special `__isDict` attribute in the settings to allow outputting
Python dicts into the config. An example of this being necessary is
setting the padding for tabs
This commit is contained in:
Giovanni d'Amelio 2024-08-30 15:49:37 -07:00
parent c2cd2a52e0
commit 2d9de557a1
2 changed files with 60 additions and 15 deletions

View file

@ -6,25 +6,34 @@ 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 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;
in if builtins.isAttrs v then
concatStringsSep "\n" (mapAttrsToList (formatLine "${o}${n}.") v)
if builtins.isAttrs v then
# Allow outputting python dicts in the config with the special __isDict attribute
if (v ? __isDict && v.__isDict == true) then
let
# Remove the __isDict attribute from the final output
removedSpecialAttr =
attrsets.filterAttrs (name: _value: name != "__isDict") v;
in concatStringsSep "\n"
(mapAttrsToList (formatDictLine "${o}${n}") removedSpecialAttr)
else
concatStringsSep "\n" (mapAttrsToList (formatLine "${o}${n}.") v)
else
"${o}${n} = ${formatValue v}";
formatDictLine = o: n: v: ''${o}['${n}'] = "${v}"'';
formatDictLine = o: n: v: "${o}['${n}'] = ${formatValue v}";
formatKeyBindings = m: b:
let
@ -108,6 +117,15 @@ in {
tabs.bar.bg = "#000000";
};
tabs.tabs_are_windows = true;
# Special `__isDict` attribute to allow outputting Python Dicts
tabs.padding = {
__isDict = true;
bottom = 1;
left = 5;
right = 5;
top = 1;
};
}
'';
};

View file

@ -14,6 +14,25 @@
};
spellcheck.languages = [ "en-US" "sv-SE" ];
tabs.tabs_are_windows = true;
tabs.padding = {
__isDict = true;
bottom = 1;
left = 5;
right = 5;
top = 1;
};
};
searchEngines = {
DEFAULT = "https://duckduckgo.com/?q={}";
# Nix stuff
nix-home-manager =
"https://home-manager-options.extranix.com/?query={}&release=master";
nix-options =
"https://search.nixos.org/options?channel=unstable&type=packages&query={}";
nix-packages =
"https://search.nixos.org/packages?channel=unstable&type=packages&query={}";
};
extraConfig = ''
@ -38,7 +57,15 @@
c.colors.hints.fg = "#ffffff"
c.colors.tabs.bar.bg = "#000000"
c.spellcheck.languages = ["en-US", "sv-SE"]
c.tabs.padding['bottom'] = 1
c.tabs.padding['left'] = 5
c.tabs.padding['right'] = 5
c.tabs.padding['top'] = 1
c.tabs.tabs_are_windows = True
c.url.searchengines['DEFAULT'] = "https://duckduckgo.com/?q={}"
c.url.searchengines['nix-home-manager'] = "https://home-manager-options.extranix.com/?query={}&release=master"
c.url.searchengines['nix-options'] = "https://search.nixos.org/options?channel=unstable&type=packages&query={}"
c.url.searchengines['nix-packages'] = "https://search.nixos.org/packages?channel=unstable&type=packages&query={}"
# Extra qutebrowser configuration.
''
}