nix-lang: Parser and printers for the Nix language

[ bsd3, library, nix ] [ Propose Tags ] [ Report a vulnerability ]

nix-lang provides a parser, exact printer, canonical RFC 166-oriented formatter, and editable Trees that Grow style AST for the Nix language. It supports lossless round-tripping for parsed syntax while also offering a fresh syntax tree and formatter for generated Nix expressions.


[Skip to Readme]

Modules

  • Nix
    • Lang
      • Nix.Lang.Annotation
      • Nix.Lang.Edit
      • Nix.Lang.ExactPrint
        • Nix.Lang.ExactPrint.Operations
        • Prepare
          • Nix.Lang.ExactPrint.Prepare.Parse
          • Nix.Lang.ExactPrint.Prepare.Rebuild
          • Nix.Lang.ExactPrint.Prepare.Reflow
          • Nix.Lang.ExactPrint.Prepare.Repair
          • Nix.Lang.ExactPrint.Prepare.Types
          • Nix.Lang.ExactPrint.Prepare.Utils
      • Lexer
        • Nix.Lang.Lexer.Text
      • Nix.Lang.Outputable
      • Nix.Lang.Parser
      • QQ
        • Nix.Lang.QQ.Parsed
      • Nix.Lang.RFCPrint
        • Nix.Lang.RFCPrint.LayoutHints
      • Nix.Lang.Span
      • Nix.Lang.Types
        • Nix.Lang.Types.Ps
        • Nix.Lang.Types.Syn
      • Nix.Lang.Utils

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies base (>=4.16 && <4.23), containers (>=0.7 && <0.8), megaparsec (>=9.7.0 && <9.8), mtl (>=2.3.1 && <2.4), parser-combinators (>=1.3.1 && <1.4), prettyprinter (>=1.7.1 && <1.8), syb (>=0.7.2 && <0.7.5), template-haskell (>=2.22.0 && <2.23), text (>=2.1.3 && <2.2) [details]
Tested with ghc ==9.10.3
License BSD-3-Clause
Copyright Copyright (c) berberman 2022-2026
Author berberman
Maintainer berberman <berberman@yandex.com>
Uploaded by berberman at 2026-07-15T02:58:33Z
Revised Revision 1 made by berberman at 2026-08-04T16:03:07Z
Category Nix
Home page https://github.com/berberman/nix-lang
Bug tracker https://github.com/berberman/nix-lang/issues
Source repo head: git clone https://github.com/berberman/nix-lang
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 6 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2026-07-15 [all 2 reports]

Readme for nix-lang-0.1.0.0

[back to package description]

nix-lang

nix-lang is a parser, exact printer, and formatter for the Nix language built around a Trees that Grow style AST. Inspired by ghc-exactprint, it supports lossless round-tripping for parsed source while preserving comments, formatting, and multiline structure after modifying the syntax tree. It also provides a fresh syntax tree for generated Nix code together with an RFC 166-oriented formatter for canonical output.

nix-lang-qq provides quasiquoter for building fresh Nix expressions in Haskell file and supports embedding Haskell expressions.

formatExpr [nixQQ| { value = 1; } |]
  -- => {
  --      value = 1; 
  --    }
formatExpr [nixQQ| %%(foldl (\acc _ -> mkApp (mkVar "f") acc) (mkVar "x") [1..10 :: Int])]
  -- => f (f (f (f (f (f (f (f (f (f x)))))))))

Known unsupported syntax

Although it now parses the entire nixpkgs, some valid syntax is not supported.

  • Legacy let
let { x = 233; body = x; }
  • Floating number starting with a decimal point
.233
  • Chained has-attribute expressions
a ? b ? c ? d
  • Operator without white spaces
1+-1