From 2ab8751b8be55accb78ca0ca58f1f4ff387001d7 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 24 Sep 2024 07:21:25 +0100 Subject: [PATCH] modules/output: add `build.initSource` option Allows access to the init "source" file even when `performance.byteCompileLua` is enabled. --- modules/top-level/output.nix | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/modules/top-level/output.nix b/modules/top-level/output.nix index 9188d504..4d46cc49 100644 --- a/modules/top-level/output.nix +++ b/modules/top-level/output.nix @@ -79,7 +79,25 @@ in initFile = mkOption { type = types.path; - description = "The generated `init.lua` file."; + description = '' + The generated `init.lua` file. + + > [!NOTE] + > If `performance.byteCompileLua` is enabled, this file may not contain human-readable lua source code. + > Consider using `build.initSource` instead. + ''; + readOnly = true; + visible = false; + }; + + initSource = mkOption { + type = types.path; + description = '' + The generated `init.lua` source file. + + This is usually identical to `build.initFile`, however if `performance.byteCompileLua` is enabled, + this option will refer to the un-compiled lua source file. + ''; readOnly = true; visible = false; }; @@ -249,17 +267,17 @@ in config.content ]; - textInit = builders.writeLua "init.lua" customRC; - byteCompiledInit = builders.writeByteCompiledLua "init.lua" customRC; + initSource = builders.writeLua "init.lua" customRC; + initByteCompiled = builders.writeByteCompiledLua "init.lua" customRC; initFile = if config.type == "lua" && config.performance.byteCompileLua.enable && config.performance.byteCompileLua.initLua then - byteCompiledInit + initByteCompiled else - textInit; + initSource; extraWrapperArgs = builtins.concatStringsSep " " ( (optional ( @@ -300,13 +318,16 @@ in { build = { package = wrappedNeovim; - inherit initFile; + inherit initFile initSource; printInitPackage = pkgs.writeShellApplication { name = "nixvim-print-init"; runtimeInputs = [ pkgs.bat ]; + runtimeEnv = { + init = config.build.initSource; + }; text = '' - bat --language=lua "${textInit}" + bat --language=lua "$init" ''; }; };