From ae6f4ba40049db6323c3b00524a9dbf311d10322 Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Tue, 22 Oct 2024 00:05:50 +0200 Subject: [PATCH] Add treemfmt for code formatting --- flake.lock | 43 +++++++++++++++++++++++++++++++++++++++---- flake.nix | 16 +++++++++++++--- justfile | 2 +- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index 35b5bcc..f7bf7f1 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1726969270, - "narHash": "sha256-8fnFlXBgM/uSvBlLWjZ0Z0sOdRBesyNdH0+esxqizGc=", + "lastModified": 1729307008, + "narHash": "sha256-QUvb6epgKi9pCu9CttRQW4y5NqJ+snKr1FZpG/x3Wtc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "23cbb250f3bf4f516a2d0bf03c51a30900848075", + "rev": "a9b86fc2290b69375c5542b622088eb6eca2a7c3", "type": "github" }, "original": { @@ -34,10 +34,27 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1726871744, + "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" } }, "systems": { @@ -54,6 +71,24 @@ "repo": "default", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1729242555, + "narHash": "sha256-6jWSWxv2crIXmYSEb3LEVsFkCkyVHNllk61X4uhqfCs=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "d986489c1c757f6921a48c1439f19bfb9b8ecab5", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 225b1ac..e9d9a9a 100644 --- a/flake.nix +++ b/flake.nix @@ -4,6 +4,7 @@ inputs = { flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; + treefmt-nix.url = "github:numtide/treefmt-nix"; }; outputs = @@ -11,16 +12,25 @@ self, flake-utils, nixpkgs, - ... + treefmt-nix, }: flake-utils.lib.eachDefaultSystem ( system: let pkgs = import nixpkgs { inherit system; }; + + treefmtEval = treefmt-nix.lib.evalModule pkgs { + projectRootFile = "flake.nix"; + programs = { + nixfmt.enable = true; + nixfmt.package = pkgs.nixfmt-rfc-style; + shfmt.enable = true; + }; + }; in { - # Formatter for the Nix code - formatter = pkgs.nixpkgs-fmt; + # For `nix fmt` + formatter = treefmtEval.config.build.wrapper; # Checks/tests for the project checks = { diff --git a/justfile b/justfile index 306a400..c949c85 100644 --- a/justfile +++ b/justfile @@ -14,7 +14,7 @@ lint: # Format all source code fmt: - echo FIXME: Add formatter here + nix fmt # Update all dependencies update: update-nix-pkgs