aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/no/notify-run
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/no/notify-run')
-rw-r--r--pkgs/by-name/no/notify-run/Cargo.lock4
-rw-r--r--pkgs/by-name/no/notify-run/Cargo.toml2
-rw-r--r--pkgs/by-name/no/notify-run/flake.lock27
-rw-r--r--pkgs/by-name/no/notify-run/flake.lock.license9
-rw-r--r--pkgs/by-name/no/notify-run/flake.nix7
-rw-r--r--pkgs/by-name/no/notify-run/src/main.rs82
-rwxr-xr-xpkgs/by-name/no/notify-run/update.sh4
7 files changed, 65 insertions, 70 deletions
diff --git a/pkgs/by-name/no/notify-run/Cargo.lock b/pkgs/by-name/no/notify-run/Cargo.lock
index c94414f8..c1ff746e 100644
--- a/pkgs/by-name/no/notify-run/Cargo.lock
+++ b/pkgs/by-name/no/notify-run/Cargo.lock
@@ -13,9 +13,9 @@ version = 4
[[package]]
name = "anyhow"
-version = "1.0.101"
+version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea"
+checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
[[package]]
name = "notify-run"
diff --git a/pkgs/by-name/no/notify-run/Cargo.toml b/pkgs/by-name/no/notify-run/Cargo.toml
index 8c36c3e9..ceff208e 100644
--- a/pkgs/by-name/no/notify-run/Cargo.toml
+++ b/pkgs/by-name/no/notify-run/Cargo.toml
@@ -17,4 +17,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-anyhow = "1.0.101"
+anyhow = "1.0.104"
diff --git a/pkgs/by-name/no/notify-run/flake.lock b/pkgs/by-name/no/notify-run/flake.lock
deleted file mode 100644
index d5681f40..00000000
--- a/pkgs/by-name/no/notify-run/flake.lock
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "nodes": {
- "nixpkgs": {
- "locked": {
- "lastModified": 1770843696,
- "narHash": "sha256-LovWTGDwXhkfCOmbgLVA10bvsi/P8eDDpRudgk68HA8=",
- "owner": "NixOS",
- "repo": "nixpkgs",
- "rev": "2343bbb58f99267223bc2aac4fc9ea301a155a16",
- "type": "github"
- },
- "original": {
- "owner": "NixOS",
- "ref": "nixpkgs-unstable",
- "repo": "nixpkgs",
- "type": "github"
- }
- },
- "root": {
- "inputs": {
- "nixpkgs": "nixpkgs"
- }
- }
- },
- "root": "root",
- "version": 7
-}
diff --git a/pkgs/by-name/no/notify-run/flake.lock.license b/pkgs/by-name/no/notify-run/flake.lock.license
deleted file mode 100644
index eae6a84c..00000000
--- a/pkgs/by-name/no/notify-run/flake.lock.license
+++ /dev/null
@@ -1,9 +0,0 @@
-nixos-config - My current NixOS configuration
-
-Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
-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 <https://www.gnu.org/licenses/gpl-3.0.txt>.
diff --git a/pkgs/by-name/no/notify-run/flake.nix b/pkgs/by-name/no/notify-run/flake.nix
index 07be3258..ea5fecb2 100644
--- a/pkgs/by-name/no/notify-run/flake.nix
+++ b/pkgs/by-name/no/notify-run/flake.nix
@@ -11,12 +11,13 @@
description = "An safe way to run applications, that might fail";
inputs = {
- nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
- outputs = {nixpkgs, ...}: let
+ outputs = {...}: let
system = "x86_64-linux";
- pkgs = nixpkgs.legacyPackages."${system}";
+ sources = import ../../../../npins/full.nix {};
+
+ pkgs = (sources.loadFlake "nixpkgs").legacyPackages."${system}";
in {
devShells."${system}".default = pkgs.mkShell {
packages = [
diff --git a/pkgs/by-name/no/notify-run/src/main.rs b/pkgs/by-name/no/notify-run/src/main.rs
index a6a0165a..94f9ad4e 100644
--- a/pkgs/by-name/no/notify-run/src/main.rs
+++ b/pkgs/by-name/no/notify-run/src/main.rs
@@ -8,7 +8,13 @@
// You should have received a copy of the License along with this program.
// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
-use std::{env::args, path::PathBuf, process::Command};
+use std::{
+ env::args,
+ io::{BufRead, BufReader, Read, Write},
+ path::PathBuf,
+ process::{Command, Stdio},
+ thread::JoinHandle,
+};
use anyhow::{Context, Result};
@@ -20,18 +26,40 @@ fn main() -> Result<()> {
cmd.args(arguments.split(" ").collect::<Vec<_>>().as_slice());
}
- eprintln!("Spawning {:?}", cmd);
+ eprintln!("notify-run> Spawning {:?}", cmd);
- let output = cmd
- .output()
- .with_context(|| format!("Failed to spawn and await output of {:?}", cmd))?;
+ let mut child = cmd
+ .stderr(Stdio::piped())
+ .stdout(Stdio::piped())
+ .spawn()
+ .with_context(|| format!("Failed to spawn {:?}", cmd))?;
- if !output.status.success() {
+ let (stdout, stderr) = (
+ child.stdout.take().expect("Was piped"),
+ child.stderr.take().expect("Was piped"),
+ );
+
+ let name = PathBuf::from(&args[0])
+ .file_name()
+ .expect("this to be a command, and thus have a file_name")
+ .to_string_lossy()
+ .to_string();
+
+ let stdout_t = write_thread(stdout, name.to_owned());
+ let stderr_t = write_thread(stderr, name.to_owned());
+ stdout_t
+ .join()
+ .unwrap()
+ .context("Failed to join stdout thread")?;
+ stderr_t
+ .join()
+ .unwrap()
+ .context("Failed to join stderr thread")?;
+
+ let status = child.wait().context("Failed to wait for child output")?;
+ if !status.success() {
let mut notify_send = Command::new("notify-send");
- notify_send.args([
- format!("Command {:?} failed", cmd).as_str(),
- &String::from_utf8_lossy(output.stderr.as_slice()),
- ]);
+ notify_send.args([format!("Command {:?} failed", cmd).as_str()]);
notify_send.status().with_context(|| {
format!(
@@ -39,27 +67,29 @@ fn main() -> Result<()> {
cmd
)
})?;
- } else {
- let name = PathBuf::from(&args[0])
- .file_name()
- .expect("this to be a command, and thus have a file_name")
- .to_string_lossy()
- .to_string();
-
- print!("{}", append_name(&name, &output.stdout));
- eprint!("{}", append_name(&name, &output.stderr));
}
Ok(())
}
-fn append_name(name: &str, base: &[u8]) -> String {
- let base = String::from_utf8_lossy(base).to_string();
+fn write_thread<R: Read + Send + 'static>(input: R, name: String) -> JoinHandle<Result<()>> {
+ std::thread::spawn(move || {
+ let mut reader = BufReader::new(input);
- let mut output = String::new();
- for line in base.lines() {
- output.push_str(format!("{name}> {line}\n").as_str());
- }
+ let mut buf = String::new();
+ loop {
+ buf.clear();
+ if reader
+ .read_line(&mut buf)
+ .context("Failed to read from child output")?
+ == 0
+ {
+ break;
+ }
+
+ write!(std::io::stdout(), "{name}> {buf}")?;
+ }
- output
+ Ok(())
+ })
}
diff --git a/pkgs/by-name/no/notify-run/update.sh b/pkgs/by-name/no/notify-run/update.sh
index 23d90a86..188771c4 100755
--- a/pkgs/by-name/no/notify-run/update.sh
+++ b/pkgs/by-name/no/notify-run/update.sh
@@ -10,5 +10,5 @@
# You should have received a copy of the License along with this program.
# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
-[ "$1" = "upgrade" ] && cargo upgrade
-cargo update
+[ "$1" = "upgrade" ] && cargo upgrade --incompatible allow --pinned allow --recursive true
+cargo update --recursive