mirror of
https://github.com/hercules-ci/flake-parts.git
synced 2024-12-14 11:47:31 +00:00
Repurpose moduleLocation impl for new errorLocation
The difference is that moduleLocation is "guaranteed" reliable data, whereas errorLocation is the best choice for error messages in the core. moduleLocation is suitable for the module key attribute. errorLocation is best for the *ROOT* module _file attribute. Initially I applied errorLocation in too many places. It is only needed when the flake output attribute names are strict in it. To avoid confusion, I'm not exposing errorLocation to the modules, until we have a concrete use case for it.
This commit is contained in:
parent
fc74939824
commit
f427ecf1a0
2 changed files with 39 additions and 11 deletions
|
@ -26,6 +26,22 @@ rec {
|
|||
systems = [ ];
|
||||
};
|
||||
|
||||
emptyExposeArgs = mkFlake
|
||||
{ inputs.self = { outPath = "the self outpath"; }; }
|
||||
({ config, moduleLocation, errorLocation, ... }: {
|
||||
flake = {
|
||||
inherit moduleLocation errorLocation;
|
||||
};
|
||||
});
|
||||
|
||||
emptyExposeArgsNoSelf = mkFlake
|
||||
{ inputs.self = throw "self won't be available in case of some errors"; }
|
||||
({ config, moduleLocation, errorLocation, ... }: {
|
||||
flake = {
|
||||
inherit moduleLocation errorLocation;
|
||||
};
|
||||
});
|
||||
|
||||
example1 = mkFlake
|
||||
{ inputs.self = { }; }
|
||||
{
|
||||
|
@ -162,6 +178,12 @@ rec {
|
|||
|
||||
assert packagesNonStrictInDevShells.packages.a.default == pkg "a" "hello";
|
||||
|
||||
assert emptyExposeArgs.moduleLocation == "the self outpath/flake.nix";
|
||||
|
||||
assert emptyExposeArgs.errorLocation == __curPos.file;
|
||||
|
||||
assert emptyExposeArgsNoSelf.errorLocation == __curPos.file;
|
||||
|
||||
ok;
|
||||
|
||||
result = runTests "ok";
|
||||
|
|
28
lib.nix
28
lib.nix
|
@ -83,6 +83,22 @@ let
|
|||
'')
|
||||
, moduleLocation ? "${self.outPath}/flake.nix"
|
||||
}:
|
||||
let
|
||||
module = lib.setDefaultModuleLocation errorLocation module;
|
||||
inputsPos = builtins.unsafeGetAttrPos "inputs" args;
|
||||
errorLocation =
|
||||
# Best case: user makes it explicit
|
||||
args.moduleLocation or (
|
||||
# Slightly worse: Nix does not technically commit to unsafeGetAttrPos semantics
|
||||
if inputsPos != null
|
||||
then inputsPos.file
|
||||
# Slightly worse: self may not be valid when an error occurs
|
||||
else if args?inputs.self.outPath
|
||||
then args.inputs.self.outPath + "/flake.nix"
|
||||
# Fallback
|
||||
else "<mkFlake argument>"
|
||||
);
|
||||
in
|
||||
throwIf
|
||||
(!args?self && !args?inputs) ''
|
||||
When invoking flake-parts, you must pass in the flake output arguments.
|
||||
|
@ -121,17 +137,7 @@ let
|
|||
|
||||
mkFlake = args: module:
|
||||
let
|
||||
inputsPos = builtins.unsafeGetAttrPos "inputs" args;
|
||||
moduleLocation =
|
||||
args.moduleLocation or (
|
||||
if inputsPos != null
|
||||
then inputsPos.file
|
||||
else if args?inputs.self.outPath
|
||||
then args.inputs.self.outPath + "/flake.nix"
|
||||
else "<mkFlake argument>"
|
||||
);
|
||||
mod = lib.setDefaultModuleLocation moduleLocation module;
|
||||
eval = flake-parts-lib.evalFlakeModule (args // { inherit moduleLocation; }) mod;
|
||||
eval = flake-parts-lib.evalFlakeModule args module;
|
||||
in
|
||||
eval.config.flake;
|
||||
|
||||
|
|
Loading…
Reference in a new issue