ofborg/ofborg-simple-build/src/main.rs
Daiderd Jordan 7ccb4943a1
move simple-build to a separate project
This is mostly intended as an example and since this is only useful for
testing it should be relatively safe.
2020-04-24 22:17:12 +02:00

37 lines
830 B
Rust

#[macro_use]
extern crate log;
use std::env;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use ofborg::config;
use ofborg::nix;
fn main() {
ofborg::setup_log();
log::info!("Loading config...");
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
let nix = cfg.nix();
log::info!("Running build...");
match nix.safely_build_attrs(
&Path::new("./"),
nix::File::DefaultNixpkgs,
vec![String::from("hello")],
) {
Ok(mut out) => {
print!("{}", file_to_str(&mut out));
}
Err(mut out) => print!("{}", file_to_str(&mut out)),
}
}
fn file_to_str(f: &mut File) -> String {
let mut buffer = Vec::new();
f.read_to_end(&mut buffer).expect("Reading eval output");
String::from(String::from_utf8_lossy(&buffer))
}