mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
This commit adds support for byte compiling lua configuration files. It's enabled by default (if byte compiling is enabled at all) and can be disabled with `performance.byteCompileLua.configs` toggle. To implement this feature `extraFiles.<name>.finalSource` internal read-only option is introduced. `source` option cannot be used because it's user configurable. In order to access the values of the `performance.byteCompileLua` options, parent config is added to specialArgs of extraFiles submodule. Then the usages of `source` option changed to `finalSource` in all relevant places (filesPlugin and wrappers). Added more helpers for various cases of byte compiling: * `byteCompileLuaFile` byte compiles lua file * `byteCompileLuaHook` is a setup hook that byte compiles all lua files * `byteCompileLuaDrv` overrides derivation by adding byteCompileLuaHook to it Added tests to validate that extraFiles specified by various methods are handled correctly. Added a separate home-manager test, that is intended to validate that extraFiles propagated to wrapper modules are correctly byte compiled.
100 lines
2.5 KiB
Nix
100 lines
2.5 KiB
Nix
{
|
|
pkgs,
|
|
config,
|
|
options,
|
|
lib,
|
|
helpers,
|
|
...
|
|
}:
|
|
let
|
|
inherit (lib) types;
|
|
|
|
fileModuleType = types.submoduleWith {
|
|
shorthandOnlyDefinesConfig = true;
|
|
specialArgs = {
|
|
inherit helpers;
|
|
defaultPkgs = pkgs;
|
|
};
|
|
# Don't include the modules in the docs, as that'd be redundant
|
|
modules = lib.optionals (!config.isDocs) [
|
|
../../.
|
|
./submodule.nix
|
|
];
|
|
description = "Nixvim configuration";
|
|
};
|
|
in
|
|
{
|
|
options = {
|
|
files = lib.mkOption {
|
|
type = types.attrsOf fileModuleType;
|
|
description = "Extra files to add to the runtimepath";
|
|
default = { };
|
|
example = {
|
|
"ftplugin/nix.lua" = {
|
|
opts = {
|
|
tabstop = 2;
|
|
shiftwidth = 2;
|
|
expandtab = true;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
filesPlugin = lib.mkOption {
|
|
type = types.package;
|
|
description = "A derivation with all the files inside.";
|
|
internal = true;
|
|
readOnly = true;
|
|
};
|
|
};
|
|
|
|
config =
|
|
let
|
|
extraFiles = lib.filter (file: file.enable) (lib.attrValues config.extraFiles);
|
|
concatFilesOption = attr: lib.flatten (lib.mapAttrsToList (_: builtins.getAttr attr) config.files);
|
|
in
|
|
{
|
|
# Each file can declare plugins/packages/warnings/assertions
|
|
extraPlugins = concatFilesOption "extraPlugins";
|
|
extraPackages = concatFilesOption "extraPackages";
|
|
warnings = concatFilesOption "warnings";
|
|
assertions = concatFilesOption "assertions";
|
|
|
|
# Add files to extraFiles
|
|
extraFiles = lib.mkDerivedConfig options.files (
|
|
lib.mapAttrs' (
|
|
_: file: {
|
|
name = file.path;
|
|
value.source = file.plugin;
|
|
}
|
|
)
|
|
);
|
|
|
|
# A directory with all the files in it
|
|
# Implementation based on NixOS's /etc module
|
|
filesPlugin = pkgs.runCommandLocal "nvim-config" { } ''
|
|
set -euo pipefail
|
|
|
|
makeEntry() {
|
|
src="$1"
|
|
target="$2"
|
|
mkdir -p "$out/$(dirname "$target")"
|
|
cp "$src" "$out/$target"
|
|
}
|
|
|
|
mkdir -p "$out"
|
|
${lib.concatMapStringsSep "\n" (
|
|
{ target, finalSource, ... }:
|
|
lib.escapeShellArgs [
|
|
"makeEntry"
|
|
# Force local source paths to be added to the store
|
|
"${finalSource}"
|
|
target
|
|
]
|
|
) extraFiles}
|
|
'';
|
|
|
|
# Never combine user files with the rest of the plugins
|
|
performance.combinePlugins.standalonePlugins = [ config.filesPlugin ];
|
|
};
|
|
}
|