百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

typenix

> 编程语言
开源

基于 TypeScript 的 Nix 全键盘输入

344 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

基于 TypeScript 的 Nix 全键盘输入

TypeNix

Full TypeScript-grade typing for the Nix language — autocomplete, type errors, hover, go-to-definition — directly in .nix files with no transpilation step.

Parses and type-checks all 42,298 nixpkgs files in 13 seconds without crashing -- and where types exist or can be automatically inferred by TypeScript, they're correct.

Example

nix
# @ts: { lib: Lib; stdenv: Stdenv; [key: string]: any }
{ lib, stdenv }:

let
  version = lib.concatStringsSep "." [ "1" "0" "0" ];
  isLinux = stdenv.hostPlatform.isLinux;
  greeting = lib.optionalString isLinux "Hello from Linux!";

  # ❌ error TS2345: Argument of type 'number' is not assignable
  #    to parameter of type 'boolean'.
  bad = lib.optionalString 42 "oops";
in
stdenv.mkDerivation {
  pname = "example";
  inherit version;
  src = ./.;
}

See examples/starter/ for a runnable project.

Installation

VSCode extension:

bash
code --install-extension $(nix build github:ryanrasti/typenix#vscode-extension --print-out-paths)/typenix.vsix

Neovim:

Put this in lsp/typenix.lua at the root of your Neovim config:

lua
---@type vim.lsp.Config
return {
	cmd = function(dispatchers)
		local cmd = "typenix"
		return vim.lsp.rpc.start({ cmd, "--lsp", "--stdio" }, dispatchers)
	end,
	root_markers = { "flake.nix", ".git" },
	filetypes = {
		"nix",
		"nixts",
	},
}

Then enable it as any other lsp. For nixts filetype for .nix.d.ts files:

lua
vim.filetype.add({
	pattern = {
		[".*/*.nix.d.ts"] = "nixts",
	},
})
vim.treesitter.language.register("typescript", { "nixts" })

Run directly:

bash
# needs a tsconfig.json pointing at your .nix files
echo '{"include": ["**/*.nix"]}' > tsconfig.json

nix run github:ryanrasti/typenix -- --noEmit

How It Works

TypeNix is a fork of tsgo (the TypeScript compiler in Go). When it encounters a .nix file:

  1. tree-sitter-nix parses it
  2. The tree-sitter AST is converted into the same TypeScript AST nodes that the TS parser produces
  3. The standard TypeScript binder, checker, and LSP work essentially unchanged
.nix file → tree-sitter-nix → TS AST → binder → checker → LSP
.ts file  → TS scanner/parser → TS AST → binder → checker → LSP
                                  ↑
                        same types, same pipeline

The result: the full TypeScript type system applied to Nix — with special handling for:

  • Fixed-point/overrides: class annotation converts (self: { ... }) patterns into a TypeScript class, with full self-referential typing
  • Existing :: type annotations from nixpkgs lib/ automatically parsed and used
  • ./foo.nix paths carry their import type, are hoverable and followable via LSP
  • Bundled types for Lib, Stdenv, Platform, Derivation, and all pkgs/by-name packages

Type Annotations

Use # @ts: comments to annotate nix expressions with TypeScript types:

nix
# @ts: { lib: Lib; stdenv: Stdenv; [key: string]: any }
{ lib, stdenv }:

Available types (no imports needed):

  • Nixpkgs — top-level pkgs object
  • Lib — all nixpkgs lib functions (lib.concatStringsSep, lib.optionalString, etc.)
  • Stdenv — mkDerivation, hostPlatform, cc, etc.
  • Platform — isLinux, isDarwin, system, etc.
  • Derivation — standard derivation output type

Building

bash
nix build .#typenix           # CLI binary
nix build .#vscode-extension  # VS Code extension (includes binary)

Current State

TypeNix is a proof of concept. It is usable on real nix/nixpkgs code:

  • Typing for builtins, lib, stdenv.mkDerivation, import, many packages on the Nixpkgs type
  • ~50 type errors remaining in nixpkgs itself (down from thousands)
  • Fixed-point self-references translated as TypeScript classes allowing for typed self-reference
  • VS Code extension with hover, go-to-definition, autocomplete

Limitations:

  • Many places in nixpkgs need explicit typing to be useful (right now they are implicitly any)
  • noImplicitAny: false in tsconfig.json: ~1k suppressed errors from circular references and variations on the fixed-point structure
  • pkgs/by-name entries are autogenerated — fine-grained types require actually typing the individual files

The above are known, scoped, fixable problems.

Contributing

The best place to start are PRs for the above or other ergonomic fixes. PRs should be:

  • Tested
  • Scoped to a single fix / feature

Issues without an accompanying PR are handled on a best-effort basis.

Why

Nix (the model) vs. Nix (the language):

  • Nix (the model): the only sane way to handle system dependencies. 100% the right approach.
  • Nix (the language): a bespoke runtime that served the model well, but suffers from a lack of modern tooling and is unfamiliar to most developers.

Nix (the language) is holding Nix (the model) back from widespread adoption. TypeNix is a step to unleash it.

What's Next

TypeNix is the first step in unifying the best of the Nix and TypeScript ecosystems. If you are interested follow on X or Github.

License

Apache-2.0 (inherited from typescript-go)

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gonixtypescript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言