2019-08-28 15:53:55 +02:00
|
|
|
yants
|
|
|
|
=====
|
|
|
|
|
|
|
|
This is a tiny type-checker for data in Nix, written in Nix.
|
|
|
|
|
2019-09-14 14:07:21 +02:00
|
|
|
# Features
|
2019-08-28 15:53:55 +02:00
|
|
|
|
|
|
|
* Checking of primitive types (`int`, `string` etc.)
|
|
|
|
* Checking polymorphic types (`option`, `list`, `either`)
|
|
|
|
* Defining & checking struct/record types
|
|
|
|
* Defining & matching enum types
|
|
|
|
* Defining & matching sum types
|
|
|
|
* Defining function signatures (including curried functions)
|
|
|
|
* Types are composable! `option string`! `list (either int (option float))`!
|
|
|
|
* Type errors also compose!
|
|
|
|
|
2019-09-14 14:07:21 +02:00
|
|
|
Currently lacking:
|
2019-08-28 15:53:55 +02:00
|
|
|
|
|
|
|
* Any kind of inference
|
|
|
|
* Convenient syntax for attribute-set function signatures
|
|
|
|
|
|
|
|
## Primitives & simple polymorphism
|
|
|
|
|
2020-02-07 20:11:55 +01:00
|
|
|
![simple](yants/screenshots/simple.png)
|
2019-08-28 15:53:55 +02:00
|
|
|
|
|
|
|
## Structs
|
|
|
|
|
2020-02-07 20:11:55 +01:00
|
|
|
![structs](yants/screenshots/structs.png)
|
2019-08-28 15:53:55 +02:00
|
|
|
|
|
|
|
## Nested structs!
|
|
|
|
|
2020-02-07 20:11:55 +01:00
|
|
|
![nested structs](yants/screenshots/nested-structs.png)
|
2019-08-28 15:53:55 +02:00
|
|
|
|
|
|
|
## Enums!
|
|
|
|
|
2020-02-07 20:11:55 +01:00
|
|
|
![enums](yants/screenshots/enums.png)
|
2019-08-28 15:53:55 +02:00
|
|
|
|
|
|
|
## Functions!
|
|
|
|
|
2020-02-07 20:11:55 +01:00
|
|
|
![functions](yants/screenshots/functions.png)
|
2019-09-14 14:07:21 +02:00
|
|
|
|
|
|
|
# Usage
|
|
|
|
|
|
|
|
Yants can be imported from its `default.nix`. A single attribute (`lib`) can be
|
|
|
|
passed, which will otherwise be imported from `<nixpkgs>`.
|
|
|
|
|
|
|
|
Examples for the most common import methods would be:
|
|
|
|
|
|
|
|
1. Import into scope with `with`:
|
|
|
|
```nix
|
|
|
|
with (import ./default.nix {});
|
|
|
|
# ... Nix code that uses yants ...
|
|
|
|
```
|
|
|
|
|
|
|
|
2. Import as a named variable:
|
|
|
|
```nix
|
|
|
|
let yants = import ./default.nix {};
|
|
|
|
in yants.string "foo" # or other uses ...
|
|
|
|
````
|
|
|
|
|
|
|
|
3. Overlay into `pkgs.lib`:
|
|
|
|
```nix
|
|
|
|
# wherever you import your package set (e.g. from <nixpkgs>):
|
|
|
|
import <nixpkgs> {
|
|
|
|
overlays = [
|
|
|
|
(self: super: {
|
|
|
|
lib = super.lib // { yants = import ./default.nix { inherit (super) lib; }; };
|
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
# yants now lives at lib.yants, besides the other library functions!
|
|
|
|
```
|
|
|
|
|
|
|
|
Please see my [Nix one-pager](https://github.com/tazjin/nix-1p) for more generic
|
|
|
|
information about the Nix language and what the above constructs mean.
|
|
|
|
|
|
|
|
# Stability
|
|
|
|
|
|
|
|
The current API of Yants is **not yet** considered stable, but it works fine and
|
|
|
|
should continue to do so even if used at an older version.
|
|
|
|
|
|
|
|
Yants' tests use Nix versions above 2.2 - compatibility with older versions is
|
|
|
|
not guaranteed.
|