From 7cb428520bff36f66f22fc18a83783d4ca141fe7 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 17 Feb 2024 03:19:38 +0300 Subject: [PATCH 1/9] utility/images: add image.nvim --- configuration.nix | 6 +- flake.lock | 17 +++ flake.nix | 5 + lib/types/plugins.nix | 3 + modules/utility/default.nix | 5 +- modules/utility/images/default.nix | 6 + modules/utility/images/hologram/default.nix | 6 + modules/utility/images/image-nvim/config.nix | 27 ++++ modules/utility/images/image-nvim/default.nix | 6 + .../utility/images/image-nvim/image-nvim.nix | 116 ++++++++++++++++++ 10 files changed, 194 insertions(+), 3 deletions(-) create mode 100644 modules/utility/images/default.nix create mode 100644 modules/utility/images/hologram/default.nix create mode 100644 modules/utility/images/image-nvim/config.nix create mode 100644 modules/utility/images/image-nvim/default.nix create mode 100644 modules/utility/images/image-nvim/image-nvim.nix diff --git a/configuration.nix b/configuration.nix index 1875eaa..0be5b58 100644 --- a/configuration.nix +++ b/configuration.nix @@ -178,10 +178,14 @@ inputs: let hop.enable = true; leap.enable = true; }; + + images = { + image-nvim.enable = true; + }; }; vim.notes = { - obsidian.enable = false; # FIXME neovim fails to build if obsidian is enabled + obsidian.enable = false; # FIXME: neovim fails to build if obsidian is enabled orgmode.enable = false; mind-nvim.enable = isMaximal; todo-comments.enable = true; diff --git a/flake.lock b/flake.lock index 01f880d..7ad4c53 100644 --- a/flake.lock +++ b/flake.lock @@ -596,6 +596,22 @@ "type": "github" } }, + "image-nvim": { + "flake": false, + "locked": { + "lastModified": 1707861531, + "narHash": "sha256-mh3J3lW2Co2uA7YJzSGum0ZmpJBP0ZzBWUvJLAI9bHw=", + "owner": "3rd", + "repo": "image.nvim", + "rev": "4c6cb5ad93ee93d8d7b7c84e1eb291cee99f0a0e", + "type": "github" + }, + "original": { + "owner": "3rd", + "repo": "image.nvim", + "type": "github" + } + }, "indent-blankline": { "flake": false, "locked": { @@ -1516,6 +1532,7 @@ "highlight-undo": "highlight-undo", "hop-nvim": "hop-nvim", "icon-picker-nvim": "icon-picker-nvim", + "image-nvim": "image-nvim", "indent-blankline": "indent-blankline", "kommentary": "kommentary", "leap-nvim": "leap-nvim", diff --git a/flake.nix b/flake.nix index a1f1797..25bf39e 100644 --- a/flake.nix +++ b/flake.nix @@ -162,6 +162,11 @@ flake = false; }; + image-nvim = { + url = "github:3rd/image.nvim"; + flake = false; + }; + # Tidal cycles tidalcycles = { url = "github:mitchmindtree/tidalcycles.nix"; diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index f20a914..4db7542 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -98,6 +98,7 @@ with lib; let "vim-dirtytalk" "highlight-undo" "nvim-docs-view" + "image-nvim" ]; # You can either use the name of the plugin or a package. pluginType = with types; @@ -116,11 +117,13 @@ with lib; let type = pluginType; description = "Plugin Package."; }; + after = mkOption { type = listOf str; default = []; description = "Setup this plugin after the following ones."; }; + setup = mkOption { type = lines; default = ""; diff --git a/modules/utility/default.nix b/modules/utility/default.nix index 1fbd60a..a5a8892 100644 --- a/modules/utility/default.nix +++ b/modules/utility/default.nix @@ -1,11 +1,12 @@ -_: { +{ imports = [ ./binds + ./ccc ./gestures ./motion ./telescope - ./ccc ./icon-picker + ./images ./telescope ./diffview ./wakatime diff --git a/modules/utility/images/default.nix b/modules/utility/images/default.nix new file mode 100644 index 0000000..3def81d --- /dev/null +++ b/modules/utility/images/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + #./hologram + ./image-nvim + ]; +} diff --git a/modules/utility/images/hologram/default.nix b/modules/utility/images/hologram/default.nix new file mode 100644 index 0000000..42211c7 --- /dev/null +++ b/modules/utility/images/hologram/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./config.nix + ./hologram.nix + ]; +} diff --git a/modules/utility/images/image-nvim/config.nix b/modules/utility/images/image-nvim/config.nix new file mode 100644 index 0000000..f0d1746 --- /dev/null +++ b/modules/utility/images/image-nvim/config.nix @@ -0,0 +1,27 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib) nvim mkIf attrValues; + + cfg = config.vim.utility.images.image-nvim; +in { + config = mkIf cfg.enable { + vim = { + startPlugins = + [ + "image-nvim" + # TODO: needs luarockss here somehow + ] + ++ (attrValues {inherit (pkgs) luarocks imagemagick;}); + + luaConfigRC.image-nvim = nvim.dag.entryAnywhere '' + require("image").setup( + ${nvim.lua.toLuaObject cfg.setupOpts} + ) + ''; + }; + }; +} diff --git a/modules/utility/images/image-nvim/default.nix b/modules/utility/images/image-nvim/default.nix new file mode 100644 index 0000000..f3cc02e --- /dev/null +++ b/modules/utility/images/image-nvim/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./config.nix + ./image-nvim.nix + ]; +} diff --git a/modules/utility/images/image-nvim/image-nvim.nix b/modules/utility/images/image-nvim/image-nvim.nix new file mode 100644 index 0000000..b8b74b4 --- /dev/null +++ b/modules/utility/images/image-nvim/image-nvim.nix @@ -0,0 +1,116 @@ +{ + config, + lib, + ... +}: let + inherit (lib) mkEnableOption mkOption nvim types; +in { + options.vim.utility.images.image-nvim = { + enable = mkEnableOption "image support in Neovim [image.nvim]"; + + setupOpts = nvim.types.mkPluginSetupOption "image.nvim" { + backend = mkOption { + type = types.enum ["kitty" "ueberzug"]; + default = "ueberzug"; + description = '' + The backend to use for rendering images. + + - kitty - best in class, works great and is very snappy + - ueberzug - backed by ueberzugpp, supports any terminal, + but has lower performance + ''; + }; + + integrations = { + markdown = { + enable = mkEnableOption " image.nvim in markdown files" // {default = true;}; + clearInInsertMode = mkEnableOption "clearing of images when entering insert mode"; + downloadRemoteImages = mkEnableOption "downloading remote images"; + onlyRenderAtCursor = mkEnableOption "only rendering images at cursor"; + filetypes = mkOption { + type = with types; listOf str; + default = ["markdown" "vimwiki"]; + description = '' + Filetypes to enable image.nvim in. Markdown extensions + (i.e. quarto) can go here + ''; + }; + }; + + neorg = { + enable = mkEnableOption "image.nvim in Neorg files" // {default = true;}; + clearInInsertMode = mkEnableOption "clearing of images when entering insert mode"; + downloadRemoteImages = mkEnableOption "downloading remote images"; + onlyRenderAtCursor = mkEnableOption "only rendering images at cursor"; + filetypes = mkOption { + type = with types; listOf str; + default = ["neorg"]; + description = '' + Filetypes to enable image.nvim in. + ''; + }; + }; + + maxWidth = mkOption { + type = with types; nullOr int; + default = null; + description = '' + The maximum width of images to render. Images larger than + this will be scaled down to fit within this width. + ''; + }; + + maxHeight = mkOption { + type = with types; nullOr int; + default = null; + description = '' + The maximum height of images to render. Images larger than + this will be scaled down to fit within this height. + ''; + }; + + maxWidthWindowPercentage = mkOption { + type = with types; nullOr int; + default = null; + description = '' + The maximum width of images to render as a percentage of the + window width. Images larger than this will be scaled down to + fit within this width. + ''; + }; + + maxHeightWindowPercentage = mkOption { + type = with types; nullOr int; + default = 50; + description = '' + The maximum height of images to render as a percentage of the + window height. Images larger than this will be scaled down to + fit within this height. + ''; + }; + + windowOverlapClear = { + enable = mkEnableOption "clearing of images when they overlap with the window"; + ftIgnore = mkOption { + type = with types; listOf str; + default = ["cmp_menu" "cmp_docs" ""]; + description = '' + Filetypes to ignore window overlap clearing in. + ''; + }; + }; + + editorOnlyRenderWhenFocused = mkEnableOption "only rendering images when the editor is focused"; + hijackFilePatterns = mkOption { + type = with types; listOf str; + default = ["*.png" "*.jpg" "*.jpeg" "*.gif" "*.webp"]; + description = '' + File patterns to hijack for image.nvim. This is useful for + filetypes that don't have a dedicated integration. + ''; + }; + }; + }; + }; +} + From d7878b525c52b9faa5b2cc33638e7078aa4f4729 Mon Sep 17 00:00:00 2001 From: Frothy <76622149+FrothyMarrow@users.noreply.github.com> Date: Sat, 17 Feb 2024 17:06:05 -0500 Subject: [PATCH 2/9] utility/images: add magick to lua packages --- modules/utility/images/image-nvim/config.nix | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/utility/images/image-nvim/config.nix b/modules/utility/images/image-nvim/config.nix index f0d1746..eca14a8 100644 --- a/modules/utility/images/image-nvim/config.nix +++ b/modules/utility/images/image-nvim/config.nix @@ -10,12 +10,13 @@ in { config = mkIf cfg.enable { vim = { - startPlugins = - [ - "image-nvim" - # TODO: needs luarockss here somehow - ] - ++ (attrValues {inherit (pkgs) luarocks imagemagick;}); + startPlugins = [ + "image-nvim" + ]; + + luaPackages = [ + "magick" + ]; luaConfigRC.image-nvim = nvim.dag.entryAnywhere '' require("image").setup( From a6b133124d2ea4e14e8267c4978d66d8f1d88eae Mon Sep 17 00:00:00 2001 From: Frothy <76622149+FrothyMarrow@users.noreply.github.com> Date: Sat, 17 Feb 2024 17:11:58 -0500 Subject: [PATCH 3/9] utility/images: fix unrelated options being part of 'integrations' --- .../utility/images/image-nvim/image-nvim.nix | 85 +++++++++---------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/modules/utility/images/image-nvim/image-nvim.nix b/modules/utility/images/image-nvim/image-nvim.nix index b8b74b4..5e89b8d 100644 --- a/modules/utility/images/image-nvim/image-nvim.nix +++ b/modules/utility/images/image-nvim/image-nvim.nix @@ -59,58 +59,57 @@ in { this will be scaled down to fit within this width. ''; }; + }; - maxHeight = mkOption { - type = with types; nullOr int; - default = null; - description = '' - The maximum height of images to render. Images larger than - this will be scaled down to fit within this height. - ''; - }; + maxHeight = mkOption { + type = with types; nullOr int; + default = null; + description = '' + The maximum height of images to render. Images larger than + this will be scaled down to fit within this height. + ''; + }; - maxWidthWindowPercentage = mkOption { - type = with types; nullOr int; - default = null; - description = '' - The maximum width of images to render as a percentage of the - window width. Images larger than this will be scaled down to - fit within this width. - ''; - }; + maxWidthWindowPercentage = mkOption { + type = with types; nullOr int; + default = null; + description = '' + The maximum width of images to render as a percentage of the + window width. Images larger than this will be scaled down to + fit within this width. + ''; + }; - maxHeightWindowPercentage = mkOption { - type = with types; nullOr int; - default = 50; - description = '' - The maximum height of images to render as a percentage of the - window height. Images larger than this will be scaled down to - fit within this height. - ''; - }; + maxHeightWindowPercentage = mkOption { + type = with types; nullOr int; + default = 50; + description = '' + The maximum height of images to render as a percentage of the + window height. Images larger than this will be scaled down to + fit within this height. + ''; + }; - windowOverlapClear = { - enable = mkEnableOption "clearing of images when they overlap with the window"; - ftIgnore = mkOption { - type = with types; listOf str; - default = ["cmp_menu" "cmp_docs" ""]; - description = '' - Filetypes to ignore window overlap clearing in. - ''; - }; - }; - - editorOnlyRenderWhenFocused = mkEnableOption "only rendering images when the editor is focused"; - hijackFilePatterns = mkOption { + windowOverlapClear = { + enable = mkEnableOption "clearing of images when they overlap with the window"; + ftIgnore = mkOption { type = with types; listOf str; - default = ["*.png" "*.jpg" "*.jpeg" "*.gif" "*.webp"]; + default = ["cmp_menu" "cmp_docs" ""]; description = '' - File patterns to hijack for image.nvim. This is useful for - filetypes that don't have a dedicated integration. + Filetypes to ignore window overlap clearing in. ''; }; }; + + editorOnlyRenderWhenFocused = mkEnableOption "only rendering images when the editor is focused"; + hijackFilePatterns = mkOption { + type = with types; listOf str; + default = ["*.png" "*.jpg" "*.jpeg" "*.gif" "*.webp"]; + description = '' + File patterns to hijack for image.nvim. This is useful for + filetypes that don't have a dedicated integration. + ''; + }; }; }; } - From d2af30545d8dec4fc47631fddb145d5f06a45869 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 26 Feb 2024 11:54:07 +0300 Subject: [PATCH 4/9] =?UTF-8?q?utility/images:=20remote=20hologram.nvi?= =?UTF-8?q?=C3=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit image.nvim has better coverage --- modules/utility/images/default.nix | 2 +- modules/utility/images/hologram/default.nix | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 modules/utility/images/hologram/default.nix diff --git a/modules/utility/images/default.nix b/modules/utility/images/default.nix index 3def81d..de0a1f7 100644 --- a/modules/utility/images/default.nix +++ b/modules/utility/images/default.nix @@ -1,6 +1,6 @@ { imports = [ - #./hologram + ./hologram ./image-nvim ]; } diff --git a/modules/utility/images/hologram/default.nix b/modules/utility/images/hologram/default.nix deleted file mode 100644 index 42211c7..0000000 --- a/modules/utility/images/hologram/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - imports = [ - ./config.nix - ./hologram.nix - ]; -} From 30fb2e4f28b7be56165251d6f9a061d3143ba108 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 26 Feb 2024 11:54:20 +0300 Subject: [PATCH 5/9] images/image-nvim: make lib calls more explicit --- modules/utility/images/image-nvim/config.nix | 9 ++++--- .../utility/images/image-nvim/image-nvim.nix | 25 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/utility/images/image-nvim/config.nix b/modules/utility/images/image-nvim/config.nix index eca14a8..52666d3 100644 --- a/modules/utility/images/image-nvim/config.nix +++ b/modules/utility/images/image-nvim/config.nix @@ -1,10 +1,11 @@ { config, - pkgs, lib, ... }: let - inherit (lib) nvim mkIf attrValues; + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.utility.images.image-nvim; in { @@ -18,9 +19,9 @@ in { "magick" ]; - luaConfigRC.image-nvim = nvim.dag.entryAnywhere '' + luaConfigRC.image-nvim = entryAnywhere '' require("image").setup( - ${nvim.lua.toLuaObject cfg.setupOpts} + ${toLuaObject cfg.setupOpts} ) ''; }; diff --git a/modules/utility/images/image-nvim/image-nvim.nix b/modules/utility/images/image-nvim/image-nvim.nix index 5e89b8d..e208968 100644 --- a/modules/utility/images/image-nvim/image-nvim.nix +++ b/modules/utility/images/image-nvim/image-nvim.nix @@ -3,14 +3,17 @@ lib, ... }: let - inherit (lib) mkEnableOption mkOption nvim types; + inherit (lib.options) mkEnableOption mkOption; + + inherit (lib.types) enum listOf str nullOr int; + inherit (lib.nvim.lua) mkPluginSetupOption; in { options.vim.utility.images.image-nvim = { enable = mkEnableOption "image support in Neovim [image.nvim]"; - setupOpts = nvim.types.mkPluginSetupOption "image.nvim" { + setupOpts = mkPluginSetupOption "image.nvim" { backend = mkOption { - type = types.enum ["kitty" "ueberzug"]; + type = enum ["kitty" "ueberzug"]; default = "ueberzug"; description = '' The backend to use for rendering images. @@ -28,7 +31,7 @@ in { downloadRemoteImages = mkEnableOption "downloading remote images"; onlyRenderAtCursor = mkEnableOption "only rendering images at cursor"; filetypes = mkOption { - type = with types; listOf str; + type = listOf str; default = ["markdown" "vimwiki"]; description = '' Filetypes to enable image.nvim in. Markdown extensions @@ -43,7 +46,7 @@ in { downloadRemoteImages = mkEnableOption "downloading remote images"; onlyRenderAtCursor = mkEnableOption "only rendering images at cursor"; filetypes = mkOption { - type = with types; listOf str; + type = listOf str; default = ["neorg"]; description = '' Filetypes to enable image.nvim in. @@ -52,7 +55,7 @@ in { }; maxWidth = mkOption { - type = with types; nullOr int; + type = nullOr int; default = null; description = '' The maximum width of images to render. Images larger than @@ -62,7 +65,7 @@ in { }; maxHeight = mkOption { - type = with types; nullOr int; + type = nullOr int; default = null; description = '' The maximum height of images to render. Images larger than @@ -71,7 +74,7 @@ in { }; maxWidthWindowPercentage = mkOption { - type = with types; nullOr int; + type = nullOr int; default = null; description = '' The maximum width of images to render as a percentage of the @@ -81,7 +84,7 @@ in { }; maxHeightWindowPercentage = mkOption { - type = with types; nullOr int; + type = nullOr int; default = 50; description = '' The maximum height of images to render as a percentage of the @@ -93,7 +96,7 @@ in { windowOverlapClear = { enable = mkEnableOption "clearing of images when they overlap with the window"; ftIgnore = mkOption { - type = with types; listOf str; + type = listOf str; default = ["cmp_menu" "cmp_docs" ""]; description = '' Filetypes to ignore window overlap clearing in. @@ -103,7 +106,7 @@ in { editorOnlyRenderWhenFocused = mkEnableOption "only rendering images when the editor is focused"; hijackFilePatterns = mkOption { - type = with types; listOf str; + type = listOf str; default = ["*.png" "*.jpg" "*.jpeg" "*.gif" "*.webp"]; description = '' File patterns to hijack for image.nvim. This is useful for From b6166f298d237092d975fa806515a2de6e0f0d77 Mon Sep 17 00:00:00 2001 From: Frothy <76622149+FrothyMarrow@users.noreply.github.com> Date: Mon, 26 Feb 2024 06:42:04 -0500 Subject: [PATCH 6/9] utility/images: remove import for non existing hologram module --- modules/utility/images/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/utility/images/default.nix b/modules/utility/images/default.nix index de0a1f7..5b876e0 100644 --- a/modules/utility/images/default.nix +++ b/modules/utility/images/default.nix @@ -1,6 +1,5 @@ { imports = [ - ./hologram ./image-nvim ]; } From 2d16435392991951986065b407dd634e66eef764 Mon Sep 17 00:00:00 2001 From: Frothy <76622149+FrothyMarrow@users.noreply.github.com> Date: Mon, 26 Feb 2024 06:43:20 -0500 Subject: [PATCH 7/9] utility/images/image-nvim: fix inherit for `mkPluginSetupOption` --- modules/utility/images/image-nvim/image-nvim.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/utility/images/image-nvim/image-nvim.nix b/modules/utility/images/image-nvim/image-nvim.nix index e208968..6433e50 100644 --- a/modules/utility/images/image-nvim/image-nvim.nix +++ b/modules/utility/images/image-nvim/image-nvim.nix @@ -6,7 +6,7 @@ inherit (lib.options) mkEnableOption mkOption; inherit (lib.types) enum listOf str nullOr int; - inherit (lib.nvim.lua) mkPluginSetupOption; + inherit (lib.nvim.types) mkPluginSetupOption; in { options.vim.utility.images.image-nvim = { enable = mkEnableOption "image support in Neovim [image.nvim]"; From a32f13b63677b01b5e3d6180f1afd8adda6f312b Mon Sep 17 00:00:00 2001 From: Frothy <76622149+FrothyMarrow@users.noreply.github.com> Date: Mon, 26 Feb 2024 06:51:55 -0500 Subject: [PATCH 8/9] lib: fix trying to call an attrset --- lib/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/default.nix b/lib/default.nix index 0e0b73f..94db90b 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -5,5 +5,5 @@ dag = import ./dag.nix {inherit lib;}; languages = import ./languages.nix {inherit lib;}; lua = import ./lua.nix {inherit lib;}; - vim = import ./vim.nix {inherit lib;}; + vim = import ./vim.nix; } From 38ca1f98a22cfb3067e347ebbf875ba87913635b Mon Sep 17 00:00:00 2001 From: Frothy <76622149+FrothyMarrow@users.noreply.github.com> Date: Mon, 26 Feb 2024 07:31:30 -0500 Subject: [PATCH 9/9] utility/images/image-nvim: add assertion for `ueberzug` backend on darwin --- configuration.nix | 2 +- modules/utility/images/image-nvim/config.nix | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/configuration.nix b/configuration.nix index 0be5b58..8420bbf 100644 --- a/configuration.nix +++ b/configuration.nix @@ -180,7 +180,7 @@ inputs: let }; images = { - image-nvim.enable = true; + image-nvim.enable = false; }; }; diff --git a/modules/utility/images/image-nvim/config.nix b/modules/utility/images/image-nvim/config.nix index 52666d3..49ca3e5 100644 --- a/modules/utility/images/image-nvim/config.nix +++ b/modules/utility/images/image-nvim/config.nix @@ -1,6 +1,7 @@ { config, lib, + pkgs, ... }: let inherit (lib.modules) mkIf; @@ -10,6 +11,13 @@ cfg = config.vim.utility.images.image-nvim; in { config = mkIf cfg.enable { + assertions = [ + { + assertion = pkgs.stdenv.isDarwin && cfg.setupOpts.backend != "ueberzug"; + message = "image-nvim: ueberzug backend is broken on ${pkgs.stdenv.hostPlatform.system}. if you are using kitty, please set `vim.utility.images.image-nvim.setupOpts.backend` option to `kitty` in your configuration, otherwise disable this module."; + } + ]; + vim = { startPlugins = [ "image-nvim"