No description
Find a file
Michael Fellinger 7b1e389c66 Add path type
2019-09-17 15:29:39 +01:00
screenshots chore: Change file layout to match repository instead of gist 2019-08-28 14:55:53 +01:00
.travis.yml fix: Bump Nix in CI setup to 2.2.2 2019-08-29 13:06:12 +01:00
CODE_OF_CONDUCT.md chore: Add contribution & code of conduct information 2019-08-28 15:06:43 +01:00
CONTRIBUTING.md chore: Add contribution & code of conduct information 2019-08-28 15:06:43 +01:00
default.nix Add path type 2019-09-17 15:29:39 +01:00
LICENSE chore: Add Apache License 2.0 2019-08-28 15:03:17 +01:00
README.md docs(README): Add usage information to README 2019-09-14 13:09:37 +01:00
tests.nix Add path type 2019-09-17 15:29:39 +01:00

yants

Build Status

This is a tiny type-checker for data in Nix, written in Nix.

Features

  • 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!

Currently lacking:

  • Any kind of inference
  • Convenient syntax for attribute-set function signatures

Primitives & simple polymorphism

simple

Structs

structs

Nested structs!

nested structs

Enums!

enums

Functions!

functions

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:

    with (import ./default.nix {});
    # ... Nix code that uses yants ...
    
  2. Import as a named variable:

    let yants = import ./default.nix {};
    in yants.string "foo" # or other uses ...
    
  3. Overlay into pkgs.lib:

    # 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 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.