hello/
hello.rs

1use nix_build as nix;
2
3fn main() {
4    let outputs = nix::Config::new()
5        .target_flake("nixpkgs#hello")
6        .build()
7        .expect("nix build to work");
8
9    let hello = outputs[0].out().expect("default output to be available");
10
11    let stdout = std::process::Command::new(format!("{}/bin/hello", hello.display().to_string()))
12        .output()
13        .expect("hello to succeed")
14        .stdout;
15
16    let stdout = std::str::from_utf8(&stdout).expect("stdout to be UTF-8");
17    assert!(stdout == "Hello, world!\n");
18
19    print!("{}", stdout);
20}