diff options
Diffstat (limited to '')
| -rw-r--r-- | pkgs/by-name/no/notify-run/.envrc (renamed from modules/home.legacy/conf/alacritty/yaml/scrolling.yml) | 17 | ||||
| -rw-r--r-- | pkgs/by-name/no/notify-run/.gitignore (renamed from pkgs/by-name/ge/generate_moz_extension/.gitignore) | 3 | ||||
| -rw-r--r-- | pkgs/by-name/no/notify-run/Cargo.lock | 25 | ||||
| -rw-r--r-- | pkgs/by-name/no/notify-run/Cargo.toml (renamed from pkgs/by-name/ge/generate_moz_extension/Cargo.toml) | 12 | ||||
| -rw-r--r-- | pkgs/by-name/no/notify-run/flake.nix | 35 | ||||
| -rw-r--r-- | pkgs/by-name/no/notify-run/package.nix | 41 | ||||
| -rw-r--r-- | pkgs/by-name/no/notify-run/src/main.rs | 95 | ||||
| -rwxr-xr-x[-rw-r--r--] | pkgs/by-name/no/notify-run/update.sh (renamed from modules/home.legacy/conf/alacritty/toml/env.toml) | 7 |
8 files changed, 218 insertions, 17 deletions
diff --git a/modules/home.legacy/conf/alacritty/yaml/scrolling.yml b/pkgs/by-name/no/notify-run/.envrc index 0d108f76..880b1809 100644 --- a/modules/home.legacy/conf/alacritty/yaml/scrolling.yml +++ b/pkgs/by-name/no/notify-run/.envrc @@ -1,3 +1,5 @@ +#!/usr/bin/env sh + # nixos-config - My current NixOS configuration # # Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> @@ -8,10 +10,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>. -scrolling: - # Maximum number of lines in the scrollback buffer. - # Specifying '0' will disable scrolling. - history: 10000 +use flake || use nix +watch_file flake.nix + +PATH_add ./target/debug +PATH_add ./target/release +PATH_add ./scripts - # Scrolling distance multiplier. - multiplier: 3 +if on_git_branch; then + echo && git status --short --branch +fi diff --git a/pkgs/by-name/ge/generate_moz_extension/.gitignore b/pkgs/by-name/no/notify-run/.gitignore index cc03ebd7..8f29eabf 100644 --- a/pkgs/by-name/ge/generate_moz_extension/.gitignore +++ b/pkgs/by-name/no/notify-run/.gitignore @@ -8,6 +8,9 @@ # 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>. +# build /target /result + +# dev env .direnv diff --git a/pkgs/by-name/no/notify-run/Cargo.lock b/pkgs/by-name/no/notify-run/Cargo.lock new file mode 100644 index 00000000..c1ff746e --- /dev/null +++ b/pkgs/by-name/no/notify-run/Cargo.lock @@ -0,0 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +# 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>. +version = 4 + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "notify-run" +version = "0.1.0" +dependencies = [ + "anyhow", +] diff --git a/pkgs/by-name/ge/generate_moz_extension/Cargo.toml b/pkgs/by-name/no/notify-run/Cargo.toml index af970bd4..ceff208e 100644 --- a/pkgs/by-name/ge/generate_moz_extension/Cargo.toml +++ b/pkgs/by-name/no/notify-run/Cargo.toml @@ -9,16 +9,12 @@ # If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. [package] -name = "generate_extensions" +name = "notify-run" +description = "An safe way to run applications that might fail" version = "0.1.0" -edition = "2021" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -anyhow = "1.0.98" -futures = "0.3.31" -reqwest = "0.12.18" -serde = { version = "1.0.219", features = ["derive"] } -serde_json = "1.0.140" -tokio = { version = "1.45.1", features = ["macros", "rt-multi-thread"] } +anyhow = "1.0.104" diff --git a/pkgs/by-name/no/notify-run/flake.nix b/pkgs/by-name/no/notify-run/flake.nix new file mode 100644 index 00000000..f8649e8f --- /dev/null +++ b/pkgs/by-name/no/notify-run/flake.nix @@ -0,0 +1,35 @@ +# 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>. +{ + description = "An safe way to run applications, that might fail"; + + inputs = { + }; + + outputs = {...}: let + system = "x86_64-linux"; + sources = import ../../../../unflake.nix; + + pkgs = sources.nixpkgs.legacyPackages."${system}"; + in { + devShells."${system}".default = pkgs.mkShell { + packages = [ + pkgs.cargo + pkgs.clippy + pkgs.rustc + pkgs.rustfmt + + pkgs.cargo-edit + ]; + }; + }; +} +# vim: ts=2 + diff --git a/pkgs/by-name/no/notify-run/package.nix b/pkgs/by-name/no/notify-run/package.nix new file mode 100644 index 00000000..1f9337be --- /dev/null +++ b/pkgs/by-name/no/notify-run/package.nix @@ -0,0 +1,41 @@ +# 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>. +{ + rustPlatform, + lib, + libnotify, + makeWrapper, +}: +rustPlatform.buildRustPackage (finalAttrs: { + pname = "notify-run"; + version = "0.1.0"; + + buildInputs = [ + libnotify + ]; + nativeBuildInputs = [ + makeWrapper + ]; + + src = ./.; + cargoLock = { + lockFile = ./Cargo.lock; + }; + + postInstall = '' + # NOTE: We cannot clear the path, because we need access to the programs to start. <2025-12-03> + wrapProgram $out/bin/notify-run \ + --prefix PATH : ${lib.makeBinPath finalAttrs.buildInputs} + ''; + + meta = { + mainProgram = "notify-run"; + }; +}) diff --git a/pkgs/by-name/no/notify-run/src/main.rs b/pkgs/by-name/no/notify-run/src/main.rs new file mode 100644 index 00000000..94f9ad4e --- /dev/null +++ b/pkgs/by-name/no/notify-run/src/main.rs @@ -0,0 +1,95 @@ +// 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>. + +use std::{ + env::args, + io::{BufRead, BufReader, Read, Write}, + path::PathBuf, + process::{Command, Stdio}, + thread::JoinHandle, +}; + +use anyhow::{Context, Result}; + +fn main() -> Result<()> { + let args = args().skip(1).collect::<Vec<_>>(); + + let mut cmd = Command::new(&args[0]); + if let Some(arguments) = args.get(1) { + cmd.args(arguments.split(" ").collect::<Vec<_>>().as_slice()); + } + + eprintln!("notify-run> Spawning {:?}", cmd); + + let mut child = cmd + .stderr(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .with_context(|| format!("Failed to spawn {:?}", cmd))?; + + 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()]); + + notify_send.status().with_context(|| { + format!( + "Failed to run `notify-send` to tell about failed command ({:?}).", + cmd + ) + })?; + } + + Ok(()) +} + +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 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}")?; + } + + Ok(()) + }) +} diff --git a/modules/home.legacy/conf/alacritty/toml/env.toml b/pkgs/by-name/no/notify-run/update.sh index 307f1f1d..188771c4 100644..100755 --- a/modules/home.legacy/conf/alacritty/toml/env.toml +++ b/pkgs/by-name/no/notify-run/update.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env sh + # nixos-config - My current NixOS configuration # # Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> @@ -8,6 +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>. -[env] -TERM = "alacritty" -COLORTERM = "truecolor" +[ "$1" = "upgrade" ] && cargo upgrade --incompatible allow --pinned allow --recursive true +cargo update --recursive |
