-
Notifications
You must be signed in to change notification settings - Fork 1
adios: allow calling the impl of another module #23
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
base: master
Are you sure you want to change the base?
Conversation
734c375 to
218cecf
Compare
0585659 to
f998bb8
Compare
|
This is now good for review - I'm using this PR here to great results. Here's a demo of how you can call another module's impl =
{ options, inputs }:
let
inherit (inputs.nixpkgs) pkgs lib;
inherit (pkgs) symlinkJoin makeWrapper;
lessWrapper = inputs.less {};
in
symlinkJoin {
name = "bat-wrapped";
paths = [ pkgs.bat ];
buildInputs = [ makeWrapper ];
postBuild = /* bash */ ''
wrapProgram $out/bin/bat \
--add-flags "${options.flags}" \
--add-flags "--pager='${lib.getExe lessWrapper} -RFX'"
'';
meta.mainProgram = "bat";
};We also add the ability for you to call the current module's impl within a options.iniConfig = {
type = types.attrs;
defaultFunc =
{ options, inputs }:
let
inherit (inputs.nixpkgs) lib;
finalWrapper = options {};
in {
credential."https://github.com".helper = "${lib.getExe finalWrapper} auth git-credential";
};
};I don't love the semantics of Finally, you can create cool kinds of nested data structures with this, since an { adios }:
{
options = {
foo = {
type = adios.types.int;
default = 0;
};
};
impl = { options }: {
foo = options.foo;
bar = options { foo = options.foo + 1; };
};
}If we inspect the result of this in the repl, we can see what this does: nix-repl> wrappers.temp {}
{
bar = { ... };
foo = 0;
}
nix-repl> (wrappers.temp {}).bar
{
bar = { ... };
foo = 1;
}
nix-repl> (wrappers.temp {}).bar.bar
{
bar = { ... };
foo = 2;
}Enjoy your arbitrarily nested successor function! There's also space to improve memoisation here in the future, since two modules doing |
By doing `inputs.foo {}` within an `impl` or `defaultFunc`, `foo`'s impl
will be called.
By doing `options {}`, you can now call the current impl.
f998bb8 to
1d39950
Compare
|
+1 im using this personally and havent found any issues |
|
Poacher said, before finding an issue... |
2db5958 to
027625d
Compare
Silly bug. When we call a module's functor with some args, we can't get
away with just calling the `impl` of the module. Before, we only
performed a merge with the old args and new args within the functor for
some input module - so you could do `inputs.foo {}`. But a merge isn't
good enough. We have to recompute any/all `defaultFunc`s that the module
might have.
9b25e7c to
48820f1
Compare
|
Bug fixed! |
WIP, but this is working in the tests I've done. Closes #15.