2023-04-20 22:41:37 +02:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
2024-07-07 16:09:31 +01:00
|
|
|
options,
|
2023-04-20 22:41:37 +02:00
|
|
|
lib,
|
2024-08-02 01:26:01 +01:00
|
|
|
specialArgs,
|
2023-04-20 22:41:37 +02:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
inherit (lib) types;
|
2024-07-05 16:39:32 +01:00
|
|
|
|
2024-02-09 21:14:55 +01:00
|
|
|
fileModuleType = types.submoduleWith {
|
|
|
|
shorthandOnlyDefinesConfig = true;
|
2024-08-02 01:26:01 +01:00
|
|
|
inherit specialArgs;
|
2024-07-05 16:39:32 +01:00
|
|
|
# Don't include the modules in the docs, as that'd be redundant
|
2024-07-05 23:26:05 +01:00
|
|
|
modules = lib.optionals (!config.isDocs) [
|
2024-07-05 16:48:46 +01:00
|
|
|
../../.
|
|
|
|
./submodule.nix
|
2024-02-09 21:14:55 +01:00
|
|
|
];
|
2024-07-05 16:39:32 +01:00
|
|
|
description = "Nixvim configuration";
|
2024-02-09 21:14:55 +01:00
|
|
|
};
|
2023-04-20 22:41:37 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
files = lib.mkOption {
|
|
|
|
type = types.attrsOf fileModuleType;
|
2024-07-05 16:39:32 +01:00
|
|
|
description = "Extra files to add to the runtimepath";
|
2023-04-20 22:41:37 +02:00
|
|
|
default = { };
|
2024-07-05 16:39:32 +01:00
|
|
|
example = {
|
|
|
|
"ftplugin/nix.lua" = {
|
|
|
|
opts = {
|
|
|
|
tabstop = 2;
|
|
|
|
shiftwidth = 2;
|
|
|
|
expandtab = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-04-20 22:41:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
filesPlugin = lib.mkOption {
|
|
|
|
type = types.package;
|
2024-02-11 12:51:34 +00:00
|
|
|
description = "A derivation with all the files inside.";
|
2023-04-20 22:41:37 +02:00
|
|
|
internal = true;
|
|
|
|
readOnly = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
2024-07-07 16:09:31 +01:00
|
|
|
extraFiles = lib.filter (file: file.enable) (lib.attrValues config.extraFiles);
|
|
|
|
concatFilesOption = attr: lib.flatten (lib.mapAttrsToList (_: builtins.getAttr attr) config.files);
|
2023-04-20 22:41:37 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
# Each file can declare plugins/packages/warnings/assertions
|
|
|
|
extraPlugins = concatFilesOption "extraPlugins";
|
|
|
|
extraPackages = concatFilesOption "extraPackages";
|
|
|
|
warnings = concatFilesOption "warnings";
|
|
|
|
assertions = concatFilesOption "assertions";
|
|
|
|
|
2024-07-07 16:09:31 +01:00
|
|
|
# Add files to extraFiles
|
|
|
|
extraFiles = lib.mkDerivedConfig options.files (
|
|
|
|
lib.mapAttrs' (
|
|
|
|
_: file: {
|
|
|
|
name = file.path;
|
|
|
|
value.source = file.plugin;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2023-04-20 22:41:37 +02:00
|
|
|
# A directory with all the files in it
|
2024-07-07 16:09:31 +01:00
|
|
|
# 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" (
|
2024-07-25 18:09:16 +03:00
|
|
|
{ target, finalSource, ... }:
|
2024-07-07 16:09:31 +01:00
|
|
|
lib.escapeShellArgs [
|
|
|
|
"makeEntry"
|
|
|
|
# Force local source paths to be added to the store
|
2024-07-25 18:09:16 +03:00
|
|
|
"${finalSource}"
|
2024-07-07 16:09:31 +01:00
|
|
|
target
|
|
|
|
]
|
|
|
|
) extraFiles}
|
|
|
|
'';
|
2024-07-19 16:35:17 +03:00
|
|
|
|
|
|
|
# Never combine user files with the rest of the plugins
|
|
|
|
performance.combinePlugins.standalonePlugins = [ config.filesPlugin ];
|
2023-04-20 22:41:37 +02:00
|
|
|
};
|
|
|
|
}
|