From 605f131560a65af3448f02fb3990c1967ad488d0 Mon Sep 17 00:00:00 2001 From: Soispha Peetz Date: Thu, 3 Dec 2026 23:12:40 +0100 Subject: pkgs/fupdate-sys2: Re-implement in rust Does not yet remove the shell version, because I'm not fully sure the rust version works. The rust version should also set the new boot entry forever, and not just for exactly one boot. --- pkgs/by-name/fu/fupdate-sys2/src/cli.rs | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 pkgs/by-name/fu/fupdate-sys2/src/cli.rs (limited to 'pkgs/by-name/fu/fupdate-sys2/src/cli.rs') diff --git a/pkgs/by-name/fu/fupdate-sys2/src/cli.rs b/pkgs/by-name/fu/fupdate-sys2/src/cli.rs new file mode 100644 index 00000000..cf8a796e --- /dev/null +++ b/pkgs/by-name/fu/fupdate-sys2/src/cli.rs @@ -0,0 +1,84 @@ +// nixos-config - My current NixOS configuration +// +// Copyright (C) 2025 Benedikt Peetz +// SPDX-License-Identifier: GPL-3.0-or-later +// +// This file is part of my nixos-config. +// +// You should have received a copy of the License along with this program. +// If not, see . + +use core::fmt; +use std::{ffi::OsStr, process::Command}; + +use clap::{Parser, ValueEnum}; +use clap_complete::{CompletionCandidate, engine::ArgValueCompleter}; + +/// This is a Nix flake update manager. +#[derive(Parser, Debug)] +#[command(author, version, about)] +pub struct CliArgs { + /// The branch to update from. + #[arg(short, long, add = ArgValueCompleter::new(get_branches))] + pub branch: Option, + + /// The mode to update with. + #[arg(short, long, default_value_t = Mode::Switch)] + pub mode: Mode, + + /// Don't actually make changes. + #[arg(short, long)] + pub dry_run: bool, +} + +#[derive(Debug, Clone, Copy, ValueEnum)] +pub enum Mode { + Switch, + Boot, + Test, + Build, + DryBuild, + DryActivate, + Edit, + Repl, + BuildVm, + BuildVmWithBootloader, +} + +impl fmt::Display for Mode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", format!("{self:?}").to_lowercase()) + } +} + +fn get_branches(current: &OsStr) -> Vec { + let mut output = vec![]; + + let Some(current) = current.to_str() else { + return output; + }; + + let Ok(git_output) = Command::new("git") + .args(["branch", "--list", "--format", "'%(refname:short)'"]) + .current_dir("/etc/nixos") + .output() + else { + return output; + }; + + if !git_output.status.success() { + return output; + } + + let Ok(possible) = String::from_utf8(git_output.stdout) else { + return output; + }; + + for possible in possible.trim().split('\n') { + if possible.starts_with(current) { + output.push(CompletionCandidate::new(possible)); + } + } + + output +} -- cgit v1.3.1