sloth-flake.nvim/lib/modules/default.nix

141 lines
3.6 KiB
Nix

{
pkgs,
callModule,
...
}: let
inherit (builtins) concatLists;
inherit (pkgs) bash lib;
inherit
(lib)
concatMap
flip
literalExample
mkEnableOption
mkOption
mkPackageOption
optional
optionalString
types
;
modules = {
init = callModule ./init.nix {};
plugin = callModule ./plugin {};
runtime = callModule ./runtime.nix {};
sloth = callModule ./sloth.nix {};
};
extraLuaPackagesType =
(with types; functionTo (listOf package))
// {
merge = loc: defs: let
fnList = map (def: def.value) defs;
concatPackages = ps: fn: fn ps;
in
ps: concatMap (concatPackages ps) fnList;
};
mkDiffAlias = name:
(flip optionalString) ''
cat <<SH > $out/bin/${name}
#!${bash}/bin/bash
exec $out/bin/nvim -d "\''${@}"
SH
chmod 555 $out/bin/${name}
'';
in {
defaultModule = {
config,
lib,
...
}: let
pkg = pkgs.wrapNeovimUnstable config.package config.neovimOptions;
customLuaRC = modules.init.mkCustomLuaRc config.init;
plugins = concatLists [
(map modules.plugin.extract config.plugins)
(optional (! isNull config.runtime) config.runtime.package)
[config.slothPlugin]
];
neovimOptions = pkgs.neovimUtils.makeNeovimConfig {
inherit (config) extraLuaPackages viAlias vimAlias;
inherit customLuaRC plugins;
wrapRc = customLuaRC != null;
# inherit customRC;
};
neovimPackage = pkg.overrideAttrs (final: super: {
postBuild =
super.postBuild
+ (mkDiffAlias "vimdiff" config.vimdiffAlias)
+ (mkDiffAlias "nvimdiff" config.nvimdiffAlias);
});
in {
options = {
package = mkPackageOption pkgs "neovim-unwrapped" {};
# Will probably be not needed
# dependenciesExtraArgs = mkOption {
# default = {};
# };
extraLuaPackages = mkOption {
description = ''
function to define extra lua packages that should be included in
neovim environment.
'';
type = extraLuaPackagesType;
example = literalExample "p: [p.nvim-nio]";
defaultText = literalExample "_: []";
default = _: [];
};
init = modules.init.option;
runtime = modules.runtime.option;
plugins = modules.plugin.option;
viAlias = mkEnableOption "creation on `vi` alias";
vimAlias = mkEnableOption "creation on `vim` alias";
vimdiffAlias = mkEnableOption "creation on `vimdiff` alias";
nvimdiffAlias = mkEnableOption "creation on `nvimdiff` alias";
pluginLuaDefinitions = mkOption {
description = ''
All lua definitions of plugins. Used by sloth vim plugin
'';
type = with types; attrsOf anything;
readOnly = true;
internal = true;
default = modules.sloth.mkPluginLuaDefinitions config.plugins;
};
slothPlugin = mkOption {
description = ''
The resulted sloth plugin
'';
type = types.package;
readOnly = true;
internal = true;
default = modules.sloth.mkSlothPlugin config.pluginLuaDefinitions;
};
neovimOptions = mkOption {
type = types.attrs;
readOnly = true;
description = "The resulting configuration passed to `pkgs.wrapNeovimUnstable`";
default = neovimOptions;
};
neovimPackage = mkOption {
type = types.package;
description = "The neovim package generated from your configuration.";
readOnly = true;
# defaultText = lib.literalExpression "pkgs.hello";
default = neovimPackage;
};
};
};
}