diff --git a/Cargo.lock b/Cargo.lock index f98d858..6205767 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "nixos-reedsreboot" -version = "0.1.2" +version = "0.1.3" dependencies = [ "strum", "strum_macros", diff --git a/Cargo.toml b/Cargo.toml index 41ba011..7d3e66f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nixos-reedsreboot" -version = "0.1.2" +version = "0.1.3" edition = "2021" description = "Determine if you need to reboot your NixOS machine" license = "GPL-2.0" diff --git a/flake.nix b/flake.nix index 4dc94cc..8484845 100644 --- a/flake.nix +++ b/flake.nix @@ -34,10 +34,10 @@ packages = forEachSupportedSystem ({ pkgs, ... }: { default = pkgs.rustPlatform.buildRustPackage { pname = "nixos-needsreboot"; - version = "0.1.2"; + version = "0.1.3"; src = ./.; - cargoHash = "sha256-z/LhXoi1JoMGgUX3Y1xOI9Ehz2rETApWUgsd5C6Y9Nk="; + cargoHash = "sha256-YLXyzm5DTMNR3fMPSWvuy/gnTY3sHBzuBPwUMPiBzJY="; }; }); }; diff --git a/src/main.rs b/src/main.rs index caaf403..df1405b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,12 @@ use std::error::Error; use std::fs; +use std::path::Path; mod compare_nixos_modules; pub static OLD_SYSTEM_PATH: &str = "/run/booted-system"; pub static NEW_SYSTEM_PATH: &str = "/nix/var/nix/profiles/system"; +pub static NIXOS_NEEDS_REBOOT: &str = "/var/run/reboot-required"; fn main() -> Result<(), Box> { let user = std::env::var_os("USER") @@ -16,14 +18,15 @@ fn main() -> Result<(), Box> { std::process::exit(1); } - if std::path::Path::new("/nix/var/nix/profiles/system").exists() { + if Path::new("/nix/var/nix/profiles/system").exists() { + let needs_reboot = Path::new(NIXOS_NEEDS_REBOOT).exists(); let old_system_id = fs::read_to_string(OLD_SYSTEM_PATH.to_string() + "/nixos-version")?; let new_system_id = fs::read_to_string(NEW_SYSTEM_PATH.to_string() + "/nixos-version")?; if old_system_id == new_system_id { eprintln!("DEBUG: you are using the latest NixOS generation, no need to reboot"); - } else if compare_nixos_modules::upgrades_available()? { - fs::File::create("/var/run/reboot-required")?; + } else if needs_reboot || compare_nixos_modules::upgrades_available()? { + fs::File::create(NIXOS_NEEDS_REBOOT)?; } else { eprintln!("DEBUG: no updates available, moar uptime!!!"); }