nix-community.nixvim/modules/top-level/files/default.nix
Matt Sturgeon 086873bed9
modules: refactor extraFiles
Moved `extraFiles` from `modules/output.nix` into its own file `modules/files.nix`.

Users should now assign text to a `text` attribute, however they could
also assign a file path to a `source` attribute instead.

The old method of directly assigning a string still works, and is
coerced to the new type along with a deprecation warning.
2024-07-07 16:42:47 +01:00

97 lines
2.3 KiB
Nix

{
pkgs,
config,
options,
lib,
helpers,
...
}:
let
inherit (lib) types;
fileModuleType = types.submoduleWith {
shorthandOnlyDefinesConfig = true;
specialArgs = {
inherit helpers;
defaultPkgs = pkgs;
};
# Don't include the modules in the docs, as that'd be redundant
modules = lib.optionals (!config.isDocs) [
../../.
./submodule.nix
];
description = "Nixvim configuration";
};
in
{
options = {
files = lib.mkOption {
type = types.attrsOf fileModuleType;
description = "Extra files to add to the runtimepath";
default = { };
example = {
"ftplugin/nix.lua" = {
opts = {
tabstop = 2;
shiftwidth = 2;
expandtab = true;
};
};
};
};
filesPlugin = lib.mkOption {
type = types.package;
description = "A derivation with all the files inside.";
internal = true;
readOnly = true;
};
};
config =
let
extraFiles = lib.filter (file: file.enable) (lib.attrValues config.extraFiles);
concatFilesOption = attr: lib.flatten (lib.mapAttrsToList (_: builtins.getAttr attr) config.files);
in
{
# Each file can declare plugins/packages/warnings/assertions
extraPlugins = concatFilesOption "extraPlugins";
extraPackages = concatFilesOption "extraPackages";
warnings = concatFilesOption "warnings";
assertions = concatFilesOption "assertions";
# Add files to extraFiles
extraFiles = lib.mkDerivedConfig options.files (
lib.mapAttrs' (
_: file: {
name = file.path;
value.source = file.plugin;
}
)
);
# A directory with all the files in it
# 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" (
{ target, source, ... }:
lib.escapeShellArgs [
"makeEntry"
# Force local source paths to be added to the store
"${source}"
target
]
) extraFiles}
'';
};
}