nixpkgs/pkgs/by-name/sw/switch-to-configuration-ng/build.rs
Jared Baur 32bf051ba4
nixos/switch-to-configuration: add new implementation
This adds an implementation of switch-to-configuration that allows for
closer interaction with the lifecycle of systemd units by using DBus
APIs directly instead of using systemctl. It is disabled by default, but
can be enabled by specifying `{ system.switch = { enable = false; enableNg = true; }; }`.
2024-05-10 16:33:06 -07:00

31 lines
1.2 KiB
Rust

use std::io::Write;
fn code_for_dbus_xml(xml: impl AsRef<std::path::Path>) -> String {
dbus_codegen::generate(
&std::fs::read_to_string(xml).unwrap(),
&dbus_codegen::GenOpts {
methodtype: None,
connectiontype: dbus_codegen::ConnectionType::Blocking,
..Default::default()
},
)
.unwrap()
}
fn main() {
let systemd_dbus_interface_dir = std::env::var("SYSTEMD_DBUS_INTERFACE_DIR").unwrap();
let systemd_dbus_interface_dir = std::path::Path::new(systemd_dbus_interface_dir.as_str());
let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
let systemd_manager_code =
code_for_dbus_xml(systemd_dbus_interface_dir.join("org.freedesktop.systemd1.Manager.xml"));
let mut file = std::fs::File::create(out_path.join("systemd_manager.rs")).unwrap();
file.write_all(systemd_manager_code.as_bytes()).unwrap();
let logind_manager_code =
code_for_dbus_xml(systemd_dbus_interface_dir.join("org.freedesktop.login1.Manager.xml"));
let mut file = std::fs::File::create(out_path.join("logind_manager.rs")).unwrap();
file.write_all(logind_manager_code.as_bytes()).unwrap();
}