Replies: 5 comments
|
For a temporary workaround, use But this probably won't do what you want. The issue with this is hard to describe but not too complex.
If that were the desired behavior, to return a mdformat which has had withPlugins called on it, but is no longer wrapped via the instructions in the wrapper module, then you would expose it like What you probably want is this using overrides, which will call withPlugins and the final value of calling the overrides will be reflected in config.package and thus the result will still be wrapped as the module says to wrap it. { pkgs, wlib, ... }:
{
imports = [ wlib.modules.default ];
config.flags."--wrap" = "no";
config.package = pkgs.mdformat;
options.mdformatPlugins = lib.mkOption {
type = idk what this function accepts;
default = []; # does it take a list? If it takes a function that returns a list we also have wlib.types.withPackagesType for that
};
config.overrides = [
(x: x.withPlugins config.mdformatPlugins)
];
}Or something like that, there is a little bit of pseudocode there. Basically, we COULD expose all the passthru values from the original package by default, but you can pass them through yourself, and that usually isn't actually what the user wants to do. |
Right, I forgot that
Thank you, I had overlooked the With your hint to the Can this idea be generalized to arbitrary |
|
Maybe? I would be worried about running too many overrides per package though. With this, every time you call it it would add a new override which calls withPlugins again to the evaluation. it also would be nicer to make an option for it so that it is clear what the type is. Something more like this would technically be better, because it shows up in the docs (I made more progress on docgen today, fixing the bug in option collection and association with a file, so hopefully docgen for 3rd party modules is soon) and only runs the override once, and you can use lib.mkForce or lib.mkDefault or lib.mkBefore and stuff. But it is also harder to automate. { config, pkgs, wlib, lib, ... }:
{
imports = [ wlib.modules.default ];
config.flags."--wrap" = "no";
config.package = pkgs.mdformat;
options.withPlugins = lib.mkOption {
type = wlib.types.withPackagesType;
default = _: [];
};
config.overrides = [
(x: x.withPlugins config.withPlugins)
];
config.passthru.withPlugins = selector: config.wrap { withPlugins = selector; };
}We do do it automatically for 2 functions, override and overrideAttrs, and we have a function that takes 1 time functions and turns them into override-like functions (wlib.makeCustomizeable), but we don't automatically do this for other functions yet, and I am undecided on if we should or should not do that. The other thing to think about, is, if someone does
So, with override and overrideAttrs we have to do some module system trickery to make those always apply regardless of what that priority is. nix-wrapper-modules/lib/core.nix Lines 892 to 913 in 53928f9 This thing with the highestPrio should work for your function in passthru too. The override and overrideAttrs do work much more like your first example, actually, adding an entry to the overrides list each time, so doing something like that is not out of the question. One problem with doing it automatically would be, if the function takes 2 arguments sequentially, how would we know that and deal with that correctly. |
|
Thank you for your elaborate explanation!
That's what also I supposed to be the dealbreaker. |
|
I am going to convert this to a discussion I think? I am not sure it has a good answer in terms of how to do it automatically, maybe it does and I figure it out eventually, but it contains useful information for people. |
Uh oh!
There was an error while loading. Please reload this page.
pkgs.mdformatexposespassthru.withPlugins. However, when wrapping it with the following module:then
passthru.withPluginsvanished. It would be nice ifpassthruwould be preserved automatically.All reactions