nix-community.nixvim/wrappers/modules/files.nix

72 lines
1.8 KiB
Nix
Raw Permalink Normal View History

2024-05-05 19:39:35 +02:00
modules:
{
pkgs,
config,
lib,
2024-02-09 21:14:55 +01:00
helpers,
...
2024-05-05 19:39:35 +02:00
}:
let
inherit (lib) types;
2024-02-09 21:14:55 +01:00
fileModuleType = types.submoduleWith {
shorthandOnlyDefinesConfig = true;
specialArgs.helpers = helpers;
modules = [
2024-05-05 19:39:35 +02:00
(
{ name, config, ... }:
{
imports = modules;
options.plugin = lib.mkOption {
type = types.package;
description = "A derivation with the content of the file in it";
readOnly = true;
internal = true;
};
config = {
path = name;
type = lib.mkDefault (if lib.hasSuffix ".vim" name then "vim" else "lua");
plugin = pkgs.writeTextDir config.path config.content;
};
}
)
2024-02-09 21:14:55 +01:00
];
};
2024-05-05 19:39:35 +02:00
in
{
options = {
files = lib.mkOption {
type = types.attrsOf fileModuleType;
2024-02-11 12:51:34 +00:00
description = "Files to include in the Vim config.";
2024-05-05 19:39:35 +02:00
default = { };
};
filesPlugin = lib.mkOption {
type = types.package;
2024-02-11 12:51:34 +00:00
description = "A derivation with all the files inside.";
internal = true;
readOnly = true;
};
};
2024-05-05 19:39:35 +02:00
config =
let
inherit (config) files;
concatFilesOption = attr: lib.flatten (lib.mapAttrsToList (_: builtins.getAttr attr) files);
in
{
# Each file can declare plugins/packages/warnings/assertions
extraPlugins = concatFilesOption "extraPlugins";
extraPackages = concatFilesOption "extraPackages";
warnings = concatFilesOption "warnings";
assertions = concatFilesOption "assertions";
2024-05-05 19:39:35 +02:00
# A directory with all the files in it
filesPlugin = pkgs.buildEnv {
name = "nixvim-config";
paths =
(lib.mapAttrsToList (_: file: file.plugin) files)
++ (lib.mapAttrsToList pkgs.writeTextDir config.extraFiles);
};
};
}