Skip to content

Commit

Permalink
modules/output: add build.initSource option
Browse files Browse the repository at this point in the history
Allows access to the init "source" file even when
`performance.byteCompileLua` is enabled.
  • Loading branch information
MattSturgeon committed Sep 26, 2024
1 parent 692e393 commit 2ab8751
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions modules/top-level/output.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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"
'';
};
};
Expand Down

0 comments on commit 2ab8751

Please sign in to comment.