forked from the-distro/ofborg
Nix: support debug / cloning and setting the system
This commit is contained in:
parent
017c7e9a2b
commit
bdf9ed5ac3
|
@ -6,6 +6,7 @@ use std::fs::File;
|
|||
use std::io::Seek;
|
||||
use std::io::SeekFrom;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Nix {
|
||||
system: String,
|
||||
remote: String
|
||||
|
@ -19,35 +20,46 @@ pub fn new(system: String, remote: String) -> Nix {
|
|||
}
|
||||
|
||||
impl Nix {
|
||||
pub fn safely_build_attrs(&self, nixpkgs: &Path, attrs: Vec<String>) -> Result<File,File> {
|
||||
let mut nixpath = OsString::new();
|
||||
nixpath.push("nixpkgs=");
|
||||
nixpath.push(nixpkgs.as_os_str());
|
||||
pub fn with_system(&self, system: String) -> Nix {
|
||||
return Nix{
|
||||
system: system,
|
||||
remote: self.remote.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
let mut attrargs: Vec<String> = Vec::with_capacity(attrs.len() * 2);
|
||||
pub fn safely_build_attrs(&self, nixpkgs: &Path, attrs: Vec<String>) -> Result<File,File> {
|
||||
let mut attrargs: Vec<String> = Vec::with_capacity(2 + (attrs.len() * 2));
|
||||
attrargs.push(String::from("--no-out-link"));
|
||||
attrargs.push(String::from("--keep-going"));
|
||||
for attr in attrs {
|
||||
attrargs.push(String::from("-A"));
|
||||
attrargs.push(attr);
|
||||
}
|
||||
|
||||
return self.safely("nix-build", nixpkgs, attrargs);
|
||||
}
|
||||
|
||||
pub fn safely(&self, cmd: &str, nixpkgs: &Path, args: Vec<String>) -> Result<File,File> {
|
||||
let mut nixpath = OsString::new();
|
||||
nixpath.push("nixpkgs=");
|
||||
nixpath.push(nixpkgs.as_os_str());
|
||||
|
||||
let stdout = tempfile().expect("Fetching a stdout tempfile");
|
||||
let stderr = stdout.try_clone().expect("Cloning stdout for stderr");
|
||||
let mut reader = stderr.try_clone().expect("Cloning stderr to the reader");
|
||||
|
||||
let status = Command::new("nix-build")
|
||||
let status = Command::new(cmd)
|
||||
.env_clear()
|
||||
.current_dir(nixpkgs)
|
||||
.stdout(Stdio::from(stdout))
|
||||
.stderr(Stdio::from(stderr))
|
||||
.env("NIX_PATH", nixpath)
|
||||
.env("NIX_REMOTE", &self.remote)
|
||||
.arg("--no-out-link")
|
||||
.args(&["--option", "restrict-eval", "true"])
|
||||
.args(&["--argstr", "system", &self.system])
|
||||
.arg("--keep-going")
|
||||
.args(attrargs)
|
||||
.args(args)
|
||||
.status()
|
||||
.expect("Running nix-build");
|
||||
.expect(format!("Running {:?}", cmd).as_ref());
|
||||
|
||||
reader.seek(SeekFrom::Start(0)).expect("Seeking to Start(0)");
|
||||
|
||||
|
|
Loading…
Reference in a new issue