pub struct Config { /* private fields */ }
Expand description
Build style configration for a pending build.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new nix build Config
Target is defaulted to default.nix
Examples found in repository?
examples/hello.rs (line 4)
3fn main() {
4 let outputs = nix::Config::new()
5 .target_flake("nixpkgs#hello")
6 .build()
7 .expect("nix build to work");
8
9 let hello = outputs[0].out().expect("default output to be available");
10
11 let stdout = std::process::Command::new(format!("{}/bin/hello", hello.display().to_string()))
12 .output()
13 .expect("hello to succeed")
14 .stdout;
15
16 let stdout = std::str::from_utf8(&stdout).expect("stdout to be UTF-8");
17 assert!(stdout == "Hello, world!\n");
18
19 print!("{}", stdout);
20}
Sourcepub fn arg_expr(&mut self, name: &str, value: &str) -> &mut Self
pub fn arg_expr(&mut self, name: &str, value: &str) -> &mut Self
Add an expression argument to the invoked nix expression
§Example
Config::default().arg_expr("{pkgs}:pkgs.hello").arg_expr("pkgs", "import <nixpkgs> {}")
Sourcepub fn arg_str(&mut self, name: &str, value: &str) -> &mut Self
pub fn arg_str(&mut self, name: &str, value: &str) -> &mut Self
Add a string argument to the invoked nix expression
§Example
Config::default().arg_str("{pkgs,name}:pkgs.hello.overrideAttrs (_: {inherit name;})").arg_str("name", "not-hello")
Sourcepub fn target_file(&mut self, filename: impl AsRef<OsStr>) -> &mut Self
pub fn target_file(&mut self, filename: impl AsRef<OsStr>) -> &mut Self
Build the derivation described by the given .nix file
§Example
Config::default().target_file("hello.nix")
Sourcepub fn target_flake(&mut self, flake: &str) -> &mut Self
pub fn target_flake(&mut self, flake: &str) -> &mut Self
Build the derivation described by the given flake output
§Example
Config::default().target_flake("nixpkgs#hello")
Examples found in repository?
examples/hello.rs (line 5)
3fn main() {
4 let outputs = nix::Config::new()
5 .target_flake("nixpkgs#hello")
6 .build()
7 .expect("nix build to work");
8
9 let hello = outputs[0].out().expect("default output to be available");
10
11 let stdout = std::process::Command::new(format!("{}/bin/hello", hello.display().to_string()))
12 .output()
13 .expect("hello to succeed")
14 .stdout;
15
16 let stdout = std::str::from_utf8(&stdout).expect("stdout to be UTF-8");
17 assert!(stdout == "Hello, world!\n");
18
19 print!("{}", stdout);
20}
Sourcepub fn target_expr(&mut self, expr: &str) -> &mut Self
pub fn target_expr(&mut self, expr: &str) -> &mut Self
Build the derivation described by the given expression
§Example
Config::default().target_expr("{pkgs}: pkgs.hello").build()
Sourcepub fn impure(&mut self, impure: bool) -> &mut Self
pub fn impure(&mut self, impure: bool) -> &mut Self
Set to enable impure evaluation mode
Will pass the --impure
flag to the invocation if set
Sourcepub fn build(&self) -> Result<Vec<Derivation>, Error>
pub fn build(&self) -> Result<Vec<Derivation>, Error>
Invoke nix build
with the given configuration
Examples found in repository?
examples/hello.rs (line 6)
3fn main() {
4 let outputs = nix::Config::new()
5 .target_flake("nixpkgs#hello")
6 .build()
7 .expect("nix build to work");
8
9 let hello = outputs[0].out().expect("default output to be available");
10
11 let stdout = std::process::Command::new(format!("{}/bin/hello", hello.display().to_string()))
12 .output()
13 .expect("hello to succeed")
14 .stdout;
15
16 let stdout = std::str::from_utf8(&stdout).expect("stdout to be UTF-8");
17 assert!(stdout == "Hello, world!\n");
18
19 print!("{}", stdout);
20}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more