summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--flake.nix79
-rw-r--r--treefmt.nix73
2 files changed, 121 insertions, 31 deletions
diff --git a/flake.nix b/flake.nix
index 73cd4b7..950835d 100644
--- a/flake.nix
+++ b/flake.nix
@@ -48,6 +48,12 @@
         flake-utils.follows = "flake-utils";
       };
     };
+    treefmt-nix = {
+      url = "github:numtide/treefmt-nix";
+      inputs = {
+        nixpkgs.follows = "nixpkgs";
+      };
+    };
 
     # data
     essay = {
@@ -71,6 +77,7 @@
         flake-utils.follows = "flake-utils";
         flake_version_update.follows = "flake_version_update";
         lpm.follows = "lpm";
+        treefmt-nix.follows = "treefmt-nix";
         nixpkgs.follows = "nixpkgs";
         rust-overlay.follows = "rust-overlay";
         systems.follows = "systems";
@@ -83,6 +90,7 @@
         flake-compat.follows = "flake-compat";
         flake-utils.follows = "flake-utils";
         flake_version_update.follows = "flake_version_update";
+        treefmt-nix.follows = "treefmt-nix";
         lpm.follows = "lpm";
         nixpkgs.follows = "nixpkgs";
         rust-overlay.follows = "rust-overlay";
@@ -92,51 +100,60 @@
   };
 
   outputs = {
-    nixpkgs,
-    flake-utils,
+    self,
     essay,
-    facharbeit,
     essens_analyse,
+    facharbeit,
+    flake-utils,
+    nixpkgs,
+    treefmt-nix,
     ...
   }:
     flake-utils.lib.eachDefaultSystem (
       system: let
         pkgs = nixpkgs.legacyPackages.${system};
-      in {
-        packages = {
-          default = pkgs.stdenv.mkDerivation {
-            pname = "b-peetz.de";
-            version = "v1.0";
-            src = ./src;
+        treefmtEval = import ./treefmt.nix {inherit treefmt-nix pkgs;};
+        build = pkgs.stdenv.mkDerivation {
+          pname = "b-peetz.de";
+          version = "v1.0";
+          src = ./src;
 
-            # Run local
-            preferLocalBuild = true;
-            allowSubstitutes = false;
+          # Run local
+          preferLocalBuild = true;
+          allowSubstitutes = false;
 
-            nativeBuildInputs = [];
-            buildPhase = ''
-              install -D ${essay.outputs.packages."${system}".default}/philosophy/kant_and_free_software.pdf ./dead-trees/philosophy/kant_and_free_software.pdf
-              # NOTE: This link is for backward compatibility, as I have given out links with that url <2024-07-13>
-              ln --symbolic --relative ./dead-trees/philosophy/kant_and_free_software.pdf ./dead-trees/kant_and_free_software.pdf
+          nativeBuildInputs = [];
+          buildPhase = ''
+            install -D ${essay.outputs.packages."${system}".default}/philosophy/kant_and_free_software.pdf ./dead-trees/philosophy/kant_and_free_software.pdf
+            # NOTE: This link is for backward compatibility, as I have given out links with that url <2024-07-13>
+            ln --symbolic --relative ./dead-trees/philosophy/kant_and_free_software.pdf ./dead-trees/kant_and_free_software.pdf
 
-              install -D ${facharbeit.outputs.packages."${system}".default}/chemistry/facharbeit.pdf ./dead-trees/chemistry/facharbeit.pdf
-              # NOTE: This link is for backward compatibility, as I have given out links with that url <2024-07-13>
-              ln --symbolic --relative ./dead-trees/chemistry/facharbeit.pdf ./dead-trees/raman_spectrometer.pdf
+            install -D ${facharbeit.outputs.packages."${system}".default}/chemistry/facharbeit.pdf ./dead-trees/chemistry/facharbeit.pdf
+            # NOTE: This link is for backward compatibility, as I have given out links with that url <2024-07-13>
+            ln --symbolic --relative ./dead-trees/chemistry/facharbeit.pdf ./dead-trees/raman_spectrometer.pdf
 
-              install -D ${essens_analyse.outputs.packages."${system}".default}/chemistry/essens_analyse.pdf ./dead-trees/chemistry/essens_analyse.pdf
-            '';
-            installPhase = ''
-              install -d $out/
-              cp --recursive . $out/
-            '';
-          };
+            install -D ${essens_analyse.outputs.packages."${system}".default}/chemistry/essens_analyse.pdf ./dead-trees/chemistry/essens_analyse.pdf
+          '';
+          installPhase = ''
+            install -d $out/
+            cp --recursive . $out/
+          '';
+        };
+      in {
+        packages = {
+          default = build;
+        };
+
+        checks = {
+          inherit build;
+          formatting = treefmtEval.config.build.check self;
         };
+
+        formatter = treefmtEval.config.build.wrapper;
+
         devShells = {
           default = pkgs.mkShell {
-            packages = with pkgs; [
-              alejandra
-              nodePackages_latest.prettier
-            ];
+            packages = [];
           };
         };
       }
diff --git a/treefmt.nix b/treefmt.nix
new file mode 100644
index 0000000..1cbab40
--- /dev/null
+++ b/treefmt.nix
@@ -0,0 +1,73 @@
+{
+  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;
+      ruff = {
+        enable = true;
+        format = true;
+      };
+      taplo.enable = true;
+    };
+
+    settings = {
+      global.excludes = [
+        "CHANGELOG.md"
+        "NEWS.md"
+      ];
+      formatter = {
+        clang-format = {
+          options = ["--style" "GNU"];
+        };
+        shfmt = {
+          includes = ["*.bash"];
+        };
+      };
+    };
+  }
+)