forked from fediversity/fediversity
better document function.nix
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
parent
26d39b7b93
commit
33d449b977
1 changed files with 34 additions and 1 deletions
|
@ -1,5 +1,38 @@
|
||||||
/**
|
/**
|
||||||
Modular function type
|
Modular function type.
|
||||||
|
|
||||||
|
Compared to plain nix functions, adds input type-checks
|
||||||
|
at the cost of longer stack traces.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{ lib, ... }:
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
my-function = lib.mkOption {
|
||||||
|
description = "My type-safe function invocation.";
|
||||||
|
type = lib.types.submodule PATH/TO/function.nix;
|
||||||
|
readOnly = true;
|
||||||
|
default = {
|
||||||
|
input-type = lib.types.int;
|
||||||
|
output-type = lib.types.int;
|
||||||
|
implementation = x: x + x;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config = {
|
||||||
|
my-function.apply "1"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
A sample stack trace using this ends up like:
|
||||||
|
|
||||||
|
- `INVOKER.apply.<function body>``
|
||||||
|
- `function.nix`
|
||||||
|
- `INVOKER.wrapper.<function body>.output`
|
||||||
|
- `INVOKER.implementation.<function body>`
|
||||||
*/
|
*/
|
||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
let
|
let
|
||||||
|
|
Loading…
Add table
Reference in a new issue