fork/home-manager
git clone https://git.julia.blue/fork/home-manager
3433206e
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . qutebrowser ; 8 9formatLine = o :n :v : 10let 11formatValue = v : 12if builtins . isNull v then 13"None" 14else if builtins . isBool v then 15( if v then "True" else "False" ) 16else if builtins . isString v then 17''" ${ v } "'' 18else if builtins . isList v then 19"[ ${ concatStringsSep ", " ( map formatValue v )} ]" 20else 21builtins . toString v ; 22in if builtins . isAttrs v then 23concatStringsSep "\n" ( mapAttrsToList ( formatLine " ${ o }${ n } ." ) v ) 24else 25" ${ o }${ n } = ${ formatValue v } " ; 26 27formatDictLine = o :n :v :'' ${ o } [' ${ n } '] = " ${ v } "'' ; 28 29formatKeyBindings = m :b : 30let 31formatKeyBinding = m :k :c : 32''config.bind(" ${ k } ", " ${ escape [ ''"'' ] c } ", mode=" ${ m } ")'' ; 33in concatStringsSep "\n" ( mapAttrsToList ( formatKeyBinding m ) b ); 34 35formatQuickmarks = n :s :" ${ n } ${ s } " ; 36 37in { 38options . programs . qutebrowser = { 39enable = mkEnableOption "qutebrowser" ; 40 41package = mkOption { 42type = types . package ; 43default = pkgs . qutebrowser ; 44defaultText = literalExpression "pkgs.qutebrowser" ; 45description = "Qutebrowser package to install." ; 46}; 47 48aliases = mkOption { 49type = types . attrsOf types . str ; 50default = { }; 51description = '' 52Aliases for commands. 53'' ; 54}; 55 56loadAutoconfig = mkOption { 57type = types . bool ; 58default = false ; 59description = '' 60Load settings configured via the GUI. 61'' ; 62}; 63 64searchEngines = mkOption { 65type = types . attrsOf types . str ; 66default = { }; 67description = '' 68Search engines that can be used via the address bar. Maps a search 69engine name (such as `DEFAULT`, or 70`ddg`) to a URL with a `{}` 71placeholder. The placeholder will be replaced by the search term, use 72`{{` and `}}` for literal 73`{/}` signs. The search engine named 74`DEFAULT` is used when 75`url.auto_search` is turned on and something else than 76a URL was entered to be opened. Other search engines can be used by 77prepending the search engine name to the search term, for example 78`:open google qutebrowser`. 79'' ; 80example = literalExpression '' 81{ 82w = "https://en.wikipedia.org/wiki/Special:Search?search={}&go=Go&ns0=1"; 83aw = "https://wiki.archlinux.org/?search={}"; 84nw = "https://nixos.wiki/index.php?search={}"; 85g = "https://www.google.com/search?hl=en&q={}"; 86} 87'' ; 88}; 89 90settings = mkOption { 91type = types . attrsOf types . anything ; 92default = { }; 93description = '' 94Options to add to qutebrowser {file}`config.py` file. 95See <https://qutebrowser.org/doc/help/settings.html> 96for options. 97'' ; 98example = literalExpression '' 99{ 100colors = { 101hints = { 102bg = "#000000"; 103fg = "#ffffff"; 104}; 105tabs.bar.bg = "#000000"; 106}; 107tabs.tabs_are_windows = true; 108} 109'' ; 110}; 111 112keyMappings = mkOption { 113type = types . attrsOf types . str ; 114default = { }; 115description = '' 116This setting can be used to map keys to other keys. When the key used 117as dictionary-key is pressed, the binding for the key used as 118dictionary-value is invoked instead. This is useful for global 119remappings of keys, for example to map Ctrl-[ to Escape. Note that when 120a key is bound (via `bindings.default` or 121`bindings.commands`), the mapping is ignored. 122'' ; 123}; 124 125enableDefaultBindings = mkOption { 126type = types . bool ; 127default = true ; 128description = '' 129Disable to prevent loading default key bindings. 130'' ; 131}; 132 133keyBindings = mkOption { 134type = with types ; attrsOf ( attrsOf ( separatedString " ;; " )); 135default = { }; 136description = '' 137Key bindings mapping keys to commands in different modes. This setting 138is a dictionary containing mode names and dictionaries mapping keys to 139commands: `{mode: {key: command}}` If you want to map 140a key to another key, check the `keyMappings` setting 141instead. For modifiers, you can use either `-` or 142`+` as delimiters, and these names: 143 144Control 145: `Control`, `Ctrl` 146 147Meta 148: `Meta`, `Windows`, `Mod4` 149 150Alt 151: `Alt`, `Mod1` 152 153Shift 154: `Shift` 155 156For simple keys (no `<>`-signs), a capital 157letter means the key is pressed with Shift. For special keys (with 158`<>`-signs), you need to explicitly add 159`Shift-` to match a key pressed with shift. If you 160want a binding to do nothing, bind it to the `nop` 161command. If you want a default binding to be passed through to the 162website, bind it to null. Note that some commands which are only useful 163for bindings (but not used interactively) are hidden from the command 164completion. See `:help` for a full list of available 165commands. The following modes are available: 166 167`normal` 168: Default mode, where most commands are invoked. 169 170`insert` 171: Entered when an input field is focused on a website, or by 172pressing `i` in normal mode. Passes through almost all keypresses 173to the website, but has some bindings like 174`<Ctrl-e>` to open an external editor. 175Note that single keys can't be bound in this mode. 176 177`hint` 178: Entered when `f` is pressed to select links with the keyboard. Note 179that single keys can't be bound in this mode. 180 181`passthrough` 182: Similar to insert mode, but passes through all keypresses except 183`<Escape>` to leave the mode. It might be 184useful to bind `<Escape>` to some other 185key in this mode if you want to be able to send an Escape key to 186the website as well. Note that single keys can't be bound in this 187mode. 188 189`command` 190: Entered when pressing the `:` key in order to enter a command. Note 191that single keys can't be bound in this mode. 192 193`prompt` 194: Entered when there's a prompt to display, like for download 195locations or when invoked from JavaScript. 196 197`yesno` 198: Entered when there's a yes/no prompt displayed. 199 200`caret` 201: Entered when pressing the `v` mode, used to select text using the 202keyboard. 203 204`register` 205: Entered when qutebrowser is waiting for a register name/key for 206commands like `:set-mark`. 207'' ; 208example = literalExpression '' 209{ 210normal = { 211"<Ctrl-v>" = "spawn mpv {url}"; 212",p" = "spawn --userscript qute-pass"; 213",l" = '''config-cycle spellcheck.languages ["en-GB"] ["en-US"]'''; 214"<F1>" = mkMerge [ 215"config-cycle tabs.show never always" 216"config-cycle statusbar.show in-mode always" 217"config-cycle scrolling.bar never always" 218]; 219}; 220prompt = { 221"<Ctrl-y>" = "prompt-yes"; 222}; 223} 224'' ; 225}; 226 227quickmarks = mkOption { 228type = types . attrsOf types . str ; 229default = { }; 230description = '' 231Quickmarks to add to qutebrowser's {file}`quickmarks` file. 232Note that when Home Manager manages your quickmarks, you cannot edit them at runtime. 233'' ; 234example = literalExpression '' 235{ 236nixpkgs = "https://github.com/NixOS/nixpkgs"; 237home-manager = "https://github.com/nix-community/home-manager"; 238} 239'' ; 240}; 241 242greasemonkey = mkOption { 243type = types . listOf types . package ; 244default = [ ]; 245example = literalExpression '' 246[ 247(pkgs.fetchurl { 248url = "https://raw.githubusercontent.com/afreakk/greasemonkeyscripts/1d1be041a65c251692ee082eda64d2637edf6444/youtube_sponsorblock.js"; 249sha256 = "sha256-e3QgDPa3AOpPyzwvVjPQyEsSUC9goisjBUDMxLwg8ZE="; 250}) 251(pkgs.writeText "some-script.js" ''' 252// ==UserScript== 253// @name Some Greasemonkey script 254// ==/UserScript== 255''') 256] 257'' ; 258description = '' 259Greasemonkey userscripts to add to qutebrowser's {file}`greasemonkey` 260directory. 261'' ; 262}; 263 264extraConfig = mkOption { 265type = types . lines ; 266default = "" ; 267description = '' 268Extra lines added to qutebrowser {file}`config.py` file. 269'' ; 270}; 271}; 272 273config = let 274qutebrowserConfig = concatStringsSep "\n" ([ 275( if cfg . loadAutoconfig then 276"config.load_autoconfig()" 277else 278"config.load_autoconfig(False)" ) 279] ++ mapAttrsToList ( formatLine "c." ) cfg . settings 280++ mapAttrsToList ( formatDictLine "c.aliases" ) cfg . aliases 281++ mapAttrsToList ( formatDictLine "c.url.searchengines" ) cfg . searchEngines 282++ mapAttrsToList ( formatDictLine "c.bindings.key_mappings" ) 283cfg . keyMappings 284++ optional ( ! cfg . enableDefaultBindings ) "c.bindings.default = {}" 285++ mapAttrsToList formatKeyBindings cfg . keyBindings 286++ optional ( cfg . extraConfig != "" ) cfg . extraConfig ); 287 288quickmarksFile = optionals ( cfg . quickmarks != { }) concatStringsSep "\n" 289(( mapAttrsToList formatQuickmarks cfg . quickmarks )); 290 291greasemonkeyDir = optionals ( cfg . greasemonkey != [ ]) pkgs . linkFarmFromDrvs 292"greasemonkey-userscripts" cfg . greasemonkey ; 293in mkIf cfg . enable { 294home . packages = [ cfg . package ]; 295 296home . file . ".qutebrowser/config.py" = 297mkIf pkgs . stdenv . hostPlatform . isDarwin { text = qutebrowserConfig ; }; 298 299home . file . ".qutebrowser/quickmarks" = 300mkIf ( cfg . quickmarks != { } && pkgs . stdenv . hostPlatform . isDarwin ) { 301text = quickmarksFile ; 302}; 303 304xdg . configFile . "qutebrowser/config.py" = 305mkIf pkgs . stdenv . hostPlatform . isLinux { 306text = qutebrowserConfig ; 307onChange = '' 308hash="$(echo -n "$USER" | md5sum | cut -d' ' -f1)" 309socket="''${XDG_RUNTIME_DIR:-/run/user/$UID}/qutebrowser/ipc-$hash" 310if [[ -S $socket ]]; then 311command= ${ 312escapeShellArg ( builtins . toJSON { 313args = [ ":config-source" ]; 314target_arg = null ; 315protocol_version = 1 ; 316}) 317} 318echo "$command" | ${ pkgs . socat } /bin/socat -lf /dev/null - UNIX-CONNECT:"$socket" 319fi 320unset hash socket command 321'' ; 322}; 323 324xdg . configFile . "qutebrowser/quickmarks" = 325mkIf ( cfg . quickmarks != { } && pkgs . stdenv . hostPlatform . isLinux ) { 326text = quickmarksFile ; 327}; 328 329home . file . ".qutebrowser/greasemonkey" = 330mkIf ( cfg . greasemonkey != [ ] && pkgs . stdenv . hostPlatform . isDarwin ) { 331source = greasemonkeyDir ; 332}; 333 334xdg . configFile . "qutebrowser/greasemonkey" = 335mkIf ( cfg . greasemonkey != [ ] && pkgs . stdenv . hostPlatform . isLinux ) { 336source = greasemonkeyDir ; 337}; 338}; 339}