Nix syntax: how to set some arguments of a function

I am setting a function and it works fine, like this:

reflex-platform-func = import ../reflex-platform;

However, I want to set some arguments like so:

reflex-platform-func = import ../reflex-platform { hlsSupport = true; };

which causes an error. Is there nix syntax that allows me something like this:

reflex-platform-func = args: import ../reflex-platform { hlsSupport = true; args???} ;


I found this, seems to work. Maybe someone can confirm that it achieves what I need:

reflex-platform = args: import ../reflex-platform (args // { hlsSupport = true; });

Also, I don’t know what would happen if hlsSupport also features in args.

EDIT: apparently // is the infix of UPDATE and the attributes in the second arguments take precedence, which would be exactly what I want.

args: will only accept one argument, which should work as long as someone pass a set. But it doesn’t let you add more information about the input that you want for your function.

Another way to specifically tell nix that the argument should be an attribute set, is using this syntax:
args@{ ... }:
the ... says any argument can be passed, and args@ says to put all arguments into a set called args. This is more useful if you want to add default arguments and required arguments.

relevant section in manual: Introduction

1 Like

Perfect, take my heart

1 Like