141 lines
3.7 KiB
Nix
141 lines
3.7 KiB
Nix
{version, ...}: {pkgs, ...}: let
|
|
inherit (builtins) concatLists;
|
|
inherit (pkgs) bash lib;
|
|
inherit
|
|
(lib)
|
|
callPackageWith
|
|
concatMap
|
|
evalModules
|
|
fix
|
|
flip
|
|
literalExample
|
|
mkEnableOption
|
|
mkOption
|
|
mkPackageOption
|
|
optional
|
|
optionalString
|
|
types
|
|
;
|
|
|
|
callModule = callPackageWith {inherit pkgs callModule;};
|
|
|
|
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}
|
|
'';
|
|
|
|
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) (modules.runtime.mkPlugin config.runtime))
|
|
[(modules.sloth.mkPlugin version config.plugins)]
|
|
];
|
|
|
|
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";
|
|
|
|
neovimOptions = mkOption {
|
|
type = types.attrs;
|
|
description = "The resulting configuration passed to `pkgs.wrapNeovimUnstable`";
|
|
default = neovimOptions;
|
|
};
|
|
|
|
neovimPackage = mkOption {
|
|
type = types.package;
|
|
description = "The neovim package generated from your configuration.";
|
|
# defaultText = lib.literalExpression "pkgs.hello";
|
|
default = neovimPackage;
|
|
};
|
|
};
|
|
};
|
|
in
|
|
fix (sLib: {
|
|
inherit defaultModule;
|
|
mkPluginsFromInputs = import ./mkPluginsFromInputs.nix {inherit pkgs;};
|
|
|
|
evalSlothModules = {
|
|
modules ? [],
|
|
specialArgs ? {},
|
|
}: let
|
|
moduleConfig = evalModules {
|
|
specialArgs = specialArgs // {inherit pkgs;};
|
|
modules = modules ++ [sLib.defaultModule];
|
|
};
|
|
in
|
|
moduleConfig.config;
|
|
|
|
mkNeovimPkg = {
|
|
modules ? [],
|
|
specialArgs ? {},
|
|
}:
|
|
(sLib.evalSlothModules {inherit modules specialArgs;}).neovimPackage;
|
|
})
|