summaryrefslogtreecommitdiff
path: root/nix
diff options
context:
space:
mode:
authorArtur Manuel <balkenix@outlook.com>2024-10-07 19:49:19 +0100
committerGitHub <noreply@github.com>2024-10-07 21:49:19 +0300
commit46d990f1b632dc52a667d876a32cffb24ef72bd8 (patch)
treea73acf2f403d09715b7e51cc07edfb9f359cab65 /nix
parent5bf7b1e1fadf743f41ec765f7545370e3d7ccf96 (diff)
feat: add a custom made treewide formatter (#7992)
Diffstat (limited to 'nix')
-rw-r--r--nix/default.nix2
-rw-r--r--nix/formatter.nix64
-rw-r--r--nix/overlays.nix4
3 files changed, 67 insertions, 3 deletions
diff --git a/nix/default.nix b/nix/default.nix
index 6f086ccc..d463e271 100644
--- a/nix/default.nix
+++ b/nix/default.nix
@@ -68,7 +68,7 @@ in
inherit version;
src = cleanSourceWith {
- filter = name: type: let
+ filter = name: _type: let
baseName = baseNameOf (toString name);
in
! (hasSuffix ".nix" baseName);
diff --git a/nix/formatter.nix b/nix/formatter.nix
new file mode 100644
index 00000000..66721c2c
--- /dev/null
+++ b/nix/formatter.nix
@@ -0,0 +1,64 @@
+{
+ writeShellApplication,
+ deadnix,
+ statix,
+ alejandra,
+ llvmPackages_19,
+ fd,
+}:
+writeShellApplication {
+ name = "hyprland-treewide-formatter";
+ runtimeInputs = [
+ deadnix
+ statix
+ alejandra
+ llvmPackages_19.clang-tools
+ fd
+ ];
+ text = ''
+ # shellcheck disable=SC2148
+
+ # common excludes
+ excludes="subprojects"
+
+ nix_format() {
+ if [ "$*" = 0 ]; then
+ fd '.*\.nix' . -E "$excludes" -x statix fix -- {} \;
+ fd '.*\.nix' . -E "$excludes" -X deadnix -e -- {} \; -X alejandra {} \;
+ elif [ -d "$1" ]; then
+ fd '.*\.nix' "$1" -E "$excludes" -i -x statix fix -- {} \;
+ fd '.*\.nix' "$1" -E "$excludes" -i -X deadnix -e -- {} \; -X alejandra {} \;
+ else
+ statix fix -- "$1"
+ deadnix -e "$1"
+ alejandra "$1"
+ fi
+ }
+
+ cpp_format() {
+ if [ "$*" = 0 ] || [ "$1" = "." ]; then
+ fd '.*\.cpp' . -E "$excludes" | xargs clang-format --verbose -i
+ elif [ -d "$1" ]; then
+ fd '.*\.cpp' "$1" -E "$excludes" | xargs clang-format --verbose -i
+ else
+ clang-format --verbose -i "$1"
+ fi
+ }
+
+ for i in "$@"; do
+ case ''${i##*.} in
+ "nix")
+ nix_format "$i"
+ ;;
+ "cpp")
+ cpp_format "$i"
+ ;;
+ *)
+ nix_format "$i"
+ cpp_format "$i"
+ ;;
+ esac
+
+ done
+ '';
+}
diff --git a/nix/overlays.nix b/nix/overlays.nix
index 2b2788e7..a78f3003 100644
--- a/nix/overlays.nix
+++ b/nix/overlays.nix
@@ -29,7 +29,7 @@ in {
self.overlays.udis86
# Hyprland packages themselves
- (final: prev: let
+ (final: _prev: let
date = mkDate (self.lastModifiedDate or "19700101");
in {
hyprland = final.callPackage ./default.nix {
@@ -70,7 +70,7 @@ in {
# this version is the one used in the git submodule, and allows us to
# fetch the source without '?submodules=1'
udis86 = final: prev: {
- udis86-hyprland = prev.udis86.overrideAttrs (self: super: {
+ udis86-hyprland = prev.udis86.overrideAttrs (_self: _super: {
src = final.fetchFromGitHub {
owner = "canihavesomecoffee";
repo = "udis86";