Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

initial reboot command, without actually rebooting

+46
+7
cli/src/main.rs
··· 58 58 #[arg(long, short, value_name = "seed name")] 59 59 name: Option<String>, 60 60 }, 61 + 62 + Reboot { 63 + #[arg(long, short, default_value_t = false)] 64 + yes: bool, 65 + }, 61 66 } 62 67 63 68 #[tokio::main] ··· 118 123 println!("{:#?}", seed); 119 124 () 120 125 } 126 + 127 + Actions::Reboot { yes } => Tree::reboot(yes.clone()), 121 128 _ => panic!("unsupported action"), 122 129 } 123 130
+39
cli/src/sower.rs
··· 1 1 use clap::ValueEnum; 2 2 use serde::Deserialize; 3 + use std::fs; 3 4 use std::io::{self, Write}; 4 5 use std::process::Command; 5 6 use strum::{Display, VariantNames}; ··· 137 138 .await?) 138 139 } 139 140 } 141 + 142 + #[derive(Debug)] 143 + pub struct Tree {} 144 + 145 + impl Tree { 146 + pub fn reboot(confirm: bool) { 147 + if Self::reboot_needed().expect("failed to check reboot state") { 148 + println!("Reboot needed."); 149 + } else { 150 + println!("No reboot necessary."); 151 + return; 152 + } 153 + 154 + if !confirm { 155 + println!("Check mode enabled, skipping reboot"); 156 + return; 157 + } 158 + 159 + Self::run_reboot() 160 + } 161 + 162 + pub fn reboot_needed() -> std::io::Result<bool> { 163 + let profile_paths = &["initrd", "kernel", "kernel-modules"]; 164 + let result = profile_paths.iter().any(|&path| { 165 + let current_path = format!("/nix/var/nix/profiles/system/{}", path); 166 + let booted_path = format!("/run/booted-system/{}", path); 167 + let current = fs::read_link(current_path).expect("unstable to read current link"); 168 + let booted = fs::read_link(booted_path).expect("unable to read booted link"); 169 + 170 + current != booted 171 + }); 172 + Ok(result) 173 + } 174 + 175 + pub fn run_reboot() { 176 + println!("Rebooting") 177 + } 178 + }