From 73e8649b202e4d250f3d856db3f5e2fed1f7bf8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Lepage?= <33058747+GaetanLepage@users.noreply.github.com> Date: Mon, 24 Apr 2023 10:38:57 +0200 Subject: [PATCH] modules/clipboard: add new module to manage clipboard option and provider (#346) --- modules/clipboard.nix | 56 ++++++++++++++++++++++++ tests/test-sources/modules/clipboard.nix | 17 +++++++ 2 files changed, 73 insertions(+) create mode 100644 modules/clipboard.nix create mode 100644 tests/test-sources/modules/clipboard.nix diff --git a/modules/clipboard.nix b/modules/clipboard.nix new file mode 100644 index 00000000..f3eae39f --- /dev/null +++ b/modules/clipboard.nix @@ -0,0 +1,56 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; let + cfg = config.clipboard; +in { + options = { + clipboard = { + register = mkOption { + description = '' + Sets the register to use for the clipboard. + Learn more at https://neovim.io/doc/user/options.html#'clipboard'. + ''; + type = with types; + nullOr + (either str (listOf str)); + default = null; + example = "unnamedplus"; + }; + + providers = mkOption { + type = types.submodule { + options = + mapAttrs + ( + name: packageName: { + enable = mkEnableOption name; + package = mkPackageOption pkgs packageName {}; + } + ) + { + xclip = "xclip"; + xsel = "xsel"; + }; + }; + default = {}; + description = '' + Package(s) to use as the clipboard provider. + Learn more at `:h clipboard`. + ''; + }; + }; + }; + + config = { + options.clipboard = mkIf (!isNull cfg.register) cfg.register; + + extraPackages = + mapAttrsToList + (n: v: v.package) + (filterAttrs (n: v: v.enable) cfg.providers); + }; +} diff --git a/tests/test-sources/modules/clipboard.nix b/tests/test-sources/modules/clipboard.nix new file mode 100644 index 00000000..e88a837e --- /dev/null +++ b/tests/test-sources/modules/clipboard.nix @@ -0,0 +1,17 @@ +{pkgs}: { + example-with-str = { + clipboard = { + register = "unnamed"; + + providers.xclip.enable = true; + }; + }; + + example-with-package = { + clipboard = { + register = ["unnamed" "unnamedplus"]; + + providers.xsel.enable = true; + }; + }; +}