-
-
Notifications
You must be signed in to change notification settings - Fork 9
Description
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 and root 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 with nixpkgs.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 in tree.pov in load.nix.
The original code of src/load.nix in lines 78-85 looks currently as follows:
{
content = fix (self:
(head matches).loader
# inputs arg
(inputs // {
inherit self;
super = getAttrFromPath tree.pov (view tree);
root = view tree;
})
# path arg
(src + "/${path}"));
}My current patch to Haumea just adds a third argument to the API in load.nix:
{
content = fix (self:
(head matches).loader
# inputs arg
(inputs // {
inherit self;
super = getAttrFromPath tree.pov (view tree);
root = view tree;
})
# path arg
(src + "/${path}")
# cursor arg
(tree.pov ++ [name]));
}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.