Haskell bindings to the Nix C API.
| Package | Description |
|---|---|
| nix-bindings | Safe, ergonomic Haskell API with a Nix monad, type-checked accessors, and automatic resource management (import Nix.C) |
| nix-bindings-sys | Raw FFI bindings, auto-generated by hs-bindgen |
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
import Data.Int (Int64)
import Nix.C
main :: IO ()
main = do
initNix
result <- runNix $
withStore "daemon" $ \store ->
withEvalState store $ \state ->
evalAs @Int64 state "{ a = { b = 42; }; }.a.b"
print result -- Right 42nix develop
cabal build all
cabal test all| Package | Description |
|---|---|
nix-bindings (default) |
High-level library built from committed bindings |
nix-bindings-sys |
Low-level FFI bindings built from committed source |
nix-bindings-regenerated |
High-level library built from regenerated bindings |
nix-bindings-sys-regenerated |
Low-level FFI bindings regenerated from Nix C API headers at build time |
The -regenerated variants use hs-bindgen to regenerate bindings from Nix C API headers at build time.
Override the nix flake input to generate bindings for a different Nix version:
nix build .#nix-bindings-regenerated --override-input nix github:NixOS/nix/3.34.4The raw bindings in nix-bindings-sys are generated from Nix C API headers and committed to the repository.
To regenerate manually:
nix develop
cd nix-bindings-sys
rm -rf src/Generated binding-specs
mkdir -p binding-specs
./generate-bindingsThe Nix C API headers come from the nix flake input (NixOS/nix).