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::Seek;
|
||||||
use std::io::SeekFrom;
|
use std::io::SeekFrom;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Nix {
|
pub struct Nix {
|
||||||
system: String,
|
system: String,
|
||||||
remote: String
|
remote: String
|
||||||
|
@ -19,35 +20,46 @@ pub fn new(system: String, remote: String) -> Nix {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Nix {
|
impl Nix {
|
||||||
pub fn safely_build_attrs(&self, nixpkgs: &Path, attrs: Vec<String>) -> Result<File,File> {
|
pub fn with_system(&self, system: String) -> Nix {
|
||||||
let mut nixpath = OsString::new();
|
return Nix{
|
||||||
nixpath.push("nixpkgs=");
|
system: system,
|
||||||
nixpath.push(nixpkgs.as_os_str());
|
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 {
|
for attr in attrs {
|
||||||
attrargs.push(String::from("-A"));
|
attrargs.push(String::from("-A"));
|
||||||
attrargs.push(attr);
|
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 stdout = tempfile().expect("Fetching a stdout tempfile");
|
||||||
let stderr = stdout.try_clone().expect("Cloning stdout for stderr");
|
let stderr = stdout.try_clone().expect("Cloning stdout for stderr");
|
||||||
let mut reader = stderr.try_clone().expect("Cloning stderr to the reader");
|
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()
|
.env_clear()
|
||||||
.current_dir(nixpkgs)
|
.current_dir(nixpkgs)
|
||||||
.stdout(Stdio::from(stdout))
|
.stdout(Stdio::from(stdout))
|
||||||
.stderr(Stdio::from(stderr))
|
.stderr(Stdio::from(stderr))
|
||||||
.env("NIX_PATH", nixpath)
|
.env("NIX_PATH", nixpath)
|
||||||
.env("NIX_REMOTE", &self.remote)
|
.env("NIX_REMOTE", &self.remote)
|
||||||
.arg("--no-out-link")
|
|
||||||
.args(&["--option", "restrict-eval", "true"])
|
.args(&["--option", "restrict-eval", "true"])
|
||||||
.args(&["--argstr", "system", &self.system])
|
.args(&["--argstr", "system", &self.system])
|
||||||
.arg("--keep-going")
|
.args(args)
|
||||||
.args(attrargs)
|
|
||||||
.status()
|
.status()
|
||||||
.expect("Running nix-build");
|
.expect(format!("Running {:?}", cmd).as_ref());
|
||||||
|
|
||||||
reader.seek(SeekFrom::Start(0)).expect("Seeking to Start(0)");
|
reader.seek(SeekFrom::Start(0)).expect("Seeking to Start(0)");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue