Merge pull request #4025 from khaneliman/format

flake.nix: add treefmt; treewide: clang and nix format
This commit is contained in:
Alexis Rouillard
2025-04-24 11:28:11 +02:00
committed by GitHub
7 changed files with 139 additions and 87 deletions

View File

@ -1,10 +1,9 @@
(import (import (
( let
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in lock = builtins.fromJSON (builtins.readFile ./flake.lock);
fetchTarball { in
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; fetchTarball {
sha256 = lock.nodes.flake-compat.locked.narHash; url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
} sha256 = lock.nodes.flake-compat.locked.narHash;
) }
{ src = ./.; } ) { src = ./.; }).defaultNix
).defaultNix

129
flake.nix
View File

@ -9,47 +9,96 @@
}; };
}; };
outputs = { self, nixpkgs, ... }: outputs =
{ self, nixpkgs, ... }:
let let
inherit (nixpkgs) lib; inherit (nixpkgs) lib;
genSystems = func: lib.genAttrs [ genSystems =
"x86_64-linux" func:
"aarch64-linux" lib.genAttrs
] [
(system: func (import nixpkgs { "x86_64-linux"
inherit system; "aarch64-linux"
overlays = with self.overlays; [ ]
waybar (
]; system:
})); func (
import nixpkgs {
inherit system;
overlays = with self.overlays; [
waybar
];
}
)
);
mkDate = longDate: (lib.concatStringsSep "-" [ mkDate =
(builtins.substring 0 4 longDate) longDate:
(builtins.substring 4 2 longDate) (lib.concatStringsSep "-" [
(builtins.substring 6 2 longDate) (builtins.substring 0 4 longDate)
]); (builtins.substring 4 2 longDate)
(builtins.substring 6 2 longDate)
]);
in in
{ {
devShells = genSystems devShells = genSystems (pkgs: {
(pkgs: default = pkgs.mkShell {
{ name = "waybar-shell";
default =
pkgs.mkShell
{
name = "waybar-shell";
# inherit attributes from upstream nixpkgs derivation # inherit attributes from upstream nixpkgs derivation
inherit (pkgs.waybar) buildInputs depsBuildBuild depsBuildBuildPropagated depsBuildTarget inherit (pkgs.waybar)
depsBuildTargetPropagated depsHostHost depsHostHostPropagated depsTargetTarget buildInputs
depsTargetTargetPropagated propagatedBuildInputs propagatedNativeBuildInputs strictDeps; depsBuildBuild
depsBuildBuildPropagated
depsBuildTarget
depsBuildTargetPropagated
depsHostHost
depsHostHostPropagated
depsTargetTarget
depsTargetTargetPropagated
propagatedBuildInputs
propagatedNativeBuildInputs
strictDeps
;
# overrides for local development # overrides for local development
nativeBuildInputs = pkgs.waybar.nativeBuildInputs ++ (with pkgs; [ nativeBuildInputs =
clang-tools pkgs.waybar.nativeBuildInputs
gdb ++ (with pkgs; [
]); nixfmt-rfc-style
clang-tools
gdb
]);
};
});
formatter = genSystems (
pkgs:
pkgs.treefmt.withConfig {
settings = [
{
formatter = {
clang-format = {
options = [ "-i" ];
command = lib.getExe' pkgs.clang-tools "clang-format";
excludes = [ ];
includes = [
"*.c"
"*.cpp"
"*.h"
"*.hpp"
];
}; };
}); nixfmt = {
command = lib.getExe pkgs.nixfmt-rfc-style;
includes = [ "*.nix" ];
};
};
tree-root-file = ".git/index";
}
];
}
);
overlays = { overlays = {
default = self.overlays.waybar; default = self.overlays.waybar;
@ -58,11 +107,15 @@
waybar = prev.waybar; waybar = prev.waybar;
# take the first "version: '...'" from meson.build # take the first "version: '...'" from meson.build
version = version =
(builtins.head (builtins.split "'" (builtins.head (
(builtins.elemAt builtins.split "'" (
(builtins.split " version: '" (builtins.readFile ./meson.build)) builtins.elemAt (builtins.split " version: '" (builtins.readFile ./meson.build)) 2
2))) )
+ "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty"); ))
+ "+date="
+ (mkDate (self.lastModifiedDate or "19700101"))
+ "_"
+ (self.shortRev or "dirty");
}; };
}; };
}; };

View File

@ -1,7 +1,8 @@
{ lib {
, pkgs lib,
, waybar pkgs,
, version waybar,
version,
}: }:
let let
libcava = rec { libcava = rec {
@ -14,31 +15,29 @@ let
}; };
}; };
in in
(waybar.overrideAttrs ( (waybar.overrideAttrs (oldAttrs: {
oldAttrs: { inherit version;
inherit version;
src = lib.cleanSourceWith { src = lib.cleanSourceWith {
filter = name: type: type != "regular" || !lib.hasSuffix ".nix" name; filter = name: type: type != "regular" || !lib.hasSuffix ".nix" name;
src = lib.cleanSource ../.; src = lib.cleanSource ../.;
}; };
mesonFlags = lib.remove "-Dgtk-layer-shell=enabled" oldAttrs.mesonFlags; mesonFlags = lib.remove "-Dgtk-layer-shell=enabled" oldAttrs.mesonFlags;
# downstream patch should not affect upstream # downstream patch should not affect upstream
patches = []; patches = [ ];
# nixpkgs checks version, no need when building locally # nixpkgs checks version, no need when building locally
nativeInstallCheckInputs = []; nativeInstallCheckInputs = [ ];
buildInputs = (builtins.filter (p: p.pname != "wireplumber") oldAttrs.buildInputs) ++ [ buildInputs = (builtins.filter (p: p.pname != "wireplumber") oldAttrs.buildInputs) ++ [
pkgs.wireplumber pkgs.wireplumber
]; ];
postUnpack = '' postUnpack = ''
pushd "$sourceRoot" pushd "$sourceRoot"
cp -R --no-preserve=mode,ownership ${libcava.src} subprojects/cava-${libcava.version} cp -R --no-preserve=mode,ownership ${libcava.src} subprojects/cava-${libcava.version}
patchShebangs . patchShebangs .
popd popd
''; '';
} }))
))

View File

@ -1,16 +1,16 @@
#include "modules/sni/item.hpp" #include "modules/sni/item.hpp"
#include "modules/sni/icon_manager.hpp"
#include <gdkmm/general.h> #include <gdkmm/general.h>
#include <glibmm/main.h> #include <glibmm/main.h>
#include <gtkmm/tooltip.h> #include <gtkmm/tooltip.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <filesystem>
#include <fstream> #include <fstream>
#include <map> #include <map>
#include <filesystem>
#include "gdk/gdk.h" #include "gdk/gdk.h"
#include "modules/sni/icon_manager.hpp"
#include "util/format.hpp" #include "util/format.hpp"
#include "util/gtk_icon.hpp" #include "util/gtk_icon.hpp"
@ -206,10 +206,10 @@ void Item::setCustomIcon(const std::string& id) {
std::string custom_icon = IconManager::instance().getIconForApp(id); std::string custom_icon = IconManager::instance().getIconForApp(id);
if (!custom_icon.empty()) { if (!custom_icon.empty()) {
if (std::filesystem::exists(custom_icon)) { if (std::filesystem::exists(custom_icon)) {
Glib::RefPtr<Gdk::Pixbuf> custom_pixbuf = Gdk::Pixbuf::create_from_file(custom_icon); Glib::RefPtr<Gdk::Pixbuf> custom_pixbuf = Gdk::Pixbuf::create_from_file(custom_icon);
icon_name = ""; // icon_name has priority over pixmap icon_name = ""; // icon_name has priority over pixmap
icon_pixmap = custom_pixbuf; icon_pixmap = custom_pixbuf;
} else { // if file doesn't exist it's most likely an icon_name } else { // if file doesn't exist it's most likely an icon_name
icon_name = custom_icon; icon_name = custom_icon;
} }
} }

View File

@ -1,8 +1,9 @@
#include "modules/sni/tray.hpp" #include "modules/sni/tray.hpp"
#include "modules/sni/icon_manager.hpp"
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include "modules/sni/icon_manager.hpp"
namespace waybar::modules::SNI { namespace waybar::modules::SNI {
Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config) Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)

View File

@ -115,10 +115,10 @@ float waybar::modules::Temperature::getTemperature() {
auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0; auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0;
// First, try with dev.cpu // First, try with dev.cpu
if ( (sysctlbyname(fmt::format("dev.cpu.{}.temperature", zone).c_str(), &temp, &size, if ((sysctlbyname(fmt::format("dev.cpu.{}.temperature", zone).c_str(), &temp, &size, NULL, 0) ==
NULL, 0) == 0) || 0) ||
(sysctlbyname(fmt::format("hw.acpi.thermal.tz{}.temperature", zone).c_str(), &temp, &size, (sysctlbyname(fmt::format("hw.acpi.thermal.tz{}.temperature", zone).c_str(), &temp, &size,
NULL, 0) == 0) ) { NULL, 0) == 0)) {
auto temperature_c = ((float)temp - 2732) / 10; auto temperature_c = ((float)temp - 2732) / 10;
return temperature_c; return temperature_c;
} }

View File

@ -382,7 +382,7 @@ std::string Task::state_string(bool shortened) const {
return res.substr(0, res.size() - 1); return res.substr(0, res.size() - 1);
} }
void Task::handle_title(const char* title) { void Task::handle_title(const char *title) {
if (title_.empty()) { if (title_.empty()) {
spdlog::debug(fmt::format("Task ({}) setting title to {}", id_, title_)); spdlog::debug(fmt::format("Task ({}) setting title to {}", id_, title_));
} else { } else {