From be0e73a308e9c6f778b7dc710ec6c6fe154b8634 Mon Sep 17 00:00:00 2001 From: Ivar <41924494+IvarWithoutBones@users.noreply.github.com> Date: Tue, 15 Jun 2021 18:22:21 +0200 Subject: [PATCH] qutebrowser: add quickmark support (#2059) Closes: https://github.com/nix-community/home-manager/issues/1230 --- modules/programs/qutebrowser.nix | 30 +++++++++++++++ .../modules/programs/qutebrowser/default.nix | 1 + .../programs/qutebrowser/quickmarks.nix | 37 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 tests/modules/programs/qutebrowser/quickmarks.nix diff --git a/modules/programs/qutebrowser.nix b/modules/programs/qutebrowser.nix index cbd6b0eb8..8d4868fbb 100644 --- a/modules/programs/qutebrowser.nix +++ b/modules/programs/qutebrowser.nix @@ -32,6 +32,8 @@ let ''config.bind("${k}", "${escape [ ''"'' ] c}", mode="${m}")''; in concatStringsSep "\n" (mapAttrsToList (formatKeyBinding m) b); + formatQuickmarks = n: s: "${n} ${s}"; + in { options.programs.qutebrowser = { enable = mkEnableOption "qutebrowser"; @@ -251,6 +253,21 @@ in { ''; }; + quickmarks = mkOption { + type = types.attrsOf types.str; + default = { }; + description = '' + Quickmarks to add to qutebrowser's quickmarks file. + Note that when Home Manager manages your quickmarks, you cannot edit them at runtime. + ''; + example = literalExample '' + { + nixpkgs = "https://github.com/NixOS/nixpkgs"; + home-manager = "https://github.com/nix-community/home-manager"; + } + ''; + }; + extraConfig = mkOption { type = types.lines; default = ""; @@ -274,13 +291,26 @@ in { ++ optional (!cfg.enableDefaultBindings) "c.bindings.default = {}" ++ mapAttrsToList formatKeyBindings cfg.keyBindings ++ optional (cfg.extraConfig != "") cfg.extraConfig); + + quickmarksFile = optionals (cfg.quickmarks != { }) concatStringsSep "\n" + ((mapAttrsToList formatQuickmarks cfg.quickmarks)); in mkIf cfg.enable { home.packages = [ cfg.package ]; home.file.".qutebrowser/config.py" = mkIf pkgs.stdenv.hostPlatform.isDarwin { text = qutebrowserConfig; }; + home.file.".qutebrowser/quickmarks" = + mkIf (cfg.quickmarks != { } && pkgs.stdenv.hostPlatform.isDarwin) { + text = quickmarksFile; + }; + xdg.configFile."qutebrowser/config.py" = mkIf pkgs.stdenv.hostPlatform.isLinux { text = qutebrowserConfig; }; + + xdg.configFile."qutebrowser/quickmarks" = + mkIf (cfg.quickmarks != { } && pkgs.stdenv.hostPlatform.isLinux) { + text = quickmarksFile; + }; }; } diff --git a/tests/modules/programs/qutebrowser/default.nix b/tests/modules/programs/qutebrowser/default.nix index 581b4a583..8c23515c0 100644 --- a/tests/modules/programs/qutebrowser/default.nix +++ b/tests/modules/programs/qutebrowser/default.nix @@ -1,4 +1,5 @@ { qutebrowser-settings = ./settings.nix; qutebrowser-keybindings = ./keybindings.nix; + qutebrowser-quickmarks = ./quickmarks.nix; } diff --git a/tests/modules/programs/qutebrowser/quickmarks.nix b/tests/modules/programs/qutebrowser/quickmarks.nix new file mode 100644 index 000000000..30d1856c8 --- /dev/null +++ b/tests/modules/programs/qutebrowser/quickmarks.nix @@ -0,0 +1,37 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.qutebrowser = { + enable = true; + + quickmarks = { + nixpkgs = "https://github.com/NixOS/nixpkgs"; + home-manager = "https://github.com/nix-community/home-manager"; + }; + }; + + nixpkgs.overlays = [ + (self: super: { + qutebrowser = pkgs.writeScriptBin "dummy-qutebrowser" ""; + }) + ]; + + nmt.script = let + quickmarksFile = if pkgs.stdenv.hostPlatform.isDarwin then + ".qutebrowser/quickmarks" + else + ".config/qutebrowser/quickmarks"; + in '' + assertFileContent \ + home-files/${quickmarksFile} \ + ${ + pkgs.writeText "qutebrowser-expected-quickmarks" '' + home-manager https://github.com/nix-community/home-manager + nixpkgs https://github.com/NixOS/nixpkgs'' + } + ''; + }; +}