mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-04 22:34:31 +02:00
modules/top-level: move out of wrappers/modules
This commit is contained in:
parent
b59fa976d0
commit
2deb61f6a5
10 changed files with 34 additions and 16 deletions
73
modules/top-level/files.nix
Normal file
73
modules/top-level/files.nix
Normal file
|
@ -0,0 +1,73 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
helpers,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib) types;
|
||||
fileModuleType = types.submoduleWith {
|
||||
shorthandOnlyDefinesConfig = true;
|
||||
specialArgs = {
|
||||
inherit helpers;
|
||||
defaultPkgs = pkgs;
|
||||
};
|
||||
modules = [
|
||||
(
|
||||
{ name, config, ... }:
|
||||
{
|
||||
imports = [ ../. ];
|
||||
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
|
||||
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";
|
||||
|
||||
# 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);
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue