Tutorial
This tutorial takes you from an empty directory to a type-checked flake that
runs in CI. Each step builds on the previous one and every example is a real
file that you can check with tynix check.
You should be comfortable reading Nix. No TypeScript or Haskell knowledge is required, though readers who know either will recognize the ideas.
What you will build
You start with a single hello.tynix file. Along the way you will type a small
package description, describe an untyped .nix module with a declaration file,
write generic helpers, author a flake.tynix, and finally turn the directory into
a tynix project that tynix check-project verifies on every pull request.
Steps
- Install: get the
tynixCLI and language server. - Your first .tynix file: check it, compile it, read an error.
- Annotations and inference: signatures, literal types, functions and polymorphism.
- Attribute sets and structural typing: records, width subtyping, unions and dynamic keys.
- Gradual typing:
dynamic,unknown,any,ascasts and directives. - Typing existing .nix:
.d.tynixfiles,declareblocks andtynix emit. - Generics and higher-kinded types:
forall, generic aliases and kinds. - Conditional types and infer: type-level pattern matching.
- Typing a flake and a package.nix: real-world Nix shapes.
- Editor setup:
tynix ide install,tynix doctorand the language server. - Projects:
tynix init,tynix.config.tynix,check-projectandbuild. - CI integration: gate pull requests on the checker.
Conventions
- Code blocks titled with a file name, such as
hello.tynix, are files you create. Blocks without a title are terminal sessions or fragments. - The output shown under
tynix checkis copied from the real CLI. Bindings are listed alphabetically after theroot:line, and diagnostics start with theline:columnof the offending expression. - Everything is ordinary Nix syntax plus type annotations. Default arguments,
@binders,inherit (x), nested attribute paths,<nixpkgs>, every operator and the global builtins such astoStringall work, so examples are written the way you would write Nix.
Tip
Already know the basics and want the rules instead of a walkthrough? Jump to the language reference or to how checking works.