mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-16 04:04:34 +02:00
Enable creation of other config files than init.lua (#246)
This commit is contained in:
parent
bc468178ae
commit
a6eec507cc
8 changed files with 283 additions and 115 deletions
64
wrappers/modules/files.nix
Normal file
64
wrappers/modules/files.nix
Normal file
|
@ -0,0 +1,64 @@
|
|||
modules: {
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) types;
|
||||
fileModuleType = types.submodule ({
|
||||
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;
|
||||
};
|
||||
});
|
||||
in {
|
||||
options = {
|
||||
files = lib.mkOption {
|
||||
type = types.attrsOf fileModuleType;
|
||||
description = "Files to include in the vim config";
|
||||
default = {};
|
||||
};
|
||||
|
||||
filesPlugin = lib.mkOption {
|
||||
type = types.package;
|
||||
description = "A derivation with all the files inside";
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
};
|
||||
};
|
||||
|
||||
config = let
|
||||
files = config.files;
|
||||
concatFilesOption = attr:
|
||||
lib.flatten (lib.mapAttrsToList (_: file: builtins.getAttr attr file) files);
|
||||
in {
|
||||
# Each file can declare plugins/packages/warnings/assertions
|
||||
extraPlugins = concatFilesOption "extraPlugins";
|
||||
extraPackages = concatFilesOption "extraPackages";
|
||||
warnings = concatFilesOption "warnings";
|
||||
assertions = concatFilesOption "assertions";
|
||||
|
||||
# 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
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue