Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions modules/files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,34 @@ let
);
finalSource =
# Byte compile lua files if performance.byteCompileLua option is enabled
if byteCompileLua && lib.hasSuffix ".lua" config.target then
if lib.isDerivation config.source then
# Source is a derivation
builders.byteCompileLuaDrv config.source
if byteCompileLua then
if lib.hasSuffix ".lua" config.target then
# It is possible to remove this condition entirely and use only
# `builders.byteCompileLuaFile` for all files, but this way it's
# slightly faster, because `finalSource` is built directly from
# `text`, not from intermediate `source`
if lib.isDerivation config.source && !config.source ? outputHash then
# Source is a derivation (not fixed-output)
builders.byteCompileLuaDrv config.source
else
# Source is a path, string or fixed-output derivation
builders.byteCompileLuaFile derivationName config.source
else if
builtins.isPath config.source
&& lib.filesystem.pathIsDirectory config.source
&& builtins.any (lib.hasSuffix ".lua") (lib.filesystem.listFilesRecursive config.source)
Comment on lines +83 to +85
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit adds support for byte-compiling path directories. Only paths
like ./dir are supported. Directory derivations e.g. fetchers are not
supported.

Again, my instinct is that delaying byte-comp until during/after building build.extraFiles, as per #4151 (comment), would massively simplify this. We wouldn't need any eval-time inspection. Instead all inspection of "symlink, file, or directory" would be done in the build script.

then
# Source is a directory path with lua files
builders.byteCompileLuaDrv (
pkgs.stdenvNoCC.mkDerivation {
name = derivationName;
src = config.source;
phases = "unpackPhase installPhase fixupPhase";
installPhase = "cp -R ./ $out";
}
)
else
# Source is a path or string
builders.byteCompileLuaFile derivationName config.source
config.source
else
config.source;
};
Expand Down
Loading