Skip to content

Commit

Permalink
0.1.3: check if /var/run/reboot-required already exists because of a …
Browse files Browse the repository at this point in the history
…prior run
  • Loading branch information
thefossguy committed Mar 5, 2024
1 parent e886f29 commit eec6546
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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=";
};
});
};
Expand Down
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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<dyn Error>> {
let user = std::env::var_os("USER")
Expand All @@ -16,14 +18,15 @@ fn main() -> Result<(), Box<dyn Error>> {
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!!!");
}
Expand Down

0 comments on commit eec6546

Please sign in to comment.