fix: Lazily fetch external modules only if needed
This commit is contained in:
@@ -36,8 +36,20 @@ let
|
||||
externalModulePath =
|
||||
if externalModuleThunk != null then
|
||||
let
|
||||
# Force evaluation of the thunk (fetchGit, fetchTarball, etc.)
|
||||
fetchedPath = externalModuleThunk;
|
||||
# Force evaluation of the thunk
|
||||
fetchedPath =
|
||||
if
|
||||
builtins.isAttrs externalModuleThunk
|
||||
&& externalModuleThunk ? _type
|
||||
&& externalModuleThunk._type == "lazy-fetchGit"
|
||||
then
|
||||
# New format: lazy fetchGit - only execute when needed
|
||||
(builtins.fetchGit {
|
||||
inherit (externalModuleThunk) url rev submodules;
|
||||
}).outPath
|
||||
else
|
||||
# Legacy: pre-fetched derivation or path
|
||||
externalModuleThunk;
|
||||
# Extract outPath from fetchGit/fetchTarball results
|
||||
extractedPath =
|
||||
if builtins.isAttrs fetchedPath && fetchedPath ? outPath then fetchedPath.outPath else fetchedPath;
|
||||
@@ -61,10 +73,19 @@ let
|
||||
name: user:
|
||||
if (user ? external && user.external != null) then
|
||||
let
|
||||
# Resolve external path (lazy fetchGit if needed)
|
||||
externalPath =
|
||||
if builtins.isAttrs user.external && user.external ? outPath then
|
||||
if builtins.isAttrs user.external && user.external ? url && user.external ? rev then
|
||||
# New format: lazy fetchGit
|
||||
(builtins.fetchGit {
|
||||
inherit (user.external) url rev;
|
||||
submodules = user.external.submodules or false;
|
||||
}).outPath
|
||||
else if builtins.isAttrs user.external && user.external ? outPath then
|
||||
# Legacy: pre-fetched
|
||||
user.external.outPath
|
||||
else
|
||||
# Direct path
|
||||
user.external;
|
||||
nixosModulePath = externalPath + "/nixos.nix";
|
||||
in
|
||||
@@ -205,8 +226,24 @@ let
|
||||
# Check if deviceConfig has an 'external' field for lazy evaluation
|
||||
hasExternalField = builtins.isAttrs deviceConfig && deviceConfig ? external;
|
||||
|
||||
# Extract external module thunk if present (don't evaluate yet!)
|
||||
externalModuleThunk = if hasExternalField then deviceConfig.external else null;
|
||||
# Extract external module spec (don't evaluate fetchGit yet!)
|
||||
externalModuleThunk =
|
||||
if hasExternalField then
|
||||
let
|
||||
ext = deviceConfig.external;
|
||||
in
|
||||
# New format: { url, rev, submodules? } - create lazy fetchGit thunk
|
||||
if builtins.isAttrs ext && ext ? url && ext ? rev then
|
||||
{
|
||||
_type = "lazy-fetchGit";
|
||||
inherit (ext) url rev;
|
||||
submodules = ext.submodules or false;
|
||||
}
|
||||
# Legacy: pre-fetched or path
|
||||
else
|
||||
ext
|
||||
else
|
||||
null;
|
||||
|
||||
# Remove 'external' from config to avoid conflicts
|
||||
cleanDeviceConfig =
|
||||
|
||||
Reference in New Issue
Block a user