diff --git a/flake.lock b/flake.lock index e8d4a2e..bf07e4d 100644 --- a/flake.lock +++ b/flake.lock @@ -80,7 +80,8 @@ "fenix": "fenix", "flake-utils": "flake-utils", "nix-vm-test": "nix-vm-test", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" } }, "rust-analyzer-src": { @@ -114,6 +115,26 @@ "repo": "default", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1743748085, + "narHash": "sha256-uhjnlaVTWo5iD3LXics1rp9gaKgDRQj6660+gbUU3cE=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "815e4121d6a5d504c0f96e5be2dd7f871e4fd99d", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 1e84d67..2686434 100644 --- a/flake.nix +++ b/flake.nix @@ -10,9 +10,12 @@ nix-vm-test.url = "github:numtide/nix-vm-test"; nix-vm-test.inputs.nixpkgs.follows = "nixpkgs"; nix-vm-test.inputs.flake-utils.follows = "flake-utils"; + + treefmt-nix.url = "github:numtide/treefmt-nix"; + treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, flake-utils, nix-vm-test, ... }@inputs: + outputs = { self, nixpkgs, flake-utils, nix-vm-test, treefmt-nix, ... }@inputs: nixpkgs.lib.foldl (a: b: nixpkgs.lib.recursiveUpdate a b) { } [ @@ -86,6 +89,8 @@ nix-vm-test.overlays.default ]; }; + + treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix; in { packages.package-deb = pkgs.callPackage ./pkgs/package-deb.nix { @@ -152,26 +157,15 @@ checks = { systemd-rosenpass = pkgs.testers.runNixOSTest ./tests/systemd/rosenpass.nix; systemd-rp = pkgs.testers.runNixOSTest ./tests/systemd/rp.nix; - - cargo-fmt = pkgs.runCommand "check-cargo-fmt" - { inherit (self.devShells.${system}.default) nativeBuildInputs buildInputs; } '' - cargo fmt --manifest-path=${./.}/Cargo.toml --check --all && touch $out - ''; - nixpkgs-fmt = pkgs.runCommand "check-nixpkgs-fmt" - { nativeBuildInputs = [ pkgs.nixpkgs-fmt ]; } '' - nixpkgs-fmt --check ${./.} && touch $out - ''; - prettier-check = pkgs.runCommand "check-with-prettier" - { nativeBuildInputs = [ pkgs.nodePackages.prettier ]; } '' - cd ${./.} && prettier --check . && touch $out - ''; + formatting = treefmtEval.config.build.check self; } // pkgs.lib.optionalAttrs (system == "x86_64-linux") (import ./tests/legacy-distro-packaging.nix { inherit pkgs; rosenpass-deb = self.packages.${system}.package-deb; rosenpass-rpm = self.packages.${system}.package-rpm; }); - formatter = pkgs.nixpkgs-fmt; + # for `nix fmt` + formatter = treefmtEval.config.build.wrapper; })) ]; } diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..a79c8f3 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,30 @@ +{ pkgs, ... }: +{ + # Used to find the project root + projectRootFile = "flake.nix"; + programs.nixfmt.enable = true; + programs.prettier = { + enable = true; + includes = [ + "*.css" + "*.html" + "*.js" + "*.json" + "*.json5" + "*.md" + "*.mdx" + "*.toml" + "*.yaml" + "*.yml" + ]; + excludes = [ + "supply-chain/*" + ]; + settings = { + plugins = [ + "${pkgs.nodePackages.prettier-plugin-toml}/lib/node_modules/prettier-plugin-toml/lib/index.js" + ]; + }; + }; + programs.rustfmt.enable = true; +}