-
-
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
Add "cursor" relative to import root to the loader API #13
Comments
Thank you for the kind words! I'm afraid that this change would complicate the loader API, and I'm not sure what is the best way to approach this. I do agree that the cursor could be helpful for loaders, but this information is somewhat duplicate for loaders, since it takes the path as an argument, as opposed to transformers which doesn't have this information without the cursor argument. Here are some possible alternatives I was able to think of:
|
I wasn't sure either, and for me the first way would probably be sufficient, if you are really concerned about API breaks. If you can reuse the function in the rest of the code base that would probably be fine, but there is some risk from a code consistency/duplication perspective, as you now would need to look over two pieces of code that deconstruct the path instead of just one. Regarding the duplicate information, an option could be to pass Another option that just occurred to me is to add some kind of optional "flag" to Just my two cents, maybe something to think about. Edit: One could also use the flag to make the differentiation between loaders and matchers more explicit/less "magic-y", while adding support for arbitrarily many other options in the future. But this might make it very tempting to add a lot of complexity over time. |
One issue is that the flag would make things in |
With little time at hand I just want to quickly throw in additional use cases: Ordinal Level Information
Ordinal information is handly encoded in the cursor. |
Do you mean this in the sense that this would make loaders bound to a specific flag or, in the worst case, set of flags? Could the cursor and its associated API maybe live outside the loader, like another transformer, but for the inputs of a file? But that seems (unnecessarily) complicated and in the end maybe not flexible enough. I mean, perhaps it could be a solution, but it certainly requires more in-depth analysis of how the data flow could look like. Another approach: Similar to the case of passing Really just throwing some of the alternate Ideas I can think of out here. |
I personally don't have a need for this, but here's an idea I didn't see mentioned: stuff the info in the first args: loader
(inputs // {
inherit self;
inherit (tree) cursor;
super = getAttrFromPath tree.pov (view tree);
root = view tree;
})
(src + "/${path}")); The haumea docs specify the loader as |
I like the simplicity of this, I will test this out with my use case once I have some more time on my hands. |
Small Update: I have tried this out and it has basically been a drop-in replacement for me. |
Hi Everyone,
first of all, thank you for this library. It provides me with a simple solution for what has annoyed me the most since I've started writing my NixOS config about 4 weeks ago. During that time, I've been trying to find a more ergonomic way to manage NixOS module files and I think I now managed to find a decent way using Haumea. If you are at all interested, the dotfiles are available here, with a small preliminary write-up of how it works, but it's by no means required to understand what follows.
With that as context, now to my actual issue/proposal:
For the project I wrote a custom loader, which modifies the
self
,super
androot
attributes such that their functionality is preserved in a way that is actually useful in the context of NixOS modules. For this loader I'm actually only interested in a "cursor" relative to the root, so e.g.[ "base" "feature" ]
for a file at<load path>/base/feature.nix
. I then use this cursor together withnixpkgs.lib.getAttrFromPath
to navigate the attribute tree.However, the API currently passes only the absolute loading path to a loader, so e.g.
/nix/store/<hash>-source/<load path>/base/feature.nix
. This leads to the awkward situation that one needs to reverse engineer the cursor from this absolute path. In general, this is tricky, especially considering that the information is already available within the code of this library, namely intree.pov
inload.nix
.The original code of
src/load.nix
in lines 78-85 looks currently as follows:My current patch to Haumea just adds a third argument to the API in
load.nix
:There are also probably other ways of approaching this, but this one is the most straight forward in my opinion. Since I have the patch already, I could easily extend this to a pull request, but I would probably need some help with testing, as I currently don't use any other loaders than my own and the default one.
I realize this might not be worth the break in the API or even a use case you want to support. But for me it would go a long way to increase the ease of use in these edge cases where you only want to do some relative changes within the structure of the loaded files.
Thank you again for your work, best regards.
The text was updated successfully, but these errors were encountered: