summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--flake.lock23
-rw-r--r--flake.nix18
-rw-r--r--treefmt.nix86
3 files changed, 122 insertions, 5 deletions
diff --git a/flake.lock b/flake.lock
index c85da85..662b7ff 100644
--- a/flake.lock
+++ b/flake.lock
@@ -279,7 +279,8 @@
         "ragenix": "ragenix",
         "rust-overlay": "rust-overlay",
         "simple-nixos-mailserver": "simple-nixos-mailserver",
-        "systems": "systems"
+        "systems": "systems",
+        "treefmt-nix": "treefmt-nix"
       }
     },
     "rust-overlay": {
@@ -342,6 +343,26 @@
         "repo": "x86_64-linux",
         "type": "github"
       }
+    },
+    "treefmt-nix": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1734704479,
+        "narHash": "sha256-MMi74+WckoyEWBRcg/oaGRvXC9BVVxDZNRMpL+72wBI=",
+        "owner": "numtide",
+        "repo": "treefmt-nix",
+        "rev": "65712f5af67234dad91a5a4baee986a8b62dbf8f",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "treefmt-nix",
+        "type": "github"
+      }
     }
   },
   "root": "root",
diff --git a/flake.nix b/flake.nix
index dc63ea9..c7af7b4 100644
--- a/flake.nix
+++ b/flake.nix
@@ -7,6 +7,13 @@
 
     library.url = "git+https://git.vhack.eu/vhack.eu/nix-library?ref=prime";
 
+    treefmt-nix = {
+      url = "github:numtide/treefmt-nix";
+      inputs = {
+        nixpkgs.follows = "nixpkgs";
+      };
+    };
+
     # inputs for following
     systems = {
       url = "github:nix-systems/x86_64-linux"; # only evaluate for this system
@@ -76,6 +83,7 @@
     nixpkgs,
     nixpkgs-unstable,
     library,
+    treefmt-nix,
     # modules
     simple-nixos-mailserver,
     impermanence,
@@ -107,6 +115,7 @@
     vhackPackages = import ./pkgs {inherit pkgs nixLib;};
 
     inherit (library) nixLib;
+    treefmtEval = import ./treefmt.nix {inherit treefmt-nix pkgs;};
   in {
     nixosConfigurations."server1" = nixpkgs.lib.nixosSystem {
       system = "x86_64-linux";
@@ -119,15 +128,17 @@
         ];
     };
 
-    checks."${system}" = tests;
+    checks."${system}" = nixLib.warnMerge tests {
+      formatting =
+        treefmtEval.config.build.check self;
+    } "the flake checks";
 
     packages."${system}" = vhackPackages;
+    formatter."${system}" = treefmtEval.config.build.wrapper;
 
     devShells."${system}" = {
       default = pkgs.mkShell {
         packages = with pkgs; [
-          alejandra
-
           # used for certificate generation in the taskserver setup
           gnutls
 
@@ -138,6 +149,5 @@
         ];
       };
     };
-    formatter."${system}" = pkgs.alejandra;
   };
 }
diff --git a/treefmt.nix b/treefmt.nix
new file mode 100644
index 0000000..e2c6aea
--- /dev/null
+++ b/treefmt.nix
@@ -0,0 +1,86 @@
+{
+  treefmt-nix,
+  pkgs,
+}:
+treefmt-nix.lib.evalModule pkgs (
+  {pkgs, ...}: {
+    # Used to find the project root
+    projectRootFile = "flake.nix";
+
+    programs = {
+      alejandra.enable = true;
+      rustfmt.enable = true;
+      clang-format.enable = true;
+      mdformat.enable = true;
+      shfmt = {
+        enable = true;
+        indent_size = 4;
+      };
+      shellcheck.enable = true;
+      prettier = {
+        settings = {
+          arrowParens = "always";
+          bracketSameLine = false;
+          bracketSpacing = true;
+          editorconfig = true;
+          embeddedLanguageFormatting = "auto";
+          endOfLine = "lf";
+          # experimentalTernaries = false;
+          htmlWhitespaceSensitivity = "css";
+          insertPragma = false;
+          jsxSingleQuote = true;
+          printWidth = 80;
+          proseWrap = "always";
+          quoteProps = "consistent";
+          requirePragma = false;
+          semi = true;
+          singleAttributePerLine = true;
+          singleQuote = true;
+          trailingComma = "all";
+          useTabs = false;
+          vueIndentScriptAndStyle = false;
+
+          tabWidth = 4;
+          overrides = {
+            files = ["*.js"];
+            options.tabwidth = 2;
+          };
+        };
+      };
+      stylua = {
+        enable = true;
+        settings = {
+          sort_requires.enabled = true;
+          column_width = 120;
+          line_endings = "Unix";
+          indent_type = "Spaces";
+          indent_width = 2;
+          quote_style = "ForceDouble";
+          call_parentheses = "Always";
+          # space_after_function_names = "Never";
+          collapse_simple_statement = "Always";
+        };
+      };
+      ruff = {
+        enable = true;
+        format = true;
+      };
+      taplo.enable = true;
+    };
+
+    settings = {
+      global.excludes = [
+        "CHANGELOG.md"
+        "NEWS.md"
+      ];
+      formatter = {
+        clang-format = {
+          options = ["--style" "GNU"];
+        };
+        shfmt = {
+          includes = ["*.bash"];
+        };
+      };
+    };
+  }
+)