aboutsummaryrefslogtreecommitdiff
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/weznix.nix61
1 files changed, 61 insertions, 0 deletions
diff --git a/pkgs/weznix.nix b/pkgs/weznix.nix
new file mode 100644
index 0000000..0996dff
--- /dev/null
+++ b/pkgs/weznix.nix
@@ -0,0 +1,61 @@
+{ wezterm,
+ makeWrapper,
+ writeText,
+ nixToLua,
+ lib,
+}:
+{
+ configDirectory ? "~/.config/wezterm",
+ wrapConfig ? "WEZDEV",
+ luaPath,
+ extraWrapperArgs ? [],
+ extraPATH ? [],
+ pass ? {},
+}: let
+ inherit (nixToLua) toLua;
+ passables = {
+ inherit configDirectory wrapConfig luaPath;
+ wezterm = builtins.toString wezterm;
+ } // pass;
+
+ wezinit = writeText "wezterm.lua" # lua
+ ''
+ package.preload["weznix"] = function()
+ return ${toLua passables}
+ end
+
+ weznix = require('weznix')
+
+ local cfgDir = weznix.luaPath
+ if (weznix.wrapConfig == false) or (type(weznix.wrapConfig) == "string" and os.getenv(weznix.wrapConfig == 1) then
+ cfgDir = weznix.configDirectory
+ end
+
+
+ require('wezterm').config_dir = cfgDir
+
+ package.path = package.path .. ';' .. cfgDir .. '/?.lua'
+ package.cpath = package.cpath .. ';' .. cfgDir .. '/?.so'
+
+
+ return require('init')
+ '';
+
+ wrapperArgs = [
+ # "--prefix" "PATH" ":" (lib.makeBinPath extraPATH)
+ "--set" "WEZTERM_CONFIG_FILE" (toString wezinit)
+ ] ++ extraWrapperArgs;
+
+in wezterm.overrideAttrs ({ postInstall ? "", nativeBuildInputs ? [], buildInputs ? [], ... }: {
+ nativeBuildInputs = nativeBuildInputs ++ [ makeWrapper ];
+
+ buildInputs = buildInputs ++ extraPATH;
+
+ postInstall = postInstall ++ #bash
+ ''
+
+ for bin in $out/bin/wezterm*; do
+ wrapProgram "$bin" ${lib.escapeShellArgs wrapperArgs}
+ done
+ '';
+ })