diff --git a/lib/default.nix b/lib/default.nix index 3d357d7c..d7534078 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -66,6 +66,7 @@ lib.fix ( defaultNullOpts mkCompositeOption mkCompositeOption' + mkLazyLoadOption mkNullOrLua mkNullOrLua' mkNullOrLuaFn diff --git a/lib/options.nix b/lib/options.nix index 02ce903a..822abb8a 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -333,5 +333,113 @@ rec { else example; }; + + mkLazyLoadOption = + { + originalName, + lazyLoadDefaults ? { }, + }: + lib.mkOption { + description = '' + Lazy-load settings for ${originalName}. + ''; + type = + let + triggerType = + with types; + oneOf [ + rawLua + str + (listOf str) + ]; + in + types.submodule { + options = with defaultNullOpts; { + + enable = lib.mkEnableOption '' + lazy-loading for ${originalName} + ''; + + # Spec loading: + enabled = mkStrLuaFnOr types.bool (lazyLoadDefaults.enabledInSpec or null) '' + When false, or if the function returns false, then ${originalName} will not be included in the spec. + + Equivalence: lz.n => enabled; lazy.nvim => enabled + ''; + + priority = mkNullable types.number (lazyLoadDefaults.priority or null) '' + Only useful for start plugins (not lazy-loaded) to force loading certain plugins first. + + Equivalence: lz.n => priority; lazy.nvim => priority + ''; + + # Spec setup + # Actions + beforeAll = mkLuaFn (lazyLoadDefaults.beforeAll or null) '' + Always executed before any plugins are loaded. + + Equivalence: lz.n => beforeAll; lazy.nvim => init + ''; + + before = mkLuaFn (lazyLoadDefaults.before or null) '' + Executed before ${originalName} is loaded. + + Equivalence: lz.n => before; lazy.nvim => None + ''; + + after = mkLuaFn (lazyLoadDefaults.after or null) '' + Executed after ${originalName} is loaded. + + Equivalence: lz.n => after; lazy.nvim => config + ''; + + # Triggers + event = mkNullable triggerType (lazyLoadDefaults.event or null) '' + Lazy-load on event. Events can be specified as `BufEnter` or with a pattern like `BufEnter *.lua` + + Equivalence: lz.n => event; lazy.nvim => event + ''; + + cmd = mkNullable triggerType (lazyLoadDefaults.cmd or null) '' + Lazy-load on command. + + Equivalence: lz.n => cmd; lazy.nvim => cmd + ''; + + ft = mkNullable triggerType (lazyLoadDefaults.ft or null) '' + Lazy-load on filetype. + + Equivalence: lz.n => ft; lazy.nvim => ft + ''; + + keys = + mkNullable (types.listOf lib.nixvim.keymaps.mapOptionSubmodule) (lazyLoadDefaults.keys or null) + '' + Lazy-load on key mapping. Use the same format as `config.keymaps`. + + Equivalence: lz.n => keys; lazy.nvim => keys + ''; + + colorscheme = mkNullable triggerType (lazyLoadDefaults.colorscheme or null) '' + Lazy-load on colorscheme. + + Equivalence: lz.n => colorscheme; lazy.nvim => None + ''; + + extraSettings = mkSettingsOption { + description = '' + Extra settings to pass to the lazy loader backend. + ''; + example = { + dependencies = { + __unkeyed-1 = "nvim-lua/plenary.nvim"; + lazy = true; + }; + }; + }; + }; + }; + default = lazyLoadDefaults; + }; } // removed