add operation type for nix commands
This commit is contained in:
parent
48430ba3be
commit
ca7f94b36b
|
@ -7,16 +7,16 @@ use ofborg::nix;
|
||||||
|
|
||||||
pub struct EvalChecker {
|
pub struct EvalChecker {
|
||||||
name: String,
|
name: String,
|
||||||
cmd: String,
|
op: nix::Operation,
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
nix: nix::Nix,
|
nix: nix::Nix,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EvalChecker {
|
impl EvalChecker {
|
||||||
pub fn new(name: &str, cmd: &str, args: Vec<String>, nix: nix::Nix) -> EvalChecker {
|
pub fn new(name: &str, op: nix::Operation, args: Vec<String>, nix: nix::Nix) -> EvalChecker {
|
||||||
EvalChecker {
|
EvalChecker {
|
||||||
name: name.to_owned(),
|
name: name.to_owned(),
|
||||||
cmd: cmd.to_owned(),
|
op: op,
|
||||||
args: args,
|
args: args,
|
||||||
nix: nix,
|
nix: nix,
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@ impl EvalChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(&self, path: &Path) -> Result<File, File> {
|
pub fn execute(&self, path: &Path) -> Result<File, File> {
|
||||||
self.nix.safely(&self.cmd, path, self.args.clone(), false)
|
self.nix.safely(self.op.clone(), path, self.args.clone(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cli_cmd(&self) -> String {
|
pub fn cli_cmd(&self) -> String {
|
||||||
let mut cli = vec![self.cmd.clone()];
|
let mut cli = vec![self.op.to_string()];
|
||||||
cli.append(&mut self.args.clone());
|
cli.append(&mut self.args.clone());
|
||||||
return cli.join(" ");
|
return cli.join(" ");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::fmt;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Seek;
|
use std::io::Seek;
|
||||||
use std::io::SeekFrom;
|
use std::io::SeekFrom;
|
||||||
|
@ -7,6 +7,37 @@ use std::path::Path;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use tempfile::tempfile;
|
use tempfile::tempfile;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum Operation {
|
||||||
|
Build,
|
||||||
|
Instantiate,
|
||||||
|
Unknown { program: String },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Operation {
|
||||||
|
pub fn new(program: &str) -> Operation {
|
||||||
|
Operation::Unknown { program: program.to_owned() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn command(&self) -> Command {
|
||||||
|
match *self {
|
||||||
|
Operation::Build => Command::new("nix-build"),
|
||||||
|
Operation::Instantiate => Command::new("nix-instantiate"),
|
||||||
|
Operation::Unknown { ref program } => Command::new(program),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Operation {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match *self {
|
||||||
|
Operation::Build => write!(f, "{}", "nix-build"),
|
||||||
|
Operation::Instantiate => write!(f, "{}", "nix-instantiate"),
|
||||||
|
Operation::Unknown { ref program } => write!(f, "{}", program),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Nix {
|
pub struct Nix {
|
||||||
system: String,
|
system: String,
|
||||||
|
@ -71,17 +102,17 @@ impl Nix {
|
||||||
attrargs.push(attr);
|
attrargs.push(attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.safe_command("nix-build", nixpkgs, attrargs);
|
return self.safe_command(Operation::Build, nixpkgs, attrargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn safely(
|
pub fn safely(
|
||||||
&self,
|
&self,
|
||||||
cmd: &str,
|
op: Operation,
|
||||||
nixpkgs: &Path,
|
nixpkgs: &Path,
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
keep_stdout: bool,
|
keep_stdout: bool,
|
||||||
) -> Result<File, File> {
|
) -> Result<File, File> {
|
||||||
return self.run(self.safe_command(cmd, nixpkgs, args), keep_stdout);
|
return self.run(self.safe_command(op, nixpkgs, args), keep_stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&self, mut cmd: Command, keep_stdout: bool) -> Result<File, File> {
|
pub fn run(&self, mut cmd: Command, keep_stdout: bool) -> Result<File, File> {
|
||||||
|
@ -113,12 +144,10 @@ impl Nix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn safe_command(&self, cmd: &str, nixpkgs: &Path, args: Vec<String>) -> Command {
|
pub fn safe_command(&self, op: Operation, nixpkgs: &Path, args: Vec<String>) -> Command {
|
||||||
let mut nixpath = OsString::new();
|
let nixpath = format!("nixpkgs={}", nixpkgs.display());
|
||||||
nixpath.push("nixpkgs=");
|
|
||||||
nixpath.push(nixpkgs.as_os_str());
|
|
||||||
|
|
||||||
let mut command = Command::new(cmd);
|
let mut command = op.command();
|
||||||
command.env_clear();
|
command.env_clear();
|
||||||
command.current_dir(nixpkgs);
|
command.current_dir(nixpkgs);
|
||||||
command.env("HOME", "/homeless-shelter");
|
command.env("HOME", "/homeless-shelter");
|
||||||
|
@ -276,7 +305,7 @@ mod tests {
|
||||||
|
|
||||||
let ret: Result<File, File> =
|
let ret: Result<File, File> =
|
||||||
nix.run(
|
nix.run(
|
||||||
nix.safe_command("./environment.sh", build_path().as_path(), vec![]),
|
nix.safe_command(Operation::new("./environment.sh"), build_path().as_path(), vec![]),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -298,7 +327,7 @@ mod tests {
|
||||||
|
|
||||||
let ret: Result<File, File> =
|
let ret: Result<File, File> =
|
||||||
nix.run(
|
nix.run(
|
||||||
nix.safe_command("./environment.sh", build_path().as_path(), vec![]),
|
nix.safe_command(Operation::new("./environment.sh"), build_path().as_path(), vec![]),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -320,7 +349,7 @@ mod tests {
|
||||||
let nix = nix();
|
let nix = nix();
|
||||||
|
|
||||||
let ret: Result<File, File> = nix.run(
|
let ret: Result<File, File> = nix.run(
|
||||||
nix.safe_command("echo", build_path().as_path(), vec![]),
|
nix.safe_command(Operation::new("echo"), build_path().as_path(), vec![]),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -393,7 +422,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn instantiation() {
|
fn instantiation() {
|
||||||
let ret: Result<File, File> = nix().safely(
|
let ret: Result<File, File> = nix().safely(
|
||||||
"nix-instantiate",
|
Operation::Instantiate,
|
||||||
passing_eval_path().as_path(),
|
passing_eval_path().as_path(),
|
||||||
vec![],
|
vec![],
|
||||||
true,
|
true,
|
||||||
|
|
|
@ -170,7 +170,7 @@ impl OutPaths {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.nix.safely(
|
self.nix.safely(
|
||||||
"nix-env",
|
nix::Operation::new("nix-env"),
|
||||||
&self.path,
|
&self.path,
|
||||||
vec![
|
vec![
|
||||||
String::from("-f"),
|
String::from("-f"),
|
||||||
|
|
|
@ -10,7 +10,7 @@ use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use ofborg::checkout;
|
use ofborg::checkout;
|
||||||
use ofborg::message::{massrebuildjob, buildjob};
|
use ofborg::message::{massrebuildjob, buildjob};
|
||||||
use ofborg::nix::Nix;
|
use ofborg::nix;
|
||||||
|
|
||||||
use ofborg::acl::ACL;
|
use ofborg::acl::ACL;
|
||||||
use ofborg::stats;
|
use ofborg::stats;
|
||||||
|
@ -25,7 +25,7 @@ use hubcaps;
|
||||||
|
|
||||||
pub struct MassRebuildWorker<E> {
|
pub struct MassRebuildWorker<E> {
|
||||||
cloner: checkout::CachedCloner,
|
cloner: checkout::CachedCloner,
|
||||||
nix: Nix,
|
nix: nix::Nix,
|
||||||
github: hubcaps::Github,
|
github: hubcaps::Github,
|
||||||
acl: ACL,
|
acl: ACL,
|
||||||
identity: String,
|
identity: String,
|
||||||
|
@ -36,7 +36,7 @@ pub struct MassRebuildWorker<E> {
|
||||||
impl<E: stats::SysEvents> MassRebuildWorker<E> {
|
impl<E: stats::SysEvents> MassRebuildWorker<E> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
cloner: checkout::CachedCloner,
|
cloner: checkout::CachedCloner,
|
||||||
nix: Nix,
|
nix: nix::Nix,
|
||||||
github: hubcaps::Github,
|
github: hubcaps::Github,
|
||||||
acl: ACL,
|
acl: ACL,
|
||||||
identity: String,
|
identity: String,
|
||||||
|
@ -291,7 +291,7 @@ impl<E: stats::SysEvents> worker::SimpleWorker for MassRebuildWorker<E> {
|
||||||
let eval_checks = vec![
|
let eval_checks = vec![
|
||||||
EvalChecker::new(
|
EvalChecker::new(
|
||||||
"package-list",
|
"package-list",
|
||||||
"nix-env",
|
nix::Operation::new("nix-env"),
|
||||||
vec![
|
vec![
|
||||||
String::from("--file"),
|
String::from("--file"),
|
||||||
String::from("."),
|
String::from("."),
|
||||||
|
@ -304,7 +304,7 @@ impl<E: stats::SysEvents> worker::SimpleWorker for MassRebuildWorker<E> {
|
||||||
|
|
||||||
EvalChecker::new(
|
EvalChecker::new(
|
||||||
"nixos-options",
|
"nixos-options",
|
||||||
"nix-instantiate",
|
nix::Operation::Instantiate,
|
||||||
vec![
|
vec![
|
||||||
String::from("./nixos/release.nix"),
|
String::from("./nixos/release.nix"),
|
||||||
String::from("-A"),
|
String::from("-A"),
|
||||||
|
@ -315,7 +315,7 @@ impl<E: stats::SysEvents> worker::SimpleWorker for MassRebuildWorker<E> {
|
||||||
|
|
||||||
EvalChecker::new(
|
EvalChecker::new(
|
||||||
"nixos-manual",
|
"nixos-manual",
|
||||||
"nix-instantiate",
|
nix::Operation::Instantiate,
|
||||||
vec![
|
vec![
|
||||||
String::from("./nixos/release.nix"),
|
String::from("./nixos/release.nix"),
|
||||||
String::from("-A"),
|
String::from("-A"),
|
||||||
|
@ -326,7 +326,7 @@ impl<E: stats::SysEvents> worker::SimpleWorker for MassRebuildWorker<E> {
|
||||||
|
|
||||||
EvalChecker::new(
|
EvalChecker::new(
|
||||||
"nixpkgs-manual",
|
"nixpkgs-manual",
|
||||||
"nix-instantiate",
|
nix::Operation::Instantiate,
|
||||||
vec![
|
vec![
|
||||||
String::from("./pkgs/top-level/release.nix"),
|
String::from("./pkgs/top-level/release.nix"),
|
||||||
String::from("-A"),
|
String::from("-A"),
|
||||||
|
@ -337,7 +337,7 @@ impl<E: stats::SysEvents> worker::SimpleWorker for MassRebuildWorker<E> {
|
||||||
|
|
||||||
EvalChecker::new(
|
EvalChecker::new(
|
||||||
"nixpkgs-tarball",
|
"nixpkgs-tarball",
|
||||||
"nix-instantiate",
|
nix::Operation::Instantiate,
|
||||||
vec![
|
vec![
|
||||||
String::from("./pkgs/top-level/release.nix"),
|
String::from("./pkgs/top-level/release.nix"),
|
||||||
String::from("-A"),
|
String::from("-A"),
|
||||||
|
@ -348,7 +348,7 @@ impl<E: stats::SysEvents> worker::SimpleWorker for MassRebuildWorker<E> {
|
||||||
|
|
||||||
EvalChecker::new(
|
EvalChecker::new(
|
||||||
"nixpkgs-unstable-jobset",
|
"nixpkgs-unstable-jobset",
|
||||||
"nix-instantiate",
|
nix::Operation::Instantiate,
|
||||||
vec![
|
vec![
|
||||||
String::from("./pkgs/top-level/release.nix"),
|
String::from("./pkgs/top-level/release.nix"),
|
||||||
String::from("-A"),
|
String::from("-A"),
|
||||||
|
@ -542,7 +542,7 @@ pub enum System {
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
struct Stdenvs {
|
struct Stdenvs {
|
||||||
nix: Nix,
|
nix: nix::Nix,
|
||||||
co: PathBuf,
|
co: PathBuf,
|
||||||
|
|
||||||
linux_stdenv_before: Option<String>,
|
linux_stdenv_before: Option<String>,
|
||||||
|
@ -553,7 +553,7 @@ struct Stdenvs {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Stdenvs {
|
impl Stdenvs {
|
||||||
fn new(nix: Nix, co: PathBuf) -> Stdenvs {
|
fn new(nix: nix::Nix, co: PathBuf) -> Stdenvs {
|
||||||
return Stdenvs {
|
return Stdenvs {
|
||||||
nix: nix,
|
nix: nix,
|
||||||
co: co,
|
co: co,
|
||||||
|
@ -615,7 +615,7 @@ impl Stdenvs {
|
||||||
|
|
||||||
fn evalstdenv(&self, system: &str) -> Option<String> {
|
fn evalstdenv(&self, system: &str) -> Option<String> {
|
||||||
let result = self.nix.with_system(system.to_owned()).safely(
|
let result = self.nix.with_system(system.to_owned()).safely(
|
||||||
"nix-instantiate",
|
nix::Operation::Instantiate,
|
||||||
&self.co,
|
&self.co,
|
||||||
vec![
|
vec![
|
||||||
String::from("."),
|
String::from("."),
|
||||||
|
@ -768,8 +768,7 @@ mod tests {
|
||||||
let nixpkgs = String::from_utf8(output.stdout)
|
let nixpkgs = String::from_utf8(output.stdout)
|
||||||
.expect("nixpkgs required");
|
.expect("nixpkgs required");
|
||||||
|
|
||||||
let nix = Nix::new(String::from("x86_64-linux"), String::from("daemon"), 1200, None);
|
let nix = nix::Nix::new(String::from("x86_64-linux"), String::from("daemon"), 1200, None);
|
||||||
|
|
||||||
let mut stdenv =
|
let mut stdenv =
|
||||||
Stdenvs::new(
|
Stdenvs::new(
|
||||||
nix.clone(),
|
nix.clone(),
|
||||||
|
|
Loading…
Reference in a new issue