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);
in
fetchTarball { fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash; sha256 = lock.nodes.flake-compat.locked.narHash;
} }
) ) { src = ./.; }).defaultNix
{ src = ./.; }
).defaultNix

View File

@ -9,48 +9,97 @@
}; };
}; };
outputs = { self, nixpkgs, ... }: outputs =
{ self, nixpkgs, ... }:
let let
inherit (nixpkgs) lib; inherit (nixpkgs) lib;
genSystems = func: lib.genAttrs [ genSystems =
func:
lib.genAttrs
[
"x86_64-linux" "x86_64-linux"
"aarch64-linux" "aarch64-linux"
] ]
(system: func (import nixpkgs { (
system:
func (
import nixpkgs {
inherit system; inherit system;
overlays = with self.overlays; [ overlays = with self.overlays; [
waybar waybar
]; ];
})); }
)
);
mkDate = longDate: (lib.concatStringsSep "-" [ mkDate =
longDate:
(lib.concatStringsSep "-" [
(builtins.substring 0 4 longDate) (builtins.substring 0 4 longDate)
(builtins.substring 4 2 longDate) (builtins.substring 4 2 longDate)
(builtins.substring 6 2 longDate) (builtins.substring 6 2 longDate)
]); ]);
in in
{ {
devShells = genSystems devShells = genSystems (pkgs: {
(pkgs: default = pkgs.mkShell {
{
default =
pkgs.mkShell
{
name = "waybar-shell"; 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 =
pkgs.waybar.nativeBuildInputs
++ (with pkgs; [
nixfmt-rfc-style
clang-tools clang-tools
gdb 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;
waybar = final: prev: { waybar = final: prev: {
@ -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,8 +15,7 @@ let
}; };
}; };
in in
(waybar.overrideAttrs ( (waybar.overrideAttrs (oldAttrs: {
oldAttrs: {
inherit version; inherit version;
src = lib.cleanSourceWith { src = lib.cleanSourceWith {
@ -26,9 +26,9 @@ in
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
@ -40,5 +40,4 @@ in
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"

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 {