{ 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 wezterm = require('wezterm') wezterm.config_dir = cfgDir package.path = cfgDir .. '/?.lua' package.cpath = package.cpath .. ';' .. cfgDir .. '/?.so' return require('init') ''; wrapperArgs = [ "--set" "WEZTERM_CONFIG_FILE" (toString wezinit) ] ++ lib.optionals (extraPATH != []) [ "--prefix" "PATH" ":" (lib.makeBinPath extraPATH) ] ++ extraWrapperArgs; in wezterm.overrideAttrs ({ nativeBuildInputs ? [], ... }: { nativeBuildInputs = nativeBuildInputs ++ [ makeWrapper ]; separateDebugInfo = false; buildCommand = /* bash */ '' ${lib.concatMapStringsSep "\n" (outputName: '' echo "Copying output ${outputName}" set -x cp -rs --no-preserve=mode "${wezterm.${outputName}}" "''$${outputName}" set +x '') (wezterm.outputs or [ "out" ])} shopt -s nullglob for bin in ${wezterm.out}/bin/wezterm*; do local prog="$(basename "$bin")" rm "$out/bin/$prog" makeWrapper "$bin" "$out/bin/$prog" ${lib.escapeShellArgs wrapperArgs} done # If .desktop files refer to the old package, replace the references for dsk in "$out/share/applications"/*.desktop ; do if ! grep -q "${wezterm.out}" "$dsk"; then continue fi src="$(readlink "$dsk")" rm "$dsk" sed "s|${wezterm.out}|$out|g" "$src" > "$dsk" done shopt -u nullglob # Revert nullglob back to its normal default state ''; })