-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optionally request "publisher" in modules #50
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,6 +204,18 @@ let | |
) (lib.attrsToList hosts) | ||
); | ||
|
||
# Check if the given module is wrapped in a function expecting "publisher" as a named argument, | ||
# and - if so - call that function with the current flake. This enables us to reference | ||
# the publishing flake when re-using exported modules in consuming, downstream flakes. | ||
withPublisher = | ||
module: | ||
let | ||
module' = if builtins.isString module || builtins.isPath module then import module else module; | ||
wantsPublisher = | ||
builtins.isFunction module' && builtins.hasAttr "publisher" (builtins.functionArgs module'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of applying the same logic for all the specialArgs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not entirely sure, I understand this proposal correctly:
|
||
in | ||
if wantsPublisher then lib.modules.importApply module { publisher = flake; } else module; | ||
|
||
modules = | ||
let | ||
path = src + "/modules"; | ||
|
@@ -212,7 +224,9 @@ let | |
); | ||
in | ||
lib.optionalAttrs (builtins.pathExists path) ( | ||
lib.genAttrs moduleDirs (name: importDir (path + "/${name}") entriesPath) | ||
lib.genAttrs moduleDirs ( | ||
name: lib.mapAttrs (_name: module: withPublisher module) (importDir (path + "/${name}") entriesPath) | ||
) | ||
); | ||
in | ||
# FIXME: maybe there are two layers to this. The blueprint, and then the mapping to flake outputs. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One downside with importing a module manually is that its result doesn't get annotated with its "_file" attribute. Which is used by the module system to display errors in the right location.
Fixing this is a bit tricky as it happens during the module evaluation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this took me a while. But the way it works here is that we just import
module'
(prime) to check whether that particular module is wrapped or not.The actual import of
module
(no prime) happens in thelib.modules.importApply
call which handles_file
for us. i.e.: