{ lib, lndir, stdenvNoCC, callPackage, makeBinaryWrapper, neovim-unwrapped, }: let inherit (lib) concatMapStrings getExe getVersion makeBinPath optionalString ; inherit (builtins) typeOf baseNameOf; in lib.extendMkDerivation { constructDrv = stdenvNoCC.mkDerivation; excludeDrvArgNames = [ "extraLuaPackages" ]; extendDrvArgs = _: { # neovim pname ? "neovim", versionSuffix ? "wrapped", # you can choose the base, i choose neovim-unwrapped basePackage ? neovim-unwrapped, # extra lua packages extraLuaPackages ? _: [ ], # path, see there explanation below extraPackages ? [ ], # providers, these are the providers that will be enabled providers ? { }, # extra init.lua, this is useful for setting up the environment extraPreloadLua ? "", # plugins plugins ? { }, pluginOverrides ? null, startPlugins ? [ ], optPlugins ? [ ], # our config userConfig, # PERF: clean runtime path so it only contains explicit runtime directories # - removes directories from homedir as well as nix data directories # - this means some programs that ship extra nvim data files need to be # explicitly added to the rtp with a package override cleanRuntimePath ? false, additionalRuntimePaths ? [ ], # other customisation aliases ? [ ], keepDesktopFiles ? false, }@args: let inherit (basePackage) lua; luaEnv = lua.withPackages extraLuaPackages; inherit (lua.pkgs) luaLib; structuredPlugins = import ./plugins { inherit lib startPlugins optPlugins; plugins = callPackage ./plugins/package.nix { pins = plugins; inherit pluginOverrides; }; }; # i couldn't chose a nice api between attrs and lists, so i just did both lol attrsifiedProviders = if lib.isAttrs providers then providers else (lib.genAttrs providers (_: true)); # merge providers attrs, with priority to the user providerd options pluginProviders = { node = false; perl = false; python = false; python3 = false; ruby = false; } // attrsifiedProviders; mkResultingPath = subdir: p: "pack/${pname}/${subdir}/${if typeOf p == "path" then baseNameOf p else (p.pname or p.name)}"; config = stdenvNoCC.mkDerivation { name = "neovim-config"; __structuredAttrs = true; plugins = structuredPlugins.start ++ structuredPlugins.opt; resultingPaths = map (mkResultingPath "start") structuredPlugins.start ++ map (mkResultingPath "opt") structuredPlugins.opt; # didn't know you could do this. thanks getchiee buildCommand = # bash '' mkdir -pv $out/parser mkdir -pv $out/pack/${pname}/{start,opt} echo "generating preload.lua" cat > $out/preload.lua <> "$out/nix-support/propagated-build-inputs" done ''; }; in { inherit pname; version = "${args.version or (getVersion basePackage)}${ if versionSuffix != "" then "-${versionSuffix}" else "" }"; # don't allow for simple arugments here these **should** remain this way # so the wrapper works correctly __structuredAttrs = true; strictDeps = true; # this won't really remove anything since we still are running fixup on basePackage and the config # but it does speed up the build speed dontUnpack = true; dontFixup = true; dontConfigure = true; dontRewriteSymlinks = true; nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [ makeBinaryWrapper lndir ]; wrapperArgs = [ "--set-default" "NVIM_CONFIG" "${userConfig}" "--add-flag" "--cmd" "--add-flag" "source ${config}/preload.lua" "--set-default" "NVIM_APPNAME" pname ] ++ args.wrapperArgs or [ ]; installPhase = '' runHook preInstall mkdir -p $out lndir -silent ${basePackage} $out ${optionalString (!keepDesktopFiles) "rm -rf $out/share/applications"} wrapProgram $out/bin/nvim "''${wrapperArgs[@]}" ${concatMapStrings (alias: '' ln -s $out/bin/nvim $out/bin/${alias} '') aliases} runHook postInstall ''; passthru = { inherit config; } // args.passthru or { }; meta = basePackage.meta // { priority = (basePackage.meta.priority or lib.meta.defaultPriority) - 1; } // args.meta or { }; }; }