From 2e278b2dba42680d661f0df7335b11a3375f48c4 Mon Sep 17 00:00:00 2001 From: Haonan Chen Date: Thu, 1 Jan 2026 07:31:24 +0800 Subject: [PATCH] flake: update btop --- flake.lock | 6 +- flake/lib/buildNixpkgsConfig/btop.patch | 76 ++++++++++++++++++++++++ flake/lib/buildNixpkgsConfig/default.nix | 1 + modules/packages/btop.nix | 19 ++++++ modules/packages/minimal.nix | 2 +- 5 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 flake/lib/buildNixpkgsConfig/btop.patch create mode 100644 modules/packages/btop.nix diff --git a/flake.lock b/flake.lock index 004396be..a3a846b6 100644 --- a/flake.lock +++ b/flake.lock @@ -1144,11 +1144,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1767053975, - "narHash": "sha256-Zt1zWeJw0d2irAgC3lOfGgcAlDEUEzWG4kHV6BVhbqY=", + "lastModified": 1767223621, + "narHash": "sha256-Q0vXLCj8m9i87XfoyhKkHNIq8hjoNKEoysxU6uS+6o4=", "owner": "CHN-beta", "repo": "nixpkgs", - "rev": "9a8b7c7d8195a2dd2bf130bdcf3326f0d21e827b", + "rev": "1768cfa9daffab526e6573114c4c94353ee49d80", "type": "github" }, "original": { diff --git a/flake/lib/buildNixpkgsConfig/btop.patch b/flake/lib/buildNixpkgsConfig/btop.patch new file mode 100644 index 00000000..b44a215e --- /dev/null +++ b/flake/lib/buildNixpkgsConfig/btop.patch @@ -0,0 +1,76 @@ +diff --git a/src/btop_config.cpp b/src/btop_config.cpp +index eaaa577..3074a08 100644 +--- a/src/btop_config.cpp ++++ b/src/btop_config.cpp +@@ -234,6 +234,7 @@ namespace Config { + {"custom_gpu_name4", "#* Custom gpu4 model name, empty string to disable."}, + {"custom_gpu_name5", "#* Custom gpu5 model name, empty string to disable."}, + #endif ++ {"btrfs_group_subvolumes", "#* Show only the first subvolume of a btrfs filesystem."}, + }; + + std::unordered_map strings = { +@@ -336,6 +337,7 @@ namespace Config { + #endif + {"terminal_sync", true}, +- {"save_config_on_exit", true} ++ {"save_config_on_exit", true}, ++ {"btrfs_group_subvolumes", false}, + }; + std::unordered_map boolsTmp; + +diff --git a/src/btop_menu.cpp b/src/btop_menu.cpp +index 75ec31c..cfaec39 100644 +--- a/src/btop_menu.cpp ++++ b/src/btop_menu.cpp +@@ -724,6 +724,15 @@ namespace Menu { + "kernel as used memory.", + "", + "True or False."}, ++ { ++ "btrfs_group_subvolumes", ++ "(Linux) Show only first BTRFS subvolume.", ++ "", ++ "Set to true to only show the first BTRFS", ++ "subvolume mounted per disk.", ++ "", ++ "True or False.", ++ } + }, + { + {"graph_symbol_net", +diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp +index eebaa50..37d5745 100644 +--- a/src/linux/btop_collect.cpp ++++ b/src/linux/btop_collect.cpp +@@ -2117,6 +2117,7 @@ namespace Mem { + auto use_fstab = Config::getB("use_fstab"); + auto only_physical = Config::getB("only_physical"); + auto zfs_hide_datasets = Config::getB("zfs_hide_datasets"); ++ auto btrfs_group_subvolumes = Config::getB("btrfs_group_subvolumes"); + auto& disks = mem.disks; + static std::unordered_map>> disks_stats_promises; + ifstream diskread; +@@ -2177,6 +2178,7 @@ namespace Mem { + vector found; + found.reserve(last_found.size()); + string dev, mountpoint, fstype; ++ std::unordered_set found_btrfs_subvolumes; + while (not diskread.eof()) { + std::error_code ec; + diskread >> dev >> mountpoint >> fstype; +@@ -2198,6 +2200,14 @@ namespace Mem { + size_t zfs_dataset_name_start = 0; + if (fstype == "zfs" && (zfs_dataset_name_start = dev.find('/')) != std::string::npos && zfs_hide_datasets) continue; + ++ //? skip BtrFS subvolumes ++ if (btrfs_group_subvolumes and fstype == "btrfs") { ++ string devname = fs::canonical(dev, ec).filename(); ++ if (!found_btrfs_subvolumes.insert(devname).second) { ++ continue; ++ } ++ } ++ + if ((not use_fstab and not only_physical) + or (use_fstab and v_contains(fstab, mountpoint)) + or (not use_fstab and only_physical and v_contains(fstypes, fstype))) { diff --git a/flake/lib/buildNixpkgsConfig/default.nix b/flake/lib/buildNixpkgsConfig/default.nix index 2748aa5b..8093cdf0 100644 --- a/flake/lib/buildNixpkgsConfig/default.nix +++ b/flake/lib/buildNixpkgsConfig/default.nix @@ -72,6 +72,7 @@ in platformConfig // google-chrome = prev.google-chrome.override (prev: { commandLineArgs = prev.commandLineArgs or "" + " --disable-features=GlobalShortcutsPortal"; }); xray = prev.xray.overrideAttrs (prev: { patches = prev.patches or [] ++ [ ./xray.patch ]; }); + btop = prev.btop.overrideAttrs (prev: { patches = prev.patches or [] ++ [ ./btop.patch ]; }); } // ( let diff --git a/modules/packages/btop.nix b/modules/packages/btop.nix new file mode 100644 index 00000000..6a2c6268 --- /dev/null +++ b/modules/packages/btop.nix @@ -0,0 +1,19 @@ +{ lib, pkgs, config, ... }: +{ + options.nixos.packages.btop = lib.mkOption { type = lib.types.nullOr (lib.types.submodule {}); default = {}; }; + config = let inherit (config.nixos.packages) btop; in lib.mkIf (btop != null) + { + nixos = + { + packages.packages._packages = [ pkgs.btop ]; + user.sharedModules = + [{ + config.programs.btop = + { + enable = true; + settings.btrfs_group_subvolumes = true; + }; + }]; + }; + }; +} diff --git a/modules/packages/minimal.nix b/modules/packages/minimal.nix index 47c47eac..65e05bd0 100644 --- a/modules/packages/minimal.nix +++ b/modules/packages/minimal.nix @@ -14,7 +14,7 @@ inputs: # lsxx pciutils usbutils lshw util-linux lsof dmidecode lm_sensors hwloc acpica-tools ethtool # top - iotop iftop htop btop powertop s-tui + iotop iftop htop powertop s-tui # editor nano bat # downloader