1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
'';
})
|