2024-07-07 16:09:31 +01:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
helpers,
|
|
|
|
pkgs,
|
2024-07-25 18:09:16 +03:00
|
|
|
config,
|
2024-07-07 16:09:31 +01:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
2024-09-12 14:56:36 +01:00
|
|
|
builders = lib.nixvim.builders.withPkgs pkgs;
|
|
|
|
|
2024-07-25 18:09:16 +03:00
|
|
|
fileTypeModule =
|
2024-07-07 16:09:31 +01:00
|
|
|
{
|
|
|
|
name,
|
|
|
|
config,
|
|
|
|
options,
|
2024-07-25 18:09:16 +03:00
|
|
|
topConfig,
|
2024-07-07 16:09:31 +01:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether this file should be generated.
|
|
|
|
This option allows specific files to be disabled.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
target = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
defaultText = lib.literalMD "the attribute name";
|
|
|
|
description = ''
|
|
|
|
Name of symlink, relative to nvim config.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
text = lib.mkOption {
|
|
|
|
type = with lib.types; nullOr lines;
|
|
|
|
default = null;
|
|
|
|
description = "Text of the file.";
|
|
|
|
};
|
|
|
|
|
|
|
|
source = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
|
|
|
description = "Path of the source file.";
|
|
|
|
};
|
2024-07-25 18:09:16 +03:00
|
|
|
|
|
|
|
finalSource = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
|
|
|
description = "Path to the final source file.";
|
|
|
|
readOnly = true;
|
|
|
|
visible = false;
|
|
|
|
internal = true;
|
|
|
|
};
|
2024-07-07 16:09:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
|
|
|
derivationName = "nvim-" + lib.replaceStrings [ "/" ] [ "-" ] name;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
target = lib.mkDefault name;
|
|
|
|
source = lib.mkIf (config.text != null) (
|
|
|
|
# mkDerivedConfig uses the option's priority, and calls our function with the option's value.
|
|
|
|
# This means our `source` definition has the same priority as `text`.
|
|
|
|
lib.mkDerivedConfig options.text (pkgs.writeText derivationName)
|
|
|
|
);
|
2024-07-25 18:09:16 +03:00
|
|
|
finalSource =
|
|
|
|
# Byte compile lua files if performance.byteCompileLua option is enabled
|
|
|
|
if
|
|
|
|
lib.hasSuffix ".lua" config.target
|
|
|
|
&& topConfig.performance.byteCompileLua.enable
|
|
|
|
&& topConfig.performance.byteCompileLua.configs
|
|
|
|
then
|
|
|
|
if lib.isDerivation config.source then
|
|
|
|
# Source is a derivation
|
2024-09-12 14:56:36 +01:00
|
|
|
builders.byteCompileLuaDrv config.source
|
2024-07-25 18:09:16 +03:00
|
|
|
else
|
|
|
|
# Source is a path or string
|
2024-09-12 14:56:36 +01:00
|
|
|
builders.byteCompileLuaFile derivationName config.source
|
2024-07-25 18:09:16 +03:00
|
|
|
else
|
|
|
|
config.source;
|
2024-07-07 16:09:31 +01:00
|
|
|
};
|
2024-07-25 18:09:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
fileType = lib.types.submoduleWith {
|
|
|
|
shorthandOnlyDefinesConfig = true;
|
|
|
|
modules = [ fileTypeModule ];
|
|
|
|
specialArgs.topConfig = config;
|
|
|
|
};
|
2024-07-07 16:09:31 +01:00
|
|
|
|
|
|
|
# TODO: Added 2024-07-07, remove after 24.11
|
|
|
|
# Before we had a fileType, we used types.str.
|
|
|
|
coercedFileType = helpers.transitionType lib.types.str (text: { inherit text; }) fileType;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
extraFiles = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf coercedFileType;
|
|
|
|
description = "Extra files to add to the runtime path";
|
|
|
|
default = { };
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
{
|
|
|
|
"ftplugin/nix.lua".text = '''
|
|
|
|
vim.opt.tabstop = 2
|
|
|
|
vim.opt.shiftwidth = 2
|
|
|
|
vim.opt.expandtab = true
|
|
|
|
''';
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|