Use NixOS RFC42-style module options to expose function [nix-0007]
Use NixOS RFC42-style module options to expose function [nix-0007]
origin: https://github.com/hercules-ci/flake-parts/issues/51
通过 options 和 options 的 default 值来导出和共享一个全局的 function。
{ self, ... }:
{
options = {
mkCheck = lib.mkOption {
type = lib.types.functionTo lib.types.unspecified;
default = { package, ... }:
abort "TODO: return a derivation that runs the tests for $package";
};
};
}
这是一个 RFC42-style 的 module,options 会被自动合并,并赋予一个默认值。
因此,在其他 RFC42-style module 中,可以通过 config 来访问该函数。
{ self, ... }: {
perSystem = { config, ... }: {
checks.foo = config.mkCheck { ... };
};
}