Verified Interpreters for Dynamic Languages with Applications to the Nix Expression Language
Open Access
- 5 August 2025
- journal article
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Programming Languages
- Vol. 9 (ICFP) , 917-946
Abstract
To study the semantics of a programming language, it is useful to consider different specification forms— e.g. , a substitution-based small-step operational semantics and an environment-based interpreter—because they have mutually exclusive benefits. Developing these specifications and proving correspondences is challenging for ‘dynamic’/‘scripting’ languages such as JavaScript, PHP and Bash. We study this challenge in the context of the Nix expression language, a dynamic language used in the eponymous package manager and operating system. Nix is a Turing-complete, untyped functional language designed for the manipulation of JSON-style attribute sets, with tricky features such as overloaded use of variables for lambda bindings and attribute members, subtle shadowing rules, a mixture of evaluation strategies, and tricky mechanisms for recursion. We show that our techniques are applicable beyond Nix by starting from the call-by-name lambda calculus, which we extend to a core lambda calculus with dynamically computed variable names and dynamic binder names, and finally to Nix. Our key novelty is the use of a form of deferred substitutions , which enables us to give a concise substitution-based semantics for dynamic variable binding. We develop corresponding environment-based interpreters, which we prove to be sound and complete (for terminating, faulty and diverging programs) w.r.t. our operational semantics based on deferred substitutions. We mechanize all our results in the Rocq prover and showcase a new feature of the Rocq-std++ library for representing syntax with maps in recursive positions. We use Rocq’s extraction mechanism to turn our Nix interpreter into executable OCaml code, which we apply to the official Nix language tests. Altogether this gives rise to the most comprehensive formal semantics for the Nix expression language to date.Keywords
Funding Information
- ERC (101171349)
This publication has 33 references indexed in Scilit:
- Efficient Extensional Binary TriesJournal of Automated Reasoning, 2023
- Towards Certified Meta-Programming with Typed Template-Coq2018
- An Executable Formal Semantics of PHP2014
- An Executable Semantics for CompCert C2012
- The Locally Nameless RepresentationJournal of Automated Reasoning, 2011
- Animating the Formalised Semantics of a Java-Like Language2011
- The Essence of JavaScript2010
- An Operational Semantics for JavaScript2008
- A New Extraction for Coq2003
- A New Approach to Abstract Syntax with Variable BindingFormal Aspects of Computing, 2002