From c9a6912be575ffa83512c4dcdd9918f794ac401e Mon Sep 17 00:00:00 2001 From: Stanislav Asunkin <1353637+stasjok@users.noreply.github.com> Date: Fri, 19 Jul 2024 11:37:00 +0300 Subject: [PATCH] modules/files: fix creating configs of vim type --- modules/top-level/files/submodule.nix | 4 +++- tests/modules/files.nix | 16 --------------- tests/test-sources/modules/files.nix | 29 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 17 deletions(-) delete mode 100644 tests/modules/files.nix create mode 100644 tests/test-sources/modules/files.nix diff --git a/modules/top-level/files/submodule.nix b/modules/top-level/files/submodule.nix index d231cf6a87..c31a95c3d2 100644 --- a/modules/top-level/files/submodule.nix +++ b/modules/top-level/files/submodule.nix @@ -2,6 +2,7 @@ name, config, lib, + pkgs, helpers, ... }: @@ -17,11 +18,12 @@ config = let derivationName = "nvim-" + lib.replaceStrings [ "/" ] [ "-" ] name; + writeContent = if config.type == "lua" then helpers.writeLua else pkgs.writeText; in { path = lib.mkDefault name; type = lib.mkDefault (if lib.hasSuffix ".vim" name then "vim" else "lua"); # No need to use mkDerivedConfig; this option is readOnly. - plugin = helpers.writeLua derivationName config.content; + plugin = writeContent derivationName config.content; }; } diff --git a/tests/modules/files.nix b/tests/modules/files.nix deleted file mode 100644 index 74125ccaca..0000000000 --- a/tests/modules/files.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ - after = { - files."after/ftplugin/python.lua" = { - localOpts.conceallevel = 1; - - keymaps = [ - { - mode = "n"; - key = ""; - action = ":!python script.py"; - options.silent = true; - } - ]; - }; - }; -} diff --git a/tests/test-sources/modules/files.nix b/tests/test-sources/modules/files.nix new file mode 100644 index 0000000000..19da427247 --- /dev/null +++ b/tests/test-sources/modules/files.nix @@ -0,0 +1,29 @@ +{ + after = { + files."after/ftplugin/python.lua" = { + localOpts.conceallevel = 1; + + keymaps = [ + { + mode = "n"; + key = ""; + action = ":!python script.py"; + options.silent = true; + } + ]; + }; + }; + + vim-type = { + files."plugin/default_indent.vim".opts = { + shiftwidth = 2; + expandtab = true; + }; + + extraConfigLuaPost = '' + vim.cmd.runtime("plugin/default_indent.vim") + assert(vim.o.shiftwidth == 2, "shiftwidth is not set") + assert(vim.o.expandtab, "expandtab is not set") + ''; + }; +}