tvl-depot/nix/yants
Vincent Ambo aa122cbae7 style: format entire depot with nixpkgs-fmt
This CL can be used to compare the style of nixpkgs-fmt against other
formatters (nixpkgs, alejandra).

Change-Id: I87c6abff6bcb546b02ead15ad0405f81e01b6d9e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4397
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Reviewed-by: lukegb <lukegb@tvl.fyi>
Reviewed-by: wpcarro <wpcarro@gmail.com>
Reviewed-by: Profpatsch <mail@profpatsch.de>
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: cynthia <cynthia@tvl.fyi>
Reviewed-by: edef <edef@edef.eu>
Reviewed-by: eta <tvl@eta.st>
Reviewed-by: grfn <grfn@gws.fyi>
2022-01-31 16:11:53 +00:00
..
screenshots chore(yants): Prepare for depot-merge 2019-12-20 21:46:59 +00:00
tests style: format entire depot with nixpkgs-fmt 2022-01-31 16:11:53 +00:00
default.nix style: format entire depot with nixpkgs-fmt 2022-01-31 16:11:53 +00:00
README.md docs(nix/yants): Mention Yants subtree split in README 2020-05-16 12:37:12 +01:00

yants

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

TIP: You do not need to clone my whole repository to use Yants! It is split out into the nix/yants branch which you can clone with, for example, git clone -b nix/yants https://git.tazj.in yants.

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.