Merge pull request #22 from NotAShelf/notashelf/push-sqmmoyozwmru
Some checks failed
Build / Find uncached packages (push) Has been cancelled
Run Checks / check (NIXPKGS_ALLOW_INSECURE=1 NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix flake check --accept-flake-config) (push) Has been cancelled
Run Checks / check (nix run .#alejandra-custom -- -c . -e ./npins) (push) Has been cancelled
Nix / nix (push) Has been cancelled
Build / build-uncached (push) Has been cancelled
Run Checks / build (push) Has been cancelled

meta: flake cleanup; add btop with process normalization
This commit is contained in:
raf 2025-12-29 14:53:47 +03:00 committed by GitHub
commit 9624778f14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 140 additions and 19 deletions

View file

@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
command:
- NIXPKGS_ALLOW_INSECURE=1 nix flake check --accept-flake-config --impure
- NIXPKGS_ALLOW_INSECURE=1 NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix flake check --accept-flake-config
- nix run .#alejandra-custom -- -c . -e ./npins
uses: ./.github/workflows/nix.yml
with:

BIN
flake.lock generated

Binary file not shown.

View file

@ -16,7 +16,7 @@
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs self;} {
systems = import inputs.systems;
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
imports = [flake-parts.flakeModules.easyOverlay];
perSystem = {
@ -94,7 +94,12 @@
devShells = {
default = pkgs.mkShellNoCC {
name = "nyxexprs";
packages = [pkgs.npins];
packages = [
pkgs.npins
# Also put the default formatter in the devshell
config.formatter
];
};
};
@ -125,8 +130,7 @@
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default-linux";
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
@ -138,6 +142,16 @@
};
# Rest of my packages will be constructed from previous flakes
ndg = {
url = "github:feel-co/ndg";
inputs.nixpkgs.follows = "nixpkgs";
};
nh = {
url = "github:nix-community/nh";
inputs.nixpkgs.follows = "nixpkgs";
};
watt = {
url = "github:NotAShelf/watt";
inputs.nixpkgs.follows = "nixpkgs";
@ -153,11 +167,6 @@
inputs.nixpkgs.follows = "nixpkgs";
};
ndg = {
url = "github:feel-co/ndg";
inputs.nixpkgs.follows = "nixpkgs";
};
licenseit = {
url = "github:notashelf/licenseit";
inputs.nixpkgs.follows = "nixpkgs";
@ -178,11 +187,6 @@
inputs.nixpkgs.follows = "nixpkgs";
};
nh = {
url = "github:nix-community/nh";
inputs.nixpkgs.follows = "nixpkgs";
};
gh-notify = {
url = "github:notashelf/gh-notify";
inputs.nixpkgs.follows = "nixpkgs";
@ -198,13 +202,15 @@
inputs.nixpkgs.follows = "nixpkgs";
};
tuigreet = {
url = "github:notashelf/tuigreet";
inputs.nixpkgs.follows = "nixpkgs";
};
# 3rd party flakes that I want to extract packages from
wiremix = {
url = "github:tsowell/wiremix";
inputs = {
nixpkgs.follows = "nixpkgs";
systems.follows = "systems";
};
inputs.nixpkgs.follows = "nixpkgs";
};
nil = {

15
pkgs/btop/package.nix Normal file
View file

@ -0,0 +1,15 @@
{
lib,
btop,
}:
btop.overrideAttrs {
patches = [
./patches/normalize_processes.patch
];
meta = {
description = "Monitor of resources, with a patch to normalize process names on Nix";
mainProgram = "btop";
maintainers = [lib.maintainers.NotAShelf];
};
}

View file

@ -0,0 +1,100 @@
From f35abef6dd17c2704f3d84e1bee0acaac9d035e1 Mon Sep 17 00:00:00 2001
From: NotAShelf <raf@notashelf.dev>
Date: Tue, 25 Nov 2025 17:29:51 +0300
Subject: [PATCH] Add Nix store path normalization for process monitor
---
src/linux/btop_collect.cpp | 62 +++++++++++++++++++++++++++++++++++++-
1 file changed, 61 insertions(+), 1 deletion(-)
diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp
index eebaa50..b895320 100644
--- a/src/linux/btop_collect.cpp
+++ b/src/linux/btop_collect.cpp
@@ -94,6 +94,54 @@ long long get_monotonicTimeUSec()
return time.tv_sec * 1000000 + time.tv_nsec / 1000;
}
+//? Nix store path normalization
+string normalize_nix_path(const string& path) {
+ // Check if path starts with /nix/store/
+ if (path.rfind("/nix/store/", 0) != 0) {
+ return path;
+ }
+
+ // Find the end of the hash (31 characters after /nix/store/)
+ const size_t hash_start = 12; // length of "/nix/store/"
+ if (path.length() <= hash_start + 31) {
+ return path;
+ }
+
+ // Look for the end of the hash (first dash after 31 chars)
+ size_t hash_end = path.find('-', hash_start);
+ if (hash_end == string::npos || hash_end != hash_start + 31) {
+ return path;
+ }
+
+ // Extract the name part after the hash
+ string name_part = path.substr(hash_end + 1);
+
+ // Check if the binary is in /libexec or /bin
+ size_t bin_pos = name_part.find("/bin/");
+ size_t libexec_pos = name_part.find("/libexec/");
+ if (bin_pos != string::npos || libexec_pos != string::npos) {
+ // Strip the directory and return just the binary name
+ size_t slash_pos = (bin_pos != string::npos) ? bin_pos + 1 : libexec_pos + 1;
+ size_t next_slash = name_part.find('/', slash_pos);
+ if (next_slash != string::npos) {
+ return name_part.substr(next_slash + 1);
+ }
+ }
+
+ // Handle wrapped programs: .program-wrapped -> program-wrapped
+ if (name_part.rfind(".", 0) == 0 && name_part.find("-wrapped") != string::npos) {
+ return name_part.substr(1); // Remove the leading dot
+ }
+
+ // Handle wrapped programs in directories: name/.program-wrapped -> program-wrapped
+ size_t wrapped_pos = name_part.find("/.");
+ if (wrapped_pos != string::npos && name_part.find("-wrapped", wrapped_pos) != string::npos) {
+ return name_part.substr(wrapped_pos + 2); // Remove "/."
+ }
+
+ return name_part;
+}
+
}
namespace Cpu {
@@ -3012,6 +3060,8 @@ namespace Proc {
if (not pread.good()) continue;
getline(pread, new_proc.name);
pread.close();
+ //? Apply Nix store path normalization
+ new_proc.name = normalize_nix_path(new_proc.name);
//? Check for whitespace characters in name and set offset to get correct fields from stat file
new_proc.name_offset = rng::count(new_proc.name, ' ');
@@ -3026,7 +3076,17 @@ namespace Proc {
}
}
pread.close();
- if (not new_proc.cmd.empty()) new_proc.cmd.pop_back();
+ if (not new_proc.cmd.empty()) {
+ new_proc.cmd.pop_back();
+ //? Apply Nix store path normalization to first argument (program path)
+ size_t space_pos = new_proc.cmd.find(' ');
+ if (space_pos != string::npos) {
+ string first_arg = new_proc.cmd.substr(0, space_pos);
+ new_proc.cmd = normalize_nix_path(first_arg) + new_proc.cmd.substr(space_pos);
+ } else {
+ new_proc.cmd = normalize_nix_path(new_proc.cmd);
+ }
+ }
pread.open(d.path() / "status");
if (not pread.good()) continue;
--
2.51.0