const std = @import("std"); const process = std.process; const heap = std.heap; const mem = std.mem; const fs = std.fs; const libvirt = @import("libvirt.zig"); pub fn main() !void { var gpa = heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); const connection = try libvirt.Connection.connect("qemu:///system", allocator); defer connection.close(); var flake_dir = try fs.cwd().openDir("flakes/windows/test", .{}); defer flake_dir.close(); var nix = process.Child.init(&[_][]const u8{ "nix", "build", ".#volume", "-o", "volume" }, allocator); nix.cwd_dir = flake_dir; _ = try nix.spawnAndWait(); nix.argv = &[_][]const u8{ "nix", "build", ".#beforeInstall", "-o", "beforeInstall" }; _ = try nix.spawnAndWait(); nix.argv = &[_][]const u8{ "nix", "build", ".#afterInstall", "-o", "afterInstall" }; _ = try nix.spawnAndWait(); nix.argv = &[_][]const u8{ "nix", "build", ".#beforeBoot", "-o", "beforeBoot" }; _ = try nix.spawnAndWait(); nix.argv = &[_][]const u8{ "nix", "build", ".#afterBoot", "-o", "afterBoot" }; _ = try nix.spawnAndWait(); // const volume_def = try flake_dir.openFile("volume", .{}); // defer volume_def.close(); // const volume_xml = try volume_def.readToEndAlloc(allocator, 1024 * 1024); // defer allocator.free(volume_xml); // const volume = try connection.defineVolume(volume_xml); // -------------- const uri = try connection.getURI(); defer connection.freeURI(uri); std.debug.print("uri: {s}\n", .{uri}); const num_active = try connection.numOfDomains(); const num_inactive = try connection.numOfDefinedDomains(); std.debug.print("active: {d}, inactive: {d}\n", .{ num_active, num_inactive }); var domain_iter = try connection.iterateDomains(&[_]libvirt.Domain.ListFlags{ libvirt.Domain.ListFlags.Active, libvirt.Domain.ListFlags.Inactive, }); defer domain_iter.deinit(); while (domain_iter.next()) |domain| { const active = domain.isActive(); const name = domain.getName(); std.debug.print("name: {s}, active: {any}\n", .{ name, active }); } } pub const DomainSpec = struct { os: Quad, preinstalledSoftware: []const []const u8, modules: []const []const u8, }; pub const Quad = struct { name: []const u8, version: []const u8, edition: []const u8, arch: []const u8, };