From 7b2640070726a60a8d00f00dc9f65dd2e44a18e5 Mon Sep 17 00:00:00 2001 From: LeMarsu Date: Wed, 22 May 2024 03:25:06 +0200 Subject: [PATCH] feat: can give dependencies to new package --- flake.nix | 7 +++---- lib.nix | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index ec9751c..44f47dd 100644 --- a/flake.nix +++ b/flake.nix @@ -17,11 +17,10 @@ utils, alejandra, ... - } @ inputs: let - in + } @ inputs: utils.lib.mkFlake { inherit self inputs; - outputsBuilder = channel: let + outputsBuilder = channel: let system = channel.nixpkgs.system; in { formatter = alejandra.defaultPackage.${channel.nixpkgs.system}; @@ -31,6 +30,6 @@ }; }; - lib = import ./lib.nix { inherit nixpkgs; }; + lib = import ./lib.nix; }; } diff --git a/lib.nix b/lib.nix index ebc2852..3d5350b 100644 --- a/lib.nix +++ b/lib.nix @@ -1,4 +1,50 @@ -{...}: { +{ + mkNeovimPkg = { + pkgs, + package ? pkgs.neovim-unwrapped, + namePrefix ? "", + nameSuffix ? "", + dependencies ? [], + dependenciesExtraArgs ? {}, + customRC ? "", + ... + }: let + inherit (builtins) isPath; + inherit (pkgs) lib; + callPackage = lib.callPackageWith (pkgs // dependenciesExtraArgs); + inherit (lib.lists) concatMap; + inherit (lib.attrsets) attrNames; + # inherit (lib.debug) traceIf traceSeq traceVal traceValSeq traceValFn; + + remotePluginToNeovimPlugin = p: + pkgs.vimUtils.buildVimPlugin rec { + inherit (p) src name; + pname = name; + }; + + mkDep = dep: + if isPath dep + then mkDependencies (callPackage dep {}) + else if dep ? plugin + then let + inherit (dep) plugin; + in + if attrNames plugin == ["name" "src"] + then [(remotePluginToNeovimPlugin plugin)] + else [plugin] + else [dep]; + mkDependencies = concatMap mkDep; + + neovimConfig = pkgs.neovimUtils.makeNeovimConfig { + inherit customRC; + plugins = mkDependencies dependencies; + }; + pkg = pkgs.wrapNeovimUnstable package neovimConfig; + # TODO nameSuffix is buggy :'( + name = "${namePrefix}${pkg.name}${nameSuffix}"; + in + pkg // {inherit name;}; + mkNeovimModule = { pluginsDir ? null, attrName ? "neoflake",