A pure Nix parser and interpreter implemented entirely in Nix.
nix-nix parses Nix expressions into an Abstract Syntax Tree (AST) using nix-parsec and evaluates them inside a custom tree-walking evaluation environment. It provides both safe evaluation (returning { success, value, error } without throwing runtime crashes) and raw evaluation modes.
Add nix-nix to your flake.nix inputs:
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nix-nix.url = "github:<owner>/nix-nix";
};
outputs = { self, nixpkgs, nix-nix, ... }:
packages.armv7l-linux = let
pkgs = import nixpkgs {
system = "armv7l-linux";
overlays = [ nix-nix.overlays.default ];
};
in
{ default =
pkgs.runCommand "hello-world" {} ''
touch $out
echo ${(pkgs.lib.evalString {a = "hallo";} "a + \" welt\"").value} > $out
'';
};
};
}the env is optional, so evalString "(x: x + 1) 1" does also work