diff --git a/modules/notes/obsidian/config.nix b/modules/notes/obsidian/config.nix index 818d447..5ba005e 100644 --- a/modules/notes/obsidian/config.nix +++ b/modules/notes/obsidian/config.nix @@ -6,9 +6,9 @@ inherit (lib.modules) mkIf; inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.binds) pushDownDefault; + inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.notes.obsidian; - auto = config.vim.autocomplete; in { config = mkIf cfg.enable { vim = { @@ -23,28 +23,7 @@ in { }; luaConfigRC.obsidian = entryAnywhere '' - require("obsidian").setup({ - dir = "${cfg.dir}", - completion = { - nvim_cmp = ${ - if (auto.type == "nvim-cmp") - then "true" - else "false" - } - }, - daily_notes = { - folder = ${ - if (cfg.daily-notes.folder == "") - then "nil," - else "'${cfg.daily-notes.folder}'," - } - date_format = ${ - if (cfg.daily-notes.date-format == "") - then "nil," - else "'${cfg.daily-notes.date-format}'," - } - } - }) + require("obsidian").setup(${toLuaObject cfg.setupOpts}) ''; }; }; diff --git a/modules/notes/obsidian/obsidian.nix b/modules/notes/obsidian/obsidian.nix index 1b7bae6..c7152fb 100644 --- a/modules/notes/obsidian/obsidian.nix +++ b/modules/notes/obsidian/obsidian.nix @@ -1,33 +1,52 @@ -{lib, ...}: let - inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) str bool; +{ + config, + lib, + ... +}: let + inherit (lib) mkEnableOption mkOption types mkRenamedOptionModule; in { + imports = let + renamedSetupOption = oldPath: newPath: + mkRenamedOptionModule + (["vim" "notes" "obsidian"] ++ oldPath) + (["vim" "notes" "obsidian" "setupOpts"] ++ newPath); + in [ + (renamedSetupOption ["dir"] ["dir"]) + (renamedSetupOption ["daily-notes" "folder"] ["daily_notes" "folder"]) + (renamedSetupOption ["daily-notes" "date-format"] ["daily_notes" "date_format"]) + (renamedSetupOption ["completion"] ["completion"]) + ]; options.vim.notes = { obsidian = { enable = mkEnableOption "complementary neovim plugins for Obsidian editor"; - dir = mkOption { - type = str; - default = "~/my-vault"; - description = "Obsidian vault directory"; - }; - daily-notes = { - folder = mkOption { - type = str; - default = ""; - description = "Directory in which daily notes should be created"; + setupOpts = lib.nvim.types.mkPluginSetupOption "Obsidian.nvim" { + dir = mkOption { + type = types.str; + default = "~/my-vault"; + description = "Obsidian vault directory"; }; - date-format = mkOption { - type = str; - default = ""; - description = "Date format used for creating daily notes"; - }; - }; - completion = { - nvim_cmp = mkOption { - type = bool; - description = "If using nvim-cmp, otherwise set to false"; + daily_notes = { + folder = mkOption { + type = types.nullOr types.str; + default = null; + description = "Directory in which daily notes should be created"; + }; + date_format = mkOption { + type = types.nullOr types.str; + default = null; + description = "Date format used for creating daily notes"; + }; + }; + + completion = { + nvim_cmp = mkOption { + # if using nvim-cmp, otherwise set to false + type = types.bool; + description = "If using nvim-cmp, otherwise set to false"; + default = config.vim.autocomplete.type == "nvim-cmp"; + }; }; }; };