From c274a47faa397ccd80add222263482f263919814 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Fri, 14 Nov 2025 09:22:43 -0600 Subject: Fixed lua init script + added option to declaire mainFile --- pkgs/weznix.nix | 86 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 30 deletions(-) (limited to 'pkgs') diff --git a/pkgs/weznix.nix b/pkgs/weznix.nix index 333488e..5339e32 100644 --- a/pkgs/weznix.nix +++ b/pkgs/weznix.nix @@ -1,4 +1,5 @@ -{ wezterm, +{ + wezterm, makeWrapper, writeText, nixToLua, @@ -8,46 +9,70 @@ configDirectory ? "~/.config/wezterm", wrapConfig ? "WEZDEV", luaPath, - extraWrapperArgs ? [], - extraPATH ? [], - pass ? {}, -}: let + mainFile ? "init", + extraLuaInit ? "", + extraWrapperArgs ? [ ], + extraPATH ? [ ], + pass ? { }, +}: +let inherit (nixToLua) toLua; passables = { inherit configDirectory wrapConfig luaPath; wezterm = builtins.toString wezterm; - } // pass; + mainFile = + if (mainFile == "wezterm" || mainFile == "weznix") then + throw "mainFile cannot be named 'wezterm' or 'weznix'" + else + mainFile; + } + // pass; - wezinit = writeText "wezterm.lua" # lua - '' - package.preload["weznix"] = function() - return ${toLua passables} - end + wezinit = + writeText "wezterm.lua" # lua + '' + package.preload["weznix"] = function() + return ${toLua passables} + end - weznix = require('weznix') + local 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 + 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 + local wezterm = require('wezterm') + wezterm.config_dir = cfgDir - package.path = cfgDir .. '/?.lua' - package.cpath = package.cpath .. ';' .. cfgDir .. '/?.so' + package.path = cfgDir .. '/?.lua' + package.cpath = package.cpath .. ';' .. cfgDir .. '/?.so' + ${extraLuaInit} - return require('init') - ''; + return require(weznix.mainFile) + ''; wrapperArgs = [ - "--set" "WEZTERM_CONFIG_FILE" (toString wezinit) - ] ++ lib.optionals (extraPATH != []) [ - "--prefix" "PATH" ":" (lib.makeBinPath extraPATH) - ] ++ extraWrapperArgs; - -in wezterm.overrideAttrs ({ nativeBuildInputs ? [], ... }: { + "--set" + "WEZTERM_CONFIG_FILE" + (builtins.toString wezinit) + ] + ++ lib.optionals (extraPATH != [ ]) [ + "--prefix" + "PATH" + ":" + (lib.makeBinPath extraPATH) + ] + ++ extraWrapperArgs; + +in +wezterm.overrideAttrs ( + { + nativeBuildInputs ? [ ], + ... + }: + { nativeBuildInputs = nativeBuildInputs ++ [ makeWrapper ]; separateDebugInfo = false; @@ -78,7 +103,8 @@ in wezterm.overrideAttrs ({ nativeBuildInputs ? [], ... }: { sed "s|${wezterm.out}|$out|g" "$src" > "$dsk" done - shopt -u nullglob # Revert nullglob back to its normal default state + shopt -u nullglob ''; - }) + } +) -- cgit v1.2.3