Skip to main content

guix_scheme/
lib.rs

1//! Read, edit, and generate Guix Scheme files (channels.scm, system config.scm) from Rust.
2//!
3//! ```
4//! use guix_scheme::{Channel, ChannelsFile};
5//! let mut cf = ChannelsFile::parse("(list)").unwrap();
6//! cf.add_channel(&Channel {
7//!     name: "pantherx".into(),
8//!     url: "https://codeberg.org/gofranz/panther.git".into(),
9//!     branch: Some("master".into()),
10//!     commit: None,
11//!     introduction_commit: Some("54b4056ac571611892c743b65f4c47dc298c49da".into()),
12//!     introduction_fingerprint: Some("A36A D41E ECC7 A871 1003  5D24 524F EB1A 9D33 C9CB".into()),
13//! }).unwrap();
14//! assert!(cf.to_string().contains("(name 'pantherx)"));
15//! ```
16//!
17//! # Boundaries
18//!
19//! String in, string out: this crate parses `&str` and renders back to
20//! `String`, and does no file IO. Reading files, writing them atomically,
21//! keeping backups, and refusing symlinks or store-managed paths are the
22//! caller's job.
23//!
24//! Edits are byte-preserving. Running on a lossless CST (see `scheme-edit`),
25//! adding or removing a channel keeps every untouched byte and comment intact
26//! and only formats the node it inserts, instead of reflowing the whole file.
27
28mod channel;
29mod channels_file;
30mod error;
31#[cfg(feature = "guile-check")]
32pub mod guile_check;
33pub mod module;
34pub mod os_builder;
35pub mod os_view;
36pub mod record;
37pub mod services;
38pub mod validate;
39
40pub use channel::Channel;
41pub use channels_file::{ChannelsFile, ChannelsShape};
42pub use error::Error;
43pub use module::{ModuleFile, PackageView, PackageViewMut, RecordFieldView, RecordTypeView};
44pub use os_view::{OperatingSystemView, OperatingSystemViewMut};
45pub use services::{ServicesView, ServicesViewMut};
46
47/// Cheap syntax check: `Ok(())` iff SRC parses as Scheme.
48///
49/// This only verifies the surface syntax (balanced delimiters, valid
50/// tokens); it does not evaluate the form or resolve any Guix bindings.
51/// For a deeper check that actually loads the config, enable the
52/// `guile-check` feature.
53pub fn validate_syntax(src: &str) -> Result<(), Error> {
54    scheme_edit::Document::parse(src)?;
55    Ok(())
56}