Skip to main content

ChannelsFile

Struct ChannelsFile 

Source
pub struct ChannelsFile { /* private fields */ }

Implementations§

Source§

impl ChannelsFile

Source

pub fn parse(src: &str) -> Result<Self, Error>

Finds the first top-level list/cons/cons* form (preamble forms like use-modules are skipped) or a bare %default-channels symbol.

Examples found in repository?
examples/format_demo.rs (line 27)
4fn main() {
5    let os = OsBuilder::new(
6        OsFlavor::Panther,
7        "panther-box",
8        "Europe/Berlin",
9        "en_US.utf8",
10    )
11    .keyboard_layout("us", None)
12    .bootloader_efi("/boot/efi")
13    .file_system("/", FsDevice::Label("my-root".into()), "ext4", false)
14    .file_system(
15        "/boot/efi",
16        FsDevice::UuidWithType("ABCD-1234".into(), "fat32".into()),
17        "vfat",
18        false,
19    )
20    .user("panther", "panther's account", &["wheel", "audio", "video"])
21    .packages_field("%os-desktop-packages")
22    .services_field("%os-desktop-services")
23    .extra_field("swap-devices", "(list (swap-space (target \"/swapfile\")))")
24    .build();
25    println!("=== system.scm ===\n{os}");
26
27    let mut cf = ChannelsFile::parse("%default-channels").unwrap();
28    cf.add_channel(&Channel {
29        name: "pantherx".into(),
30        url: "https://codeberg.org/gofranz/panther.git".into(),
31        branch: Some("master".into()),
32        commit: None,
33        introduction_commit: Some("54b4056ac571611892c743b65f4c47dc298c49da".into()),
34        introduction_fingerprint: Some("A36A D41E ECC7 A871 1003  5D24 524F EB1A 9D33 C9CB".into()),
35    })
36    .unwrap();
37    println!("=== channels.scm (from bare %default-channels) ===\n{cf}");
38
39    let src = ";; my channels\n(list\n ;; the guix channel\n (channel\n  (name 'guix)\n  (url \"https://git.savannah.gnu.org/git/guix.git\")))\n";
40    let mut cf2 = ChannelsFile::parse(src).unwrap();
41    cf2.add_channel(&Channel {
42        name: "nonguix".into(),
43        url: "https://gitlab.com/nonguix/nonguix".into(),
44        branch: None,
45        commit: None,
46        introduction_commit: Some("897c1a470da759236cc11798f4e0a5f7d4d59fbc".into()),
47        introduction_fingerprint: Some("2A39 3FFF 68F4 EF7A 3D29  12AF 6F51 20A0 22FB B2D5".into()),
48    })
49    .unwrap();
50    println!("=== channels.scm (appended to commented list) ===\n{cf2}");
51}
Source

pub fn shape(&self) -> ChannelsShape

Source

pub fn channels(&self) -> Vec<Channel>

The channels enumerated in the file (defaults stay implicit).

Source

pub fn add_channel(&mut self, ch: &Channel) -> Result<(), Error>

Append (Explicit) or insert before the %default-channels tail (WithDefaults). A cons head is promoted to cons*.

Examples found in repository?
examples/format_demo.rs (lines 28-35)
4fn main() {
5    let os = OsBuilder::new(
6        OsFlavor::Panther,
7        "panther-box",
8        "Europe/Berlin",
9        "en_US.utf8",
10    )
11    .keyboard_layout("us", None)
12    .bootloader_efi("/boot/efi")
13    .file_system("/", FsDevice::Label("my-root".into()), "ext4", false)
14    .file_system(
15        "/boot/efi",
16        FsDevice::UuidWithType("ABCD-1234".into(), "fat32".into()),
17        "vfat",
18        false,
19    )
20    .user("panther", "panther's account", &["wheel", "audio", "video"])
21    .packages_field("%os-desktop-packages")
22    .services_field("%os-desktop-services")
23    .extra_field("swap-devices", "(list (swap-space (target \"/swapfile\")))")
24    .build();
25    println!("=== system.scm ===\n{os}");
26
27    let mut cf = ChannelsFile::parse("%default-channels").unwrap();
28    cf.add_channel(&Channel {
29        name: "pantherx".into(),
30        url: "https://codeberg.org/gofranz/panther.git".into(),
31        branch: Some("master".into()),
32        commit: None,
33        introduction_commit: Some("54b4056ac571611892c743b65f4c47dc298c49da".into()),
34        introduction_fingerprint: Some("A36A D41E ECC7 A871 1003  5D24 524F EB1A 9D33 C9CB".into()),
35    })
36    .unwrap();
37    println!("=== channels.scm (from bare %default-channels) ===\n{cf}");
38
39    let src = ";; my channels\n(list\n ;; the guix channel\n (channel\n  (name 'guix)\n  (url \"https://git.savannah.gnu.org/git/guix.git\")))\n";
40    let mut cf2 = ChannelsFile::parse(src).unwrap();
41    cf2.add_channel(&Channel {
42        name: "nonguix".into(),
43        url: "https://gitlab.com/nonguix/nonguix".into(),
44        branch: None,
45        commit: None,
46        introduction_commit: Some("897c1a470da759236cc11798f4e0a5f7d4d59fbc".into()),
47        introduction_fingerprint: Some("2A39 3FFF 68F4 EF7A 3D29  12AF 6F51 20A0 22FB B2D5".into()),
48    })
49    .unwrap();
50    println!("=== channels.scm (appended to commented list) ===\n{cf2}");
51}
Source

pub fn remove_channel(&mut self, name: &str) -> Result<(), Error>

Removes the whole element (wrapper included) plus attached leading comments/blanks. A cons/cons* form left with only the tail collapses to (cons* %default-channels).

Trait Implementations§

Source§

impl Debug for ChannelsFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ChannelsFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.