Struct Config

Source
pub struct Config { /* private fields */ }
Expand description

Build style configration for a pending build.

Implementations§

Source§

impl Config

Source

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}
Source

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> {}")
Source

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")
Source

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")
Source

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}
Source

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()
Source

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

Source

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§

Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.