From 1a536ce2962cb9c850d80ffe5d196c45626792d4 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 8 Nov 2017 03:34:48 -0500 Subject: [PATCH] just pretend this makes sense --- ofborg/Cargo.lock | 20 ++++++++++++++ ofborg/Cargo.toml | 3 ++- ofborg/src/bin/builder.rs | 14 ++++------ ofborg/src/lib.rs | 4 ++- ofborg/src/message/buildjob.rs | 1 + ofborg/src/nix.rs | 48 ++++++++++++++++++++++++++++++++++ shell.nix | 9 ++++++- 7 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 ofborg/src/nix.rs diff --git a/ofborg/Cargo.lock b/ofborg/Cargo.lock index b786213..0989805 100644 --- a/ofborg/Cargo.lock +++ b/ofborg/Cargo.lock @@ -8,6 +8,7 @@ dependencies = [ "serde 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -308,6 +309,11 @@ dependencies = [ "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "redox_syscall" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "regex" version = "0.1.80" @@ -400,6 +406,18 @@ dependencies = [ "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tempfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "thread-id" version = "2.0.0" @@ -519,6 +537,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum pnacl-build-helper 1.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dfbe13ee77c06fb633d71c72438bd983286bb3521863a753ade8e951c7efb090" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "61efcbcd9fa8d8fbb07c84e34a8af18a1ff177b449689ad38a6e9457ecc7b2ae" +"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509" "checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f" "checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" "checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e" @@ -530,6 +549,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6" +"checksum tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "11ce2fe9db64b842314052e2421ac61a73ce41b898dc8e3750398b219c5fc1e0" "checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" "checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" diff --git a/ofborg/Cargo.toml b/ofborg/Cargo.toml index 3c76ecb..94cfe5b 100644 --- a/ofborg/Cargo.toml +++ b/ofborg/Cargo.toml @@ -9,4 +9,5 @@ md5 = "0.3.5" fs2 = "0.4.2" serde = "1.0" serde_derive = "1.0" -serde_json = "1.0" \ No newline at end of file +serde_json = "1.0" +tempfile = "2.2.0" \ No newline at end of file diff --git a/ofborg/src/bin/builder.rs b/ofborg/src/bin/builder.rs index 02c4d8a..711b164 100644 --- a/ofborg/src/bin/builder.rs +++ b/ofborg/src/bin/builder.rs @@ -17,6 +17,7 @@ use ofborg::config; use ofborg::checkout; use ofborg::worker; use ofborg::message::buildjob; +use ofborg::nix; fn main() { let cfg = config::load(env::args().nth(1).unwrap().as_ref()); @@ -90,18 +91,13 @@ impl worker::SimpleWorker for BuildWorker { None => { String::from("origin/master") } }; - let refpath = co.checkout_ref(target_branch.as_ref()); + let refpath = co.checkout_ref(target_branch.as_ref()).unwrap(); co.fetch_pr(job.pr.number).unwrap(); co.merge_commit(job.pr.head_sha.as_ref()).unwrap(); - match refpath { - Ok(path) => { - println!("Got path: {:?}", path); - } - Err(wat) => { - println!("Failed to do a checkout of ref : {:?}", wat); - } - } + println!("Got path: {:?}", refpath); + + let cmd = nix::safely_build_attrs_cmd(refpath, job.attrs); return Ok(()) } diff --git a/ofborg/src/lib.rs b/ofborg/src/lib.rs index a3ce06d..90788e1 100644 --- a/ofborg/src/lib.rs +++ b/ofborg/src/lib.rs @@ -3,6 +3,7 @@ extern crate serde_derive; extern crate serde; extern crate serde_json; +extern crate tempfile; extern crate amqp; extern crate fs2; extern crate md5; @@ -13,6 +14,7 @@ pub mod clone; pub mod worker; pub mod config; pub mod message; +pub mod nix; pub mod ofborg { pub use config; @@ -21,5 +23,5 @@ pub mod ofborg { pub use clone; pub use worker; pub use message; - + pub use nix; } diff --git a/ofborg/src/message/buildjob.rs b/ofborg/src/message/buildjob.rs index b41b957..25e4637 100644 --- a/ofborg/src/message/buildjob.rs +++ b/ofborg/src/message/buildjob.rs @@ -5,6 +5,7 @@ use serde_json; pub struct BuildJob { pub repo: Repo, pub pr: Pr, + pub attrs: Vec, } pub fn from(data: &Vec) -> Result { diff --git a/ofborg/src/nix.rs b/ofborg/src/nix.rs new file mode 100644 index 0000000..d6754aa --- /dev/null +++ b/ofborg/src/nix.rs @@ -0,0 +1,48 @@ +use std::path::Path; +use std::ffi::OsString; +use std::process::{Command,Stdio}; +use tempfile::tempfile; +use std::fs::File; + +pub fn safely_build_attrs(nixpkgs: &Path, attrs: Vec) -> Result { + let mut nixpath = OsString::new(); + nixpath.push("nixpkgs="); + nixpath.push(nixpkgs.as_os_str()); + + let stdout = tempfile().unwrap(); + let stderr = stdout.try_clone().unwrap(); + let reader = stderr.try_clone().unwrap(); + + let mut cmd = Command::new("nix-build") + .env_clear() + .current_dir(nixpkgs) + .stdout(Stdio::from(stdout)) + .stderr(Stdio::from(stderr)) + .env("NIX_PATH", nixpath); + + for attr in attrs { + cmd.arg("-A"); + cmd.arg(attr); + } + + let stat = cmd + .status() + .unwrap(); + + + return Ok(reader); +} + +/* + $attrs = array_intersperse(array_values((array)$body->attrs), '-A'); + var_dump($attrs); + + $fillers = implode(" ", array_fill(0, count($attrs), '%s')); + + $cmd = 'NIX_PATH=nixpkgs=%s nix-build --no-out-link --argstr system %s --option restrict-eval true --keep-going . ' . $fillers; + $args = $attrs; + array_unshift($args, NIX_SYSTEM); + array_unshift($args, $pname); + + +*/ diff --git a/shell.nix b/shell.nix index f07b953..481e36a 100644 --- a/shell.nix +++ b/shell.nix @@ -1,5 +1,12 @@ let - pkgs = import {}; + p = import {}; + pkgs = import (p.fetchFromGitHub { + owner = "NixOS"; + repo = "nixpkgs-channels"; + rev = "cfafd6f5a819472911eaf2650b50a62f0c143e3e"; + sha256 = "10xgiyh4hbwwiy8qg70ma1f27nd717aflksk9fx3ci8bmxmqbkkn"; + }) {}; + inherit (pkgs) stdenv;