Crates.io | nix-daemon |
lib.rs | nix-daemon |
version | 0.1.1 |
source | src |
created_at | 2024-07-14 06:44:43.786022 |
updated_at | 2024-07-16 06:52:19.36328 |
description | A library for talking directly to the Nix Daemon |
homepage | |
repository | https://codeberg.org/gorgon/gorgon/src/branch/main/nix-daemon |
max_upload_size | |
id | 1302805 |
size | 161,032 |
A library for talking directly to the Nix Daemon.
To connect to a local nix-daemon
, use a nix::DaemonStore
(which implements the
Store
trait):
use nix_daemon::{Store, Progress, nix::DaemonStore};
let mut store = DaemonStore::builder()
.connect_unix("/nix/var/nix/daemon-socket/socket")
.await?;
let is_valid_path = store.is_valid_path("/nix/store/...").result().await?;
If you'd rather write your own nix-daemon
compatible store, and expose it to existing
tools like nix-build
, you can implement the Store
trait yourself and use
nix::DaemonProtocolAdapter
:
use tokio::net::UnixListener;
use nix_daemon::nix::{DaemonStore, DaemonProtocolAdapter};
// Accept a connection.
let listener = UnixListener::bind("/tmp/mystore.sock")?;
let (conn, _addr) = listener.accept().await?;
// This will just use `DaemonStore` to proxy to the normal daemon, but you can
// pass your own `Store` implementation here instead.
let mut store = DaemonStore::builder()
.connect_unix("/nix/var/nix/daemon-socket/socket")
.await?;
// Run the adapter!
let (cr, cw) = conn.into_split();
let mut adapter = DaemonProtocolAdapter::builder(&mut store)
.adopt(cr, cw)
.await?;
See nix-supervisor for a more complex example.
Please see the main README.
This project was funded through the NGI0 Entrust Fund, a fund established by NLnet with financial support from the European Commission's Next Generation Internet programme, under the aegis of DG Communications Networks, Content and Technology under grant agreement NÂș 101069594.