Compare commits

...

36 commits

Author SHA1 Message Date
Ching Pei Yang
d14c5e57db
nixos: use attrset for long function args 2024-12-30 12:10:35 +01:00
Ching Pei Yang
6daec44f40
home-manager: use attr for long function args 2024-12-30 12:10:34 +01:00
Ching Pei Yang
835b775fa9
nixos: remove redundant import module 2024-12-30 12:10:34 +01:00
Ching Pei Yang
fb96ccb85b
home-manager: remove redundant import module 2024-12-30 12:10:34 +01:00
Ching Pei Yang
27f3430296
lib: remove anythingConcatLists 2024-12-30 12:10:34 +01:00
Ching Pei Yang
f8780947b7
nixos: use proper submodule type for settings 2024-12-30 12:07:54 +01:00
Ching Pei Yang
e9cc77dff7
module: remove redundant code
the bulk of the build step is moved to modules/wrapper/build
2024-12-30 12:07:53 +01:00
Ching Pei Yang
dc5551b050
home-manager: use proper submodule type for settings 2024-12-30 12:07:53 +01:00
Ching Pei Yang
2217565730
wrapper: add built package as option 2024-12-30 12:07:53 +01:00
Ching Pei Yang
4e867c5425
wrapper: rename build dir to environemnt 2024-12-30 12:07:53 +01:00
raf
ba3173d363
Merge pull request #515 from diniamo/update-run
flake: update run.nvim
2024-12-30 12:05:52 +03:00
diniamo
c3b51df4a6 flake: update run.nvim 2024-12-30 09:49:33 +01:00
raf
b6a49b299a
Merge pull request #514 from diniamo/update-mnw
flake: update mnw
2024-12-26 10:34:41 +03:00
diniamo
74e48b519d flake: update mnw 2024-12-26 08:06:13 +01:00
raf
aa1754d5cc
Merge pull request #513 from diniamo/update-run
flake: update run.nvim
2024-12-25 18:19:36 +03:00
diniamo
672630f680 flake: update run.nvim 2024-12-25 15:11:29 +01:00
raf
7dd2026b9d
Merge pull request #512 from diniamo/nvim-notify-explicit-function
nvim-notify: use explicit function for vim.notify
2024-12-25 00:52:53 +03:00
raf
edc887f0e3
Merge branch 'main' into nvim-notify-explicit-function 2024-12-25 00:51:18 +03:00
diniamo
a34d104e3f
languages/zig: disable lsp autosave (#511) 2024-12-24 14:19:08 +03:00
diniamo
f6a8cd968e nvim-notify: use explicit function for vim.notify 2024-12-24 11:43:23 +01:00
DamitusThyYeetus123
3a2edd1b75
filetree/nvim-tree: Open on directory (#462)
* nvim-tree: Add directory opening

* formatting

* Fix formatting

* format

Co-authored-by: raf <raf@notashelf.dev>

---------

Co-authored-by: Ching Pei Yang <59727193+horriblename@users.noreply.github.com>
Co-authored-by: raf <raf@notashelf.dev>
2024-12-23 08:56:19 +00:00
raf
46aa168b2d
Merge pull request #509 from diniamo/update-run
flake: update run.nvim
2024-12-22 00:33:24 +03:00
diniamo
9aad80d5e6 flake: update run.nvim 2024-12-21 22:31:41 +01:00
raf
ac905b8aed
Merge pull request #505 from diniamo/odin
languages/odin: init
2024-12-21 12:41:16 +03:00
diniamo
90a5a42742 languages/odin: init 2024-12-21 10:35:39 +01:00
raf
8bab0497fb
Merge pull request #500 from diniamo/lazy-before-setup
wrapper/lazy: add beforeSetup option
2024-12-21 08:17:41 +03:00
raf
f26744c6ce
Merge branch 'main' into lazy-before-setup 2024-12-21 08:15:08 +03:00
raf
62d296a2dc
Merge pull request #506 from amadaluzia/fix-haskell
languages/haskell: fix DAP command definition
2024-12-21 08:14:43 +03:00
raf
8c66f10550
Merge branch 'main' into fix-haskell 2024-12-21 08:14:31 +03:00
raf
ea3d488cf4
Merge pull request #504 from diniamo/surround-cleanup
surround: cleanup
2024-12-21 08:14:14 +03:00
Artur Manuel
0946d43921 languages/haskell: fix DAP command definition 2024-12-21 01:00:02 +00:00
diniamo
7eb8d07bcf surround: cleanup 2024-12-21 01:14:52 +01:00
raf
52042f624c
Merge pull request #498 from NotAShelf/fix-mdpw-ft
preview/markdown-preview: convert `mkdp_filetypes` to correct format
2024-12-20 20:01:21 +03:00
raf
af31021ce4
Merge branch 'main' into fix-mdpw-ft 2024-12-20 20:00:57 +03:00
diniamo
ed69816f68 wrapper/lazy: add beforeSetup option
Useful for avoiding a million require calls in setupOpts.
2024-12-20 10:43:36 +01:00
4f61628399
preview/markdown-preview: convert mkdp_filetypes to correct format 2024-12-19 09:53:15 +03:00
26 changed files with 462 additions and 376 deletions

View file

@ -13,4 +13,11 @@
[haskell-tools.nvim]: https://github.com/MrcJkb/haskell-tools.nvim
- Add Haskell support under `vim.languages.haskell` using [haskell-tools.nvim]
- Add Haskell support under `vim.languages.haskell` using [haskell-tools.nvim].
[diniamo](https://github.com/diniamo):
- Add Odin support under `vim.languages.odin`.
- Disable the built-in format-on-save feature of zls. Use `vim.lsp.formatOnSave`
instead.

View file

@ -38,11 +38,11 @@
},
"mnw": {
"locked": {
"lastModified": 1731821965,
"narHash": "sha256-QiGi/HBQRnIRGY4gQPuH7T3hr7NznOpEO7qNpF5ldmE=",
"lastModified": 1735150973,
"narHash": "sha256-OJhcCAoaMMXeD6o4qI/hxBCNELJp4dN8D5LJZc8w8XA=",
"owner": "Gerg-L",
"repo": "mnw",
"rev": "5fe5c41975ed0af55f55dc37cd28ba906a5d015e",
"rev": "40cd0b006cc48dffd0f8698ad7f54cf1d56779a6",
"type": "github"
},
"original": {
@ -1729,11 +1729,11 @@
"plugin-run-nvim": {
"flake": false,
"locked": {
"lastModified": 1732918526,
"narHash": "sha256-kiszNmZZDXG8tAPMQKuGJDCkqCMzsWT7BkCvkVsH2lA=",
"lastModified": 1735501787,
"narHash": "sha256-CFOyOARCLQiMOhFPeqz8n2ULyaaRxRZrOk0FCibjuIM=",
"owner": "diniamo",
"repo": "run.nvim",
"rev": "d867466e01b8fa4e54a589b9ef446cf43fb966de",
"rev": "9015c9cece816ccf10a185b420f6e345fd990802",
"type": "github"
},
"original": {

View file

@ -31,7 +31,7 @@
};
homeManagerModules = {
nvf = import ./flake/modules/home-manager.nix self.packages lib;
nvf = import ./flake/modules/home-manager.nix {inherit lib self;};
default = self.homeManagerModules.nvf;
neovim-flake =
lib.warn ''
@ -42,7 +42,7 @@
};
nixosModules = {
nvf = import ./flake/modules/nixos.nix self.packages lib;
nvf = import ./flake/modules/nixos.nix {inherit lib self;};
default = self.nixosModules.nvf;
neovim-flake =
lib.warn ''

View file

@ -1,22 +1,28 @@
# Home Manager module
packages: lib: {
{
self,
lib,
}: {
config,
pkgs,
...
}: let
inherit (self) packages inputs;
inherit (lib) maintainers;
inherit (lib.modules) mkIf mkAliasOptionModule;
inherit (lib.lists) optional;
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) attrsOf anything bool;
inherit (lib.nvim) neovimConfiguration;
inherit (lib.nvim.types) anythingConcatLists;
inherit (lib.types) anything bool submoduleWith;
cfg = config.programs.nvf;
neovimConfigured = neovimConfiguration {
inherit pkgs;
modules = [cfg.settings];
nvfModule = submoduleWith {
description = "Nvf module";
class = "nvf";
specialArgs = {
inherit pkgs lib inputs;
};
modules = import ../../modules/modules.nix {inherit pkgs lib;};
};
in {
imports = [
@ -55,7 +61,7 @@ in {
};
settings = mkOption {
type = attrsOf anythingConcatLists;
type = nvfModule;
default = {};
description = "Attribute set of nvf preferences.";
example = literalExpression ''
@ -78,7 +84,7 @@ in {
};
config = mkIf cfg.enable {
programs.nvf.finalPackage = neovimConfigured.neovim;
programs.nvf.finalPackage = cfg.settings.vim.build.finalPackage;
home = {
sessionVariables = mkIf cfg.defaultEditor {EDITOR = "nvim";};

View file

@ -1,22 +1,28 @@
# NixOS module
packages: lib: {
{
self,
lib,
}: {
config,
pkgs,
...
}: let
inherit (self) inputs packages;
inherit (lib) maintainers;
inherit (lib.modules) mkIf mkOverride mkAliasOptionModule;
inherit (lib.lists) optional;
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) attrsOf anything bool;
inherit (lib.nvim) neovimConfiguration;
inherit (lib.nvim.types) anythingConcatLists;
inherit (lib.types) anything bool submoduleWith;
cfg = config.programs.nvf;
neovimConfigured = neovimConfiguration {
inherit pkgs;
modules = [cfg.settings];
nvfModule = submoduleWith {
description = "Nvf module";
class = "nvf";
specialArgs = {
inherit pkgs lib inputs;
};
modules = import ../../modules/modules.nix {inherit pkgs lib;};
};
in {
imports = [
@ -55,7 +61,7 @@ in {
};
settings = mkOption {
type = attrsOf anythingConcatLists;
type = nvfModule;
default = {};
description = "Attribute set of nvf preferences.";
example = literalExpression ''
@ -78,7 +84,7 @@ in {
};
config = mkIf cfg.enable {
programs.nvf.finalPackage = neovimConfigured.neovim;
programs.nvf.finalPackage = cfg.settings.vim.build.finalPackage;
environment = {
variables.EDITOR = mkIf cfg.defaultEditor (mkOverride 900 "nvim");

View file

@ -1,57 +1,8 @@
{lib}: let
inherit (lib.options) showOption showFiles getFiles mergeOneOption mergeEqualOption;
inherit (lib.strings) isString isStringLike;
inherit (lib.types) anything attrsOf listOf mkOptionType;
inherit (lib.nvim.types) anythingConcatLists;
inherit (builtins) typeOf isAttrs any head concatLists stringLength match;
inherit (lib.options) mergeEqualOption;
inherit (lib.strings) isString stringLength match;
inherit (lib.types) listOf mkOptionType;
in {
# HACK: Does this break anything in our case?
# A modified version of the nixpkgs anything type that concatenates lists
# This isn't the default because the order in which the lists are concatenated depends on the order in which the modules are imported,
# which makes it non-deterministic
anythingConcatLists =
anything
// {
merge = loc: defs: let
getType = value:
if isAttrs value && isStringLike value
then "stringCoercibleSet"
else typeOf value;
# Throw an error if not all defs have the same type
checkType = getType (head defs).value;
commonType =
if any (def: getType def.value != checkType) defs
then throw "The option `${showOption loc}' has conflicting option types in ${showFiles (getFiles defs)}"
else checkType;
mergeFunctions = {
# Recursively merge attribute sets
set = (attrsOf anythingConcatLists).merge;
# Overridden behavior for lists, that concatenates lists
list = _: defs: concatLists (map (e: e.value) defs);
# This means it's a package, only accept a single definition
stringCoercibleSet = mergeOneOption;
# This works by passing the argument to the functions,
# and merging their returns values instead
lambda = loc: defs: arg:
anythingConcatLists.merge
(loc ++ ["<function body>"])
(map (def: {
inherit (def) file;
value = def.value arg;
})
defs);
};
in
# Merge the defs with the correct function from above, if available
# otherwise only allow equal values
(mergeFunctions.${commonType} or mergeEqualOption) loc defs;
};
mergelessListOf = elemType: let
super = listOf elemType;
in

View file

@ -11,5 +11,5 @@ in {
inherit (typesDag) dagOf;
inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType;
inherit (typesLanguage) diagnostics mkGrammarOption;
inherit (customTypes) anythingConcatLists char hexColor mergelessListOf;
inherit (customTypes) char hexColor mergelessListOf;
}

View file

@ -9,9 +9,8 @@
extraModules ? [],
configuration ? {},
}: let
inherit (pkgs) vimPlugins;
inherit (lib.strings) isString toString;
inherit (lib.lists) filter map concatLists;
inherit (lib.strings) toString;
inherit (lib.lists) concatLists;
# import modules.nix with `check`, `pkgs` and `lib` as arguments
# check can be disabled while calling this file is called
@ -21,7 +20,12 @@
# evaluate the extended library with the modules
# optionally with any additional modules passed by the user
module = lib.evalModules {
specialArgs = extraSpecialArgs // {modulesPath = toString ./.;};
specialArgs =
extraSpecialArgs
// {
inherit inputs;
modulesPath = toString ./.;
};
modules = concatLists [
nvimModules
modules
@ -36,102 +40,11 @@
extraModules))
];
};
# alias to the internal configuration
vimOptions = module.config.vim;
noBuildPlug = {pname, ...} @ attrs: let
src = inputs."plugin-${attrs.pname}";
in
{
version = src.shortRev or src.shortDirtyRev or "dirty";
outPath = src;
passthru.vimPlugin = false;
}
// attrs;
# build a vim plugin with the given name and arguments
# if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug
# instead
buildPlug = attrs: let
src = inputs."plugin-${attrs.pname}";
in
pkgs.vimUtils.buildVimPlugin (
{
version = src.shortRev or src.shortDirtyRev or "dirty";
inherit src;
}
// attrs
);
buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars);
pluginBuilders = {
nvim-treesitter = buildTreesitterPlug vimOptions.treesitter.grammars;
flutter-tools-patched = buildPlug {
pname = "flutter-tools";
patches = [../patches/flutter-tools.patch];
};
};
buildConfigPlugins = plugins:
map (
plug:
if (isString plug)
then pluginBuilders.${plug} or (noBuildPlug {pname = plug;})
else plug
) (filter (f: f != null) plugins);
# built (or "normalized") plugins that are modified
builtStartPlugins = buildConfigPlugins vimOptions.startPlugins;
builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins);
# additional Lua and Python3 packages, mapped to their respective functions
# to conform to the format mnw expects. end user should
# only ever need to pass a list of packages, which are modified
# here
extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages;
extraPython3Packages = ps: map (x: ps.${x}) vimOptions.python3Packages;
# Wrap the user's desired (unwrapped) Neovim package with arguments that'll be used to
# generate a wrapped Neovim package.
neovim-wrapped = inputs.mnw.lib.wrap pkgs {
neovim = vimOptions.package;
plugins = builtStartPlugins ++ builtOptPlugins;
appName = "nvf";
extraBinPath = vimOptions.extraPackages;
initLua = vimOptions.builtLuaConfigRC;
luaFiles = vimOptions.extraLuaFiles;
inherit (vimOptions) viAlias vimAlias withRuby withNodeJs withPython3;
inherit extraLuaPackages extraPython3Packages;
};
dummyInit = pkgs.writeText "nvf-init.lua" vimOptions.builtLuaConfigRC;
# Additional helper scripts for printing and displaying nvf configuration
# in your commandline.
printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}";
printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" "echo -n ${dummyInit}";
in {
inherit (module) options config;
inherit (module._module.args) pkgs;
# Expose wrapped neovim-package for userspace
# or module consumption.
neovim = pkgs.symlinkJoin {
name = "nvf-with-helpers";
paths = [neovim-wrapped printConfig printConfigPath];
postBuild = "echo Helpers added";
# Allow evaluating vimOptions, i.e., config.vim from the packages' passthru
# attribute. For example, packages.x86_64-linux.neovim.passthru.neovimConfig
# will return the configuration in full.
passthru.neovimConfig = vimOptions;
meta =
neovim-wrapped.meta
// {
description = "Wrapped Neovim package with helper scripts to print the config (path)";
};
};
neovim = module.config.vim.build.finalPackage;
}

View file

@ -49,6 +49,7 @@
# using the configuration passed in `neovim` and `plugins` modules.
wrapper = map (p: ./wrapper + "/${p}") [
"build"
"environment"
"rc"
"warnings"
"lazy"

View file

@ -77,6 +77,9 @@ in {
-- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1
-- buffer is a directory
local directory = vim.fn.isdirectory(data.file) == 1
-- buffer is a [No Name]
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
@ -84,7 +87,7 @@ in {
local filetype = vim.bo[data.buf].ft
-- only files please
if not real_file and not no_name then
if not real_file and not directory and not no_name then
return
end
@ -93,6 +96,10 @@ in {
return
end
-- cd if buffer is a directory
if directory then
vim.cmd.cd(data.file)
end
-- open the tree but don't focus it
require("nvim-tree.api").tree.toggle({ focus = false })
end

View file

@ -37,6 +37,7 @@ in {
./csharp.nix
./julia.nix
./nu.nix
./odin.nix
];
options.vim.languages = {

View file

@ -92,7 +92,7 @@ in {
cmd = ${
if isList cfg.dap.package
then expToLua cfg.dap.package
else ''${cfg.dap.package}/bin/haskell-debug-adapter''
else ''{"${cfg.dap.package}/bin/haskell-debug-adapter"}''
},
},
''}

View file

@ -0,0 +1,71 @@
{
config,
pkgs,
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) isList;
inherit (lib.types) either listOf package str enum;
inherit (lib.nvim.lua) expToLua;
inherit (lib.nvim.types) mkGrammarOption;
defaultServer = "ols";
servers = {
ols = {
package = pkgs.ols;
lspConfig = ''
lspconfig.ols.setup {
capabilities = capabilities,
on_attach = default_on_attach,
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else "{'${cfg.lsp.package}/bin/ols'}"
}
}
'';
};
};
cfg = config.vim.languages.odin;
in {
options.vim.languages.odin = {
enable = mkEnableOption "Odin language support";
treesitter = {
enable = mkEnableOption "Odin treesitter" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "odin";
};
lsp = {
enable = mkEnableOption "Odin LSP support" // {default = config.vim.languages.enableLSP;};
server = mkOption {
type = enum (attrNames servers);
default = defaultServer;
description = "Odin LSP server to use";
};
package = mkOption {
description = "Ols package, or the command to run as a list of strings";
type = either package (listOf str);
default = pkgs.ols;
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
})
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.odin-lsp = servers.${cfg.lsp.server}.lspConfig;
})
]);
}

View file

@ -6,7 +6,7 @@
}: let
inherit (builtins) attrNames;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.modules) mkIf mkMerge mkDefault;
inherit (lib.lists) isList;
inherit (lib.types) either listOf package str enum;
inherit (lib.nvim.lua) expToLua;
@ -57,15 +57,25 @@ in {
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
vim.treesitter = {
enable = true;
grammars = [cfg.treesitter.package];
};
})
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.zig-lsp = servers.${cfg.lsp.server}.lspConfig;
vim = {
lsp.lspconfig = {
enable = true;
sources.zig-lsp = servers.${cfg.lsp.server}.lspConfig;
};
# nvf handles autosaving already
globals.zig_fmt_autosave = mkDefault 0;
};
})
]);
}

View file

@ -20,17 +20,9 @@ in {
cmd = "Run";
keys = [
(mkKeymap "n" cfg.mappings.run "<cmd>Run<CR>" {desc = mappings.run.description;})
(mkKeymap "n" cfg.mappings.runOverride "<cmd>Run!<CR>" {desc = mappings.runOverride.description;})
(mkKeymap "n" cfg.mappings.runCommand ''
function()
local input = vim.fn.input("Run command: ")
if input ~= "" then require("run").run(input, false) end
end
'' {
desc = mappings.run.description;
lua = true;
})
(mkKeymap "n" cfg.mappings.run "<cmd>Run<cr>" {desc = mappings.run.description;})
(mkKeymap "n" cfg.mappings.runOverride "<cmd>Run!<cr>" {desc = mappings.runOverride.description;})
(mkKeymap "n" cfg.mappings.runCommand "<cmd>RunPrompt<cr>" {desc = mappings.run.description;})
];
};

View file

@ -16,7 +16,7 @@ in {
pluginRC.nvim-notify = entryAnywhere ''
local notify = require("notify")
notify.setup(${toLuaObject cfg.setupOpts})
vim.notify = notify
vim.notify = notify.notify
'';
};
};

View file

@ -4,8 +4,8 @@
lib,
...
}: let
inherit (lib.strings) concatMapStringsSep;
inherit (lib.modules) mkIf;
cfg = config.vim.utility.preview.markdownPreview;
in {
config = mkIf cfg.enable {
@ -15,7 +15,7 @@ in {
mkdp_auto_start = cfg.autoStart;
mkdp_auto_close = cfg.autoClose;
mkdp_refresh_slow = cfg.lazyRefresh;
mkdp_filetypes = [(concatMapStringsSep ", " (x: "'" + x + "'") cfg.filetypes)];
mkdp_filetypes = cfg.filetypes;
mkdp_command_for_global = cfg.alwaysAllowPreview;
mkdp_open_to_the_world = cfg.broadcastServer;
mkdp_open_ip = cfg.customIP;

View file

@ -4,51 +4,33 @@
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.utility.surround;
mkLznKey = mode: key: {
inherit key mode;
inherit mode key;
};
in {
config = mkIf cfg.enable {
vim = {
startPlugins = ["nvim-surround"];
pluginRC.surround = entryAnywhere "require('nvim-surround').setup(${toLuaObject cfg.setupOpts})";
lazy.plugins.nvim-surround = {
package = "nvim-surround";
setupModule = "nvim-surround";
inherit (cfg) setupOpts;
keys =
[
(mkLznKey ["i"] cfg.setupOpts.keymaps.insert)
(mkLznKey ["i"] cfg.setupOpts.keymaps.insert_line)
(mkLznKey ["x"] cfg.setupOpts.keymaps.visual)
(mkLznKey ["x"] cfg.setupOpts.keymaps.visual_line)
(mkLznKey ["n"] cfg.setupOpts.keymaps.normal)
(mkLznKey ["n"] cfg.setupOpts.keymaps.normal_cur)
(mkLznKey ["n"] cfg.setupOpts.keymaps.normal_line)
(mkLznKey ["n"] cfg.setupOpts.keymaps.normal_cur_line)
(mkLznKey ["n"] cfg.setupOpts.keymaps.delete)
(mkLznKey ["n"] cfg.setupOpts.keymaps.change)
(mkLznKey ["n"] cfg.setupOpts.keymaps.change_line)
]
++ map (mkLznKey ["n" "i" "v"]) [
"<Plug>(nvim-surround-insert)"
"<Plug>(nvim-surround-insert-line)"
"<Plug>(nvim-surround-normal)"
"<Plug>(nvim-surround-normal-cur)"
"<Plug>(nvim-surround-normal-line)"
"<Plug>(nvim-surround-normal-cur-line)"
"<Plug>(nvim-surround-visual)"
"<Plug>(nvim-surround-visual-line)"
"<Plug>(nvim-surround-delete)"
"<Plug>(nvim-surround-change)"
"<Plug>(nvim-surround-change-line)"
];
keys = [
(mkLznKey "i" cfg.setupOpts.keymaps.insert)
(mkLznKey "i" cfg.setupOpts.keymaps.insert_line)
(mkLznKey "x" cfg.setupOpts.keymaps.visual)
(mkLznKey "x" cfg.setupOpts.keymaps.visual_line)
(mkLznKey "n" cfg.setupOpts.keymaps.normal)
(mkLznKey "n" cfg.setupOpts.keymaps.normal_cur)
(mkLznKey "n" cfg.setupOpts.keymaps.normal_line)
(mkLznKey "n" cfg.setupOpts.keymaps.normal_cur_line)
(mkLznKey "n" cfg.setupOpts.keymaps.delete)
(mkLznKey "n" cfg.setupOpts.keymaps.change)
(mkLznKey "n" cfg.setupOpts.keymaps.change_line)
];
};
};
};

View file

@ -1,13 +1,111 @@
{
config,
inputs,
lib,
config,
pkgs,
...
}: let
inherit (lib.attrsets) attrValues;
}
: let
inherit (pkgs) vimPlugins;
inherit (lib.strings) isString;
inherit (lib.lists) filter map;
cfg = config.vim;
# alias to the internal configuration
vimOptions = config.vim;
noBuildPlug = {pname, ...} @ attrs: let
src = inputs."plugin-${attrs.pname}";
in
{
version = src.shortRev or src.shortDirtyRev or "dirty";
outPath = src;
passthru.vimPlugin = false;
}
// attrs;
# build a vim plugin with the given name and arguments
# if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug
# instead
buildPlug = attrs: let
src = inputs."plugin-${attrs.pname}";
in
pkgs.vimUtils.buildVimPlugin (
{
version = src.shortRev or src.shortDirtyRev or "dirty";
inherit src;
}
// attrs
);
buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars);
pluginBuilders = {
nvim-treesitter = buildTreesitterPlug vimOptions.treesitter.grammars;
flutter-tools-patched = buildPlug {
pname = "flutter-tools";
patches = [../patches/flutter-tools.patch];
};
};
buildConfigPlugins = plugins:
map (
plug:
if (isString plug)
then pluginBuilders.${plug} or (noBuildPlug {pname = plug;})
else plug
) (filter (f: f != null) plugins);
# built (or "normalized") plugins that are modified
builtStartPlugins = buildConfigPlugins vimOptions.startPlugins;
builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins);
# additional Lua and Python3 packages, mapped to their respective functions
# to conform to the format mnw expects. end user should
# only ever need to pass a list of packages, which are modified
# here
extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages;
extraPython3Packages = ps: map (x: ps.${x}) vimOptions.python3Packages;
# Wrap the user's desired (unwrapped) Neovim package with arguments that'll be used to
# generate a wrapped Neovim package.
neovim-wrapped = inputs.mnw.lib.wrap pkgs {
neovim = vimOptions.package;
plugins = builtStartPlugins ++ builtOptPlugins;
appName = "nvf";
extraBinPath = vimOptions.extraPackages;
initLua = vimOptions.builtLuaConfigRC;
luaFiles = vimOptions.extraLuaFiles;
inherit (vimOptions) viAlias vimAlias withRuby withNodeJs withPython3;
inherit extraLuaPackages extraPython3Packages;
};
dummyInit = pkgs.writeText "nvf-init.lua" vimOptions.builtLuaConfigRC;
# Additional helper scripts for printing and displaying nvf configuration
# in your commandline.
printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}";
printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" "echo -n ${dummyInit}";
# Expose wrapped neovim-package for userspace
# or module consumption.
neovim = pkgs.symlinkJoin {
name = "nvf-with-helpers";
paths = [neovim-wrapped printConfig printConfigPath];
postBuild = "echo Helpers added";
# Allow evaluating vimOptions, i.e., config.vim from the packages' passthru
# attribute. For example, packages.x86_64-linux.neovim.passthru.neovimConfig
# will return the configuration in full.
passthru.neovimConfig = vimOptions;
meta =
neovim-wrapped.meta
// {
description = "Wrapped Neovim package with helper scripts to print the config (path)";
};
};
in {
config = {
vim.startPlugins = map (x: x.package) (attrValues cfg.extraPlugins);
config.vim.build = {
finalPackage = neovim;
};
}

View file

@ -1,6 +1,6 @@
{
imports = [
./config.nix
./options.nix
./config.nix
];
}

View file

@ -1,144 +1,12 @@
{
pkgs,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption literalMD;
inherit (lib.types) package bool str listOf attrsOf;
inherit (lib.nvim.types) pluginsOpt extraPluginType;
{lib, ...}: let
inherit (lib.types) package;
inherit (lib.options) mkOption;
in {
options.vim = {
package = mkOption {
options.vim.build = {
finalPackage = mkOption {
type = package;
default = pkgs.neovim-unwrapped;
description = ''
The neovim package to use for the wrapper. This
corresponds to the package that will be wrapped
with your plugins and settings.
::: {.warning}
You will need to use an unwrapped package for this
option to work as intended. Using an already wrapped
package here may yield undesirable results.
:::
'';
};
viAlias = mkOption {
type = bool;
default = true;
description = "Enable the `vi` alias for `nvim`";
};
vimAlias = mkOption {
type = bool;
default = true;
description = "Enable the `vim` alias for `nvim`";
};
startPlugins = pluginsOpt {
default = ["plenary-nvim"];
example = ''
[pkgs.vimPlugins.telescope-nvim]
'';
description = ''
List of plugins to load on startup. This is used
internally to add plugins to Neovim's runtime.
To add additional plugins to your configuration, consider
using the [{option}`vim.extraPlugins`](#opt-vim.extraPlugins)
option.
'';
};
optPlugins = pluginsOpt {
default = [];
example = ''
[pkgs.vimPlugins.vim-ghost]
'';
description = ''
List of plugins to optionally load on startup.
This option has the same type definition as {option}`vim.startPlugins`
and plugins in this list are appended to {option}`vim.startPlugins` by
the wrapper during the build process.
To avoid overriding packages and dependencies provided by startPlugins, you
are recommended to use this option or {option}`vim.extraPlugins` option.
'';
};
extraPlugins = mkOption {
type = attrsOf extraPluginType;
default = {};
description = ''
A list of plugins and their configurations that will be
set up after builtin plugins.
This option takes a special type that allows you to order
your custom plugins using nvf's modified DAG library.
'';
example = literalMD ''
```nix
with pkgs.vimPlugins; {
aerial = {
package = aerial-nvim;
setup = "require('aerial').setup {}";
};
harpoon = {
package = harpoon;
setup = "require('harpoon').setup {}";
after = ["aerial"]; # place harpoon configuration after aerial
};
}
```
'';
};
extraPackages = mkOption {
type = listOf package;
default = [];
example = ''[pkgs.fzf pkgs.ripgrep]'';
description = ''
List of additional packages to make available to the Neovim
wrapper.
'';
};
# this defaults to `true` in the wrapper
# and since we pass this value to the wrapper
# with an inherit, it should be `true` here as well
withRuby =
mkEnableOption ''
Ruby support in the Neovim wrapper.
''
// {
default = true;
};
withNodeJs = mkEnableOption ''
NodeJs support in the Neovim wrapper
'';
luaPackages = mkOption {
type = listOf str;
default = [];
example = ''["magick" "serpent"]'';
description = "List of lua packages to install";
};
withPython3 = mkEnableOption ''
Python3 support in the Neovim wrapper
'';
python3Packages = mkOption {
type = listOf str;
default = [];
example = ''["pynvim"]'';
description = "List of python packages to install";
readOnly = true;
description = "final output package";
};
};
}

View file

@ -0,0 +1,13 @@
{
config,
lib,
...
}: let
inherit (lib.attrsets) attrValues;
cfg = config.vim;
in {
config = {
vim.startPlugins = map (x: x.package) (attrValues cfg.extraPlugins);
};
}

View file

@ -0,0 +1,6 @@
{
imports = [
./config.nix
./options.nix
];
}

View file

@ -0,0 +1,144 @@
{
pkgs,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption literalMD;
inherit (lib.types) package bool str listOf attrsOf;
inherit (lib.nvim.types) pluginsOpt extraPluginType;
in {
options.vim = {
package = mkOption {
type = package;
default = pkgs.neovim-unwrapped;
description = ''
The neovim package to use for the wrapper. This
corresponds to the package that will be wrapped
with your plugins and settings.
::: {.warning}
You will need to use an unwrapped package for this
option to work as intended. Using an already wrapped
package here may yield undesirable results.
:::
'';
};
viAlias = mkOption {
type = bool;
default = true;
description = "Enable the `vi` alias for `nvim`";
};
vimAlias = mkOption {
type = bool;
default = true;
description = "Enable the `vim` alias for `nvim`";
};
startPlugins = pluginsOpt {
default = ["plenary-nvim"];
example = ''
[pkgs.vimPlugins.telescope-nvim]
'';
description = ''
List of plugins to load on startup. This is used
internally to add plugins to Neovim's runtime.
To add additional plugins to your configuration, consider
using the [{option}`vim.extraPlugins`](#opt-vim.extraPlugins)
option.
'';
};
optPlugins = pluginsOpt {
default = [];
example = ''
[pkgs.vimPlugins.vim-ghost]
'';
description = ''
List of plugins to optionally load on startup.
This option has the same type definition as {option}`vim.startPlugins`
and plugins in this list are appended to {option}`vim.startPlugins` by
the wrapper during the build process.
To avoid overriding packages and dependencies provided by startPlugins, you
are recommended to use this option or {option}`vim.extraPlugins` option.
'';
};
extraPlugins = mkOption {
type = attrsOf extraPluginType;
default = {};
description = ''
A list of plugins and their configurations that will be
set up after builtin plugins.
This option takes a special type that allows you to order
your custom plugins using nvf's modified DAG library.
'';
example = literalMD ''
```nix
with pkgs.vimPlugins; {
aerial = {
package = aerial-nvim;
setup = "require('aerial').setup {}";
};
harpoon = {
package = harpoon;
setup = "require('harpoon').setup {}";
after = ["aerial"]; # place harpoon configuration after aerial
};
}
```
'';
};
extraPackages = mkOption {
type = listOf package;
default = [];
example = ''[pkgs.fzf pkgs.ripgrep]'';
description = ''
List of additional packages to make available to the Neovim
wrapper.
'';
};
# this defaults to `true` in the wrapper
# and since we pass this value to the wrapper
# with an inherit, it should be `true` here as well
withRuby =
mkEnableOption ''
Ruby support in the Neovim wrapper.
''
// {
default = true;
};
withNodeJs = mkEnableOption ''
NodeJs support in the Neovim wrapper
'';
luaPackages = mkOption {
type = listOf str;
default = [];
example = ''["magick" "serpent"]'';
description = "List of lua packages to install";
};
withPython3 = mkEnableOption ''
Python3 support in the Neovim wrapper
'';
python3Packages = mkOption {
type = listOf str;
default = [];
example = ''["pynvim"]'';
description = "List of python packages to install";
};
};
}

View file

@ -76,6 +76,7 @@
else
mkLuaInline ''
function()
${optionalString (spec.beforeSetup != null) spec.beforeSetup}
${
optionalString (spec.setupModule != null)
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"

View file

@ -74,6 +74,15 @@
'';
};
beforeSetup = mkOption {
type = nullOr lines;
default = null;
description = ''
Lua code to run after the plugin is loaded, but before the setup
function is called.
'';
};
setupModule = mkOption {
type = nullOr str;
default = null;