From 5a498edd14ff3a4c65b8c74c6f8deed9b2facf6a Mon Sep 17 00:00:00 2001 From: traxys Date: Fri, 21 Apr 2023 20:04:58 +0200 Subject: [PATCH] modules/output: Allow to specify text to add as extra files (#343) To enable some features (like adding tree-sitter queries) we need to add files to specific directories in the runtime path (queries/lang/file.scm for tree-sitter queries for example). This commit adds support for specifying such files. You must be careful to not have any collisions between `files` and `extraFiles`. --- modules/output.nix | 6 ++++++ tests/test-sources/modules/extra-files.nix | 9 ++++++++ wrappers/_shared.nix | 24 ++++++++++++++++------ wrappers/modules/files.nix | 5 +++-- 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 tests/test-sources/modules/extra-files.nix diff --git a/modules/output.nix b/modules/output.nix index 44f0d18a..866d80ec 100644 --- a/modules/output.nix +++ b/modules/output.nix @@ -86,6 +86,12 @@ in { description = "Extra lua packages to include with neovim"; default = _: []; }; + + extraFiles = mkOption { + type = types.attrsOf types.str; + description = "Extra files to add to the runtime path"; + default = {}; + }; }; config = let diff --git a/tests/test-sources/modules/extra-files.nix b/tests/test-sources/modules/extra-files.nix new file mode 100644 index 00000000..33807e49 --- /dev/null +++ b/tests/test-sources/modules/extra-files.nix @@ -0,0 +1,9 @@ +{ + query = { + extraFiles = { + "queries/lua/injections.scm" = '' + ;; extends + ''; + }; + }; +} diff --git a/wrappers/_shared.nix b/wrappers/_shared.nix index e6e0727f..9f5f99b9 100644 --- a/wrappers/_shared.nix +++ b/wrappers/_shared.nix @@ -26,12 +26,24 @@ in { configFiles = let cfg = config.programs.nixvim; in - lib.mapAttrs' ( - _: file: - lib.nameValuePair - "nvim/${file.path}" - {text = file.content;} + lib.mapAttrs' + ( + _: file: + lib.nameValuePair + "nvim/${file.path}" + {text = file.content;} + ) + cfg.files ) - cfg.files; + // ( + lib.mapAttrs' + ( + path: content: + lib.nameValuePair + "nvim/${path}" + {text = content;} + ) + cfg.extraFiles + ); } diff --git a/wrappers/modules/files.nix b/wrappers/modules/files.nix index 02fb98d4..7edc5509 100644 --- a/wrappers/modules/files.nix +++ b/wrappers/modules/files.nix @@ -57,8 +57,9 @@ in { # A directory with all the files in it filesPlugin = pkgs.buildEnv { name = "nixvim-config"; - paths = lib.mapAttrsToList (_: file: file.plugin) files; - ignoreCollisions = true; # Collisions can't happen by construction + paths = + (lib.mapAttrsToList (_: file: file.plugin) files) + ++ (lib.mapAttrsToList (path: content: pkgs.writeTextDir path content) config.extraFiles); }; }; }