summary refs log tree commit diff
path: root/pkgs/development/lua-modules
diff options
context:
space:
mode:
authorMatthieu Coudron <mcoudron@hotmail.com>2021-09-12 00:01:49 +0200
committerMatthieu Coudron <mcoudron@hotmail.com>2021-09-12 03:03:56 +0200
commit88842910b52c146bc5ef9c78eed34e5e570ef76c (patch)
tree209d81c2060e5ae5f211b9a473e42fab9be57888 /pkgs/development/lua-modules
parent0b6d33c2ed177be6d937e3043ac77252007a77b1 (diff)
downloadnixpkgs-88842910b52c146bc5ef9c78eed34e5e570ef76c.tar
nixpkgs-88842910b52c146bc5ef9c78eed34e5e570ef76c.tar.gz
nixpkgs-88842910b52c146bc5ef9c78eed34e5e570ef76c.tar.bz2
nixpkgs-88842910b52c146bc5ef9c78eed34e5e570ef76c.tar.lz
nixpkgs-88842910b52c146bc5ef9c78eed34e5e570ef76c.tar.xz
nixpkgs-88842910b52c146bc5ef9c78eed34e5e570ef76c.tar.zst
nixpkgs-88842910b52c146bc5ef9c78eed34e5e570ef76c.zip
lua: introduced a lua lib
Goal is to improve separation between packages and utilities.
Can help with autocompletion/navigate nixpkgs faster.
Also it will help standardize how LUA_PATH is exported across packages,
so that one can more easily make lua changes across nixpkgs (for
    instance changing where lua modules are installed).
Diffstat (limited to 'pkgs/development/lua-modules')
-rw-r--r--pkgs/development/lua-modules/default.nix7
-rw-r--r--pkgs/development/lua-modules/lib.nix63
-rw-r--r--pkgs/development/lua-modules/overrides.nix6
3 files changed, 72 insertions, 4 deletions
diff --git a/pkgs/development/lua-modules/default.nix b/pkgs/development/lua-modules/default.nix
index 091b94f58f5..e4927ee3046 100644
--- a/pkgs/development/lua-modules/default.nix
+++ b/pkgs/development/lua-modules/default.nix
@@ -1,7 +1,7 @@
 # inspired by pkgs/development/haskell-modules/default.nix
 { pkgs, lib
 , lua
-, overrides ? (self: super: {})
+, overrides ? (final: prev: {})
 }:
 
 let
@@ -15,7 +15,7 @@ let
   overridenPackages = import ./overrides.nix { inherit pkgs; };
 
   generatedPackages = if (builtins.pathExists ./generated-packages.nix) then
-        pkgs.callPackage ./generated-packages.nix { } else (self: super: {});
+        pkgs.callPackage ./generated-packages.nix { } else (final: prev: {});
 
   extensible-self = lib.makeExtensible
     (extends overrides
@@ -24,7 +24,6 @@ let
               initialPackages
               )
           )
-    )
-          ;
+    );
 in
   extensible-self
diff --git a/pkgs/development/lua-modules/lib.nix b/pkgs/development/lua-modules/lib.nix
new file mode 100644
index 00000000000..0180897f77a
--- /dev/null
+++ b/pkgs/development/lua-modules/lib.nix
@@ -0,0 +1,63 @@
+{ pkgs, lib, lua }:
+let
+  requiredLuaModules = drvs: with lib; let
+    modules =  filter hasLuaModule drvs;
+  in unique ([lua] ++ modules ++ concatLists (catAttrs "requiredLuaModules" modules));
+  # Check whether a derivation provides a lua module.
+  hasLuaModule = drv: drv ? luaModule;
+in
+rec {
+  inherit hasLuaModule requiredLuaModules;
+
+  luaPathList = [
+    "share/lua/${lua.luaversion}/?.lua"
+    "share/lua/${lua.luaversion}/?/init.lua"
+  ];
+  luaCPathList = [
+    "lib/lua/${lua.luaversion}/?.so"
+  ];
+
+  /* generate paths without a prefix
+  */
+  luaPathRelStr = lib.concatStringsSep ";" luaPathList;
+  luaCPathRelStr = lib.concatStringsSep ";" luaCPathList;
+
+  /* generate LUA_(C)PATH value for a specific derivation, i.e., with absolute paths
+  */
+  genLuaPathAbsStr = drv: lib.concatMapStringsSep ";" (x: "${drv}/${x}") luaPathList;
+  genLuaCPathAbsStr = drv: lib.concatMapStringsSep ";" (x: "${drv}/${x}") luaCPathList;
+
+  /* Generate a LUA_PATH with absolute paths
+  */
+  # genLuaPathAbs = drv:
+  #   lib.concatStringsSep ";" (map (x: "${drv}/x") luaPathList);
+
+  luaAtLeast = lib.versionAtLeast lua.luaversion;
+  luaOlder = lib.versionOlder lua.luaversion;
+  isLua51 = (lib.versions.majorMinor lua.version) == "5.1";
+  isLua52 = (lib.versions.majorMinor lua.version) == "5.2";
+  isLua53 = lua.luaversion == "5.3";
+  isLuaJIT = lib.getName lua == "luajit";
+
+  /* generates the relative path towards the folder where
+   seems stable even when using  lua_modules_path = ""
+
+   Example:
+    getDataFolder luaPackages.stdlib
+    => stdlib-41.2.2-1-rocks/stdlib/41.2.2-1/doc
+  */
+  getDataFolder = drv:
+    "${drv.pname}-${drv.version}-rocks/${drv.pname}/${drv.version}";
+
+  /* Convert derivation to a lua module.
+    so that luaRequireModules can be run later
+  */
+  toLuaModule = drv:
+    drv.overrideAttrs( oldAttrs: {
+      # Use passthru in order to prevent rebuilds when possible.
+      passthru = (oldAttrs.passthru or {})// {
+        luaModule = lua;
+        requiredLuaModules = requiredLuaModules drv.propagatedBuildInputs;
+      };
+    });
+}
diff --git a/pkgs/development/lua-modules/overrides.nix b/pkgs/development/lua-modules/overrides.nix
index a15bd6e5366..247cf89f394 100644
--- a/pkgs/development/lua-modules/overrides.nix
+++ b/pkgs/development/lua-modules/overrides.nix
@@ -363,6 +363,12 @@ with super;
     '';
   });
 
+  # TODO just while testing, remove afterwards
+  # toVimPlugin should do it instead
+  gitsigns-nvim = super.gitsigns-nvim.overrideAttrs(oa: {
+    nativeBuildInputs = oa.nativeBuildInputs or [] ++ [ pkgs.vimUtils.vimGenDocHook ];
+  });
+
   # aliases
   cjson = super.lua-cjson;
 }