Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ edition = "2024"
license = "EUPL-1.2"
repository = "https://github.com/manic-systems/evix"
rust-version = "1.95.0"
version = "2.1.1"
version = "3.0.0"

[workspace.dependencies]
# Workspace components
evix = { path = "crates/evix", version = "2.1.1" }
evix-daemon = { path = "crates/evix-daemon", version = "2.1.1" }
evix-protocol = { path = "crates/evix-protocol", version = "2.1.1" }
evix = { path = "crates/evix", version = "3.0.0" }
evix-daemon = { path = "crates/evix-daemon", version = "3.0.0" }
evix-protocol = { path = "crates/evix-protocol", version = "3.0.0" }

# Other dependencies
anyhow = "1.0.104"
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ If an `evixd` socket is available, `eval` uses it and stores a warm session for
later `query` or `diff` calls. If the daemon is not running, `eval` falls back
to local evaluation. Use `--no-daemon` to force local evaluation.

`evix eval --replay` is an experimental, incremental-like [^1] evaluation model
that serves a snapshot of a completed daemon evaluation. A normal daemon-backed
`eval` records the NDJSON event stream; a later replay with the same evaluation
configuration writes those events again without starting Nix or querying the
warm graph. The snapshot is replaced by a new `eval`, and invalidated by `diff`
or `watch`. This system is **opt-in**. It does not check whether source files,
environment variables, or other impure inputs changed, so use ordinary `eval`
when a fresh result is important to its success. Replay also skips GC root
registration, so with `--gc-roots-dir` the replayed derivations stay alive only
as long as the roots the original `eval` created. It requires a running daemon
and fails if there is no completed matching session.

[^1]: I can almost hear you asking _"what the hell is incremental-like?"_. Well,
we basically lack _any_ kind of API on Nix's end to make truly incremental
evaluation. This is the _closest_ we can get to that while retaining
meaningful performance gains.

> [!NOTE]
> Local/path flakes are checked against their `flake.lock`. Non-local flake refs
> are still locked virtually inside each worker, so Evix warns for those inputs;
Expand Down Expand Up @@ -214,6 +231,7 @@ Like `query`, `diff` requires an existing warm daemon session.
| `--force-recurse` | Recurse into all attrsets, ignoring `recurseForDerivations` |
| `--gc-roots-dir DIR` | Register GC root symlinks for evaluated derivations |
| `--socket PATH` | Daemon socket path for daemon-backed commands |
| `--replay` | Replay a completed matching daemon evaluation |
| `-v`, `--verbose` | Increase logging verbosity, repeat for trace logs |
| `-q`, `--quiet` | Decrease logging verbosity, repeat to suppress more logs |

Expand Down
6 changes: 4 additions & 2 deletions bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ $ bench/bench.sh 5 3

Runs `hyperfine` over evix at 1/4/8 local-only workers, evix remote-only
distributed evaluation, evix mixed local+remote distributed evaluation,
daemon-backed cold prewarming, warm full-graph daemon queries, filtered warm
daemon queries, and nix-eval-jobs. Writes `bench/results.md`.
daemon-backed cold prewarming, warm replay of a completed daemon event stream,
warm full-graph daemon queries, filtered warm daemon queries, and nix-eval-jobs.
Queries print only derivations, while evaluation and replay also print attrset
and error events. Writes `bench/results.md`.
6 changes: 4 additions & 2 deletions bench/bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Wall-clock benchmark of evix evaluation vs nix-eval-jobs on a fixed fixture,
# using hyperfine. Covers evix local-only evaluation, remote-only distributed
# evaluation, mixed local+remote distributed evaluation, daemon prewarming,
# warm daemon graph queries, and nix-eval-jobs as the reference.
# warm daemon graph queries and event replays, and nix-eval-jobs as the
# reference.
#
# Usage: bench/bench.sh [breadth] [depth] (defaults: breadth=6 depth=3)
set -euo pipefail
Expand Down Expand Up @@ -44,7 +45,7 @@ for _ in $(seq 1 100); do
[ -S "$sock" ] && break
sleep 0.05
done
"$evix" eval --socket "$sock" --workers 4$args_str >/dev/null
"$evix" eval --socket "$sock" --workers 4 "${args[@]}" >/dev/null

cmds=(
-n "evix local=1" "$evix eval --no-daemon --workers 1$args_str >/dev/null"
Expand All @@ -53,6 +54,7 @@ cmds=(
-n "evix distributed remote=4" "$evix eval --no-daemon --workers 0 --insecure-tokenless-remote --remote 127.0.0.1:$port $sys 4$args_str >/dev/null"
-n "evix distributed local=4 remote=4" "$evix eval --no-daemon --workers 4 --insecure-tokenless-remote --remote 127.0.0.1:$port $sys 4$args_str >/dev/null"
-n "evix daemon prewarm local=4" "$evix eval --socket $sock --workers 4$args_str >/dev/null"
-n "evix daemon warm replay local=4" "$evix eval --replay --socket $sock --workers 4$args_str >/dev/null"
-n "evix daemon warm query full local=4" "$evix query --socket $sock --workers 4$args_str >/dev/null"
-n "evix daemon warm query n0 local=4" "$evix query --socket $sock --workers 4 --attr-prefix n0$args_str >/dev/null"
)
Expand Down
19 changes: 10 additions & 9 deletions bench/results.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `evix local=1` | 263.3 ± 6.5 | 258.1 | 274.6 | 9.31 ± 0.32 |
| `evix local=4` | 157.4 ± 4.5 | 151.0 | 163.2 | 5.57 ± 0.21 |
| `evix local=8` | 153.2 ± 2.4 | 151.0 | 156.9 | 5.42 ± 0.16 |
| `evix distributed remote=4` | 198.3 ± 2.9 | 194.6 | 201.1 | 7.02 ± 0.20 |
| `evix distributed local=4 remote=4` | 168.4 ± 11.1 | 156.9 | 186.7 | 5.96 ± 0.42 |
| `evix daemon prewarm local=4` | 197.0 ± 6.5 | 186.5 | 203.1 | 6.97 ± 0.29 |
| `evix daemon warm query full local=4` | 103.3 ± 0.7 | 102.4 | 104.2 | 3.65 ± 0.09 |
| `evix daemon warm query n0 local=4` | 28.3 ± 0.7 | 27.6 | 29.4 | 1.00 |
| `nix-eval-jobs w=4` | 147.5 ± 7.6 | 135.4 | 154.3 | 5.22 ± 0.30 |
| `evix local=1` | 118.8 ± 4.6 | 112.5 | 124.5 | 11.75 ± 0.81 |
| `evix local=4` | 62.1 ± 2.7 | 60.3 | 66.9 | 6.14 ± 0.44 |
| `evix local=8` | 58.1 ± 2.9 | 54.4 | 61.6 | 5.75 ± 0.43 |
| `evix distributed remote=4` | 82.3 ± 5.4 | 76.2 | 91.1 | 8.14 ± 0.71 |
| `evix distributed local=4 remote=4` | 61.8 ± 2.7 | 59.7 | 66.1 | 6.12 ± 0.44 |
| `evix daemon prewarm local=4` | 64.2 ± 1.2 | 62.8 | 65.4 | 6.35 ± 0.38 |
| `evix daemon warm replay local=4` | 12.9 ± 0.7 | 11.9 | 13.6 | 1.28 ± 0.10 |
| `evix daemon warm query full local=4` | 13.5 ± 0.3 | 13.2 | 14.0 | 1.34 ± 0.08 |
| `evix daemon warm query n0 local=4` | 10.1 ± 0.6 | 9.5 | 10.7 | 1.00 |
| `nix-eval-jobs w=4` | 80.5 ± 7.3 | 75.2 | 92.0 | 7.96 ± 0.85 |
32 changes: 32 additions & 0 deletions crates/evix-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ enum Commands {
socket: Option<PathBuf>,
#[pound(long)]
no_daemon: bool,
/// Replay a completed matching daemon evaluation without evaluating Nix.
#[pound(long)]
replay: bool,
},

#[pound(required_group = "input")]
Expand Down Expand Up @@ -268,6 +271,7 @@ pub enum CommandPlan {
config: Config,
socket: Option<PathBuf>,
use_daemon: bool,
replay: bool,
},
Watch {
config: Config,
Expand Down Expand Up @@ -346,7 +350,11 @@ fn command_plan(command: Commands) -> Result<CommandPlan> {
gc_roots_dir,
socket,
no_daemon,
replay,
} => {
if replay && no_daemon {
bail!("--replay requires the daemon")
}
Ok(CommandPlan::Eval {
config: config(EvalInput {
flake,
Expand All @@ -369,6 +377,7 @@ fn command_plan(command: Commands) -> Result<CommandPlan> {
})?,
socket,
use_daemon: !no_daemon,
replay,
})
},
Commands::Watch {
Expand Down Expand Up @@ -864,6 +873,29 @@ mod tests {
assert_eq!(config.item_timeout_seconds, 7);
}

#[test]
fn eval_replay_requires_daemon() {
let (_, CommandPlan::Eval { replay, .. }) =
parse_plan_from(["eval", "--expr", "{}", "--replay"])
.expect("parse replay eval plan")
else {
panic!("expected eval plan");
};
assert!(replay);

let error = match parse_plan_from([
"eval",
"--expr",
"{}",
"--replay",
"--no-daemon",
]) {
Ok(_) => panic!("expected replay without daemon to fail"),
Err(error) => error.to_string(),
};
assert!(error.contains("--replay requires the daemon"));
}

#[test]
fn eval_rejects_zero_item_timeout_seconds() {
let error = match parse_plan_from([
Expand Down
18 changes: 13 additions & 5 deletions crates/evix-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,20 @@ fn run_plan(plan: CommandPlan) -> Result<()> {
config,
socket,
use_daemon,
replay,
} => {
if use_daemon {
run_client_or_local(
daemon_request(Request::eval(&wire_config(&config)))?,
socket,
|| run_local_eval(&config),
)
let request = if replay {
Request::replay(&wire_config(&config))
} else {
Request::eval(&wire_config(&config))
};
let request = daemon_request(request)?;
if replay {
run_daemon_only(request, socket)
} else {
run_client_or_local(request, socket, || run_local_eval(&config))
}
} else {
run_local_eval(&config)
}
Expand Down Expand Up @@ -120,6 +127,7 @@ fn run_plan(plan: CommandPlan) -> Result<()> {
fn daemon_request(request: Request) -> Result<Request> {
Ok(match request {
Request::Eval { config, .. } => Request::eval(&daemon_config(config)?),
Request::Replay { config, .. } => Request::replay(&daemon_config(config)?),
Request::Watch { config, .. } => Request::watch(&daemon_config(config)?),
Request::Query { config, filter, .. } => {
Request::query(&daemon_config(config)?, &filter)
Expand Down
106 changes: 104 additions & 2 deletions crates/evix-cli/tests/eval.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{
io::Read as _,
net::{TcpListener, TcpStream},
process::{Child, Command, Output, Stdio},
path::{Path, PathBuf},
process::{self, Child, Command, Output, Stdio},
thread,
time::{Duration, Instant},
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
};

fn evix() -> Command {
Expand Down Expand Up @@ -177,6 +178,57 @@ fn run_with_timeout(command: &mut Command, limit: Duration) -> Output {
}
}

#[test]
fn daemon_replay_matches_eval_and_diff_invalidates_it() {
let socket = temporary_socket_path();
let _daemon = spawn_daemon(&socket);
wait_for_socket(&socket);
let socket = socket.to_str().expect("socket path is UTF-8");
let expression = "{ recurseForDerivations = true; hello = { \
recurseForDerivations = true; leaf = 1; }; }";

let initial = evix()
.args(["eval", "--socket", socket, "--expr", expression])
.output()
.expect("run daemon evaluation");
assert!(
initial.status.success(),
"stderr:\n{}",
String::from_utf8_lossy(&initial.stderr)
);

let replay = evix()
.args(["eval", "--replay", "--socket", socket, "--expr", expression])
.output()
.expect("run replay");
assert!(
replay.status.success(),
"stderr:\n{}",
String::from_utf8_lossy(&replay.stderr)
);
assert_eq!(replay.stdout, initial.stdout);

let diff = evix()
.args(["diff", "--socket", socket, "--expr", expression])
.output()
.expect("run diff");
assert!(
diff.status.success(),
"stderr:\n{}",
String::from_utf8_lossy(&diff.stderr)
);

let replay_after_diff = evix()
.args(["eval", "--replay", "--socket", socket, "--expr", expression])
.output()
.expect("run replay after diff");
assert!(!replay_after_diff.status.success());
assert!(
String::from_utf8_lossy(&replay_after_diff.stderr)
.contains("no replayable completed evaluation")
);
}

fn unused_loopback_endpoint() -> String {
let listener = TcpListener::bind("127.0.0.1:0").expect("bind test port");
let addr = listener.local_addr().expect("read test port");
Expand All @@ -194,6 +246,24 @@ fn spawn_worker(endpoint: &str, token: &str) -> Child {
.expect("spawn evix worker")
}

fn spawn_daemon(socket: &Path) -> DaemonGuard {
DaemonGuard {
child: evix()
.args([
"daemon",
"--foreground",
"--socket",
socket.to_str().expect("socket path is UTF-8"),
])
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::piped())
.spawn()
.expect("spawn daemon"),
socket: socket.to_owned(),
}
}

fn wait_for_worker(endpoint: &str) {
for _ in 0..100 {
if TcpStream::connect(endpoint).is_ok() {
Expand All @@ -204,7 +274,39 @@ fn wait_for_worker(endpoint: &str) {
panic!("worker did not listen on {endpoint}");
}

fn wait_for_socket(socket: &Path) {
for _ in 0..100 {
if socket.exists() {
return;
}
thread::sleep(Duration::from_millis(50));
}
panic!("daemon did not create socket at {}", socket.display());
}

fn temporary_socket_path() -> PathBuf {
let nanos = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system time before UNIX epoch")
.as_nanos();
std::env::temp_dir()
.join(format!("evix-daemon-{}-{nanos}.sock", process::id()))
}

fn stop_worker(worker: &mut Child) {
let _ = worker.kill();
let _ = worker.wait();
}

struct DaemonGuard {
child: Child,
socket: PathBuf,
}

impl Drop for DaemonGuard {
fn drop(&mut self) {
let _ = self.child.kill();
let _ = self.child.wait();
let _ = std::fs::remove_file(&self.socket);
}
}
Loading
Loading