From 2fe8b8152344d72dc3a14996658301b3a768a5ef Mon Sep 17 00:00:00 2001 From: Saji Date: Fri, 2 May 2025 22:37:11 -0500 Subject: [PATCH] add treefmt --- flake.lock | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 22 +++++++++++++--------- treefmt.nix | 6 ++++++ 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 treefmt.nix diff --git a/flake.lock b/flake.lock index 3265f9b..15ac616 100644 --- a/flake.lock +++ b/flake.lock @@ -68,10 +68,28 @@ "type": "github" } }, + "nixpkgs_3": { + "locked": { + "lastModified": 1745377448, + "narHash": "sha256-jhZDfXVKdD7TSEGgzFJQvEEZ2K65UMiqW5YJ2aIqxMA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "507b63021ada5fee621b6ca371c4fca9ca46f52c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "deploy-rs": "deploy-rs", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_2", + "systems": "systems_2", + "treefmt-nix": "treefmt-nix" } }, "systems": { @@ -89,6 +107,38 @@ "type": "github" } }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "id": "systems", + "type": "indirect" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1746216483, + "narHash": "sha256-4h3s1L/kKqt3gMDcVfN8/4v2jqHrgLIe4qok4ApH5x4=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "29ec5026372e0dec56f890e50dbe4f45930320fd", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, "utils": { "inputs": { "systems": "systems" diff --git a/flake.nix b/flake.nix index 4374826..5f0cdd3 100644 --- a/flake.nix +++ b/flake.nix @@ -3,17 +3,15 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; deploy-rs.url = "github:serokell/deploy-rs"; + treefmt-nix.url = "github:numtide/treefmt-nix"; }; - outputs = { self, nixpkgs, deploy-rs }: let - systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; - forAllSystems = function: - nixpkgs.lib.genAttrs systems (system: function ( - import nixpkgs { - inherit system; - config.allowUnfree = true; - } - )); + outputs = { self, nixpkgs, deploy-rs, systems, treefmt-nix }: let + # systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; + forAllSystems = fn: + nixpkgs.lib.genAttrs (import systems) (system: fn nixpkgs.legacyPackages.${system}); + + treefmtEval = forAllSystems (pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix); in { apps = forAllSystems (pkgs: { @@ -44,6 +42,12 @@ }; }; + formatter = forAllSystems (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper); + + checks = forAllSystems (pkgs: { + formatting = treefmtEval.${pkgs.system}.config.build.check self; + }); + devShells = forAllSystems (pkgs: { default = pkgs.mkShell { packages = with pkgs; [ diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..d2ac4d2 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,6 @@ +{ pkgs, ... }: +{ + projectRootFile = "flake.nix"; + programs.nixfmt.enable = true; + programs.prettier.enable = true; +}