From 0974108f426fd5279104223a688f247d248f4a7e Mon Sep 17 00:00:00 2001 From: "Shahar \"Dawn\" Or" Date: Sun, 16 Jun 2024 22:11:50 +0700 Subject: [PATCH] style: treefmt-nix Co-authored-by: ruben beck --- default.nix | 20 ++++++++++++-------- flake.lock | 23 ++++++++++++++++++++++- flake.nix | 16 +++++++++++++++- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/default.nix b/default.nix index f620865..2b62571 100644 --- a/default.nix +++ b/default.nix @@ -1,10 +1,14 @@ -(import +( + import ( - let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in - fetchTarball { - url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } ) - { src = ./.; } -).defaultNix + {src = ./.;} +) +.defaultNix diff --git a/flake.lock b/flake.lock index 978b7de..3a64c79 100644 --- a/flake.lock +++ b/flake.lock @@ -168,7 +168,8 @@ "flake-compat": "flake-compat", "flake-utils": "flake-utils", "nix": "nix", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" } }, "rust-analyzer-src": { @@ -202,6 +203,26 @@ "repo": "default", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1718522839, + "narHash": "sha256-ULzoKzEaBOiLRtjeY3YoGFJMwWSKRYOic6VNw2UyTls=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "68eb1dc333ce82d0ab0c0357363ea17c31ea1f81", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 754d77f..d6183a7 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,8 @@ inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.nix.inputs.nixpkgs.follows = "nixpkgs"; inputs.nix.url = "github:NixOS/nix/latest-release"; + inputs.treefmt-nix.url = "github:numtide/treefmt-nix"; + inputs.treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; outputs = { self, @@ -17,8 +19,9 @@ flake-utils, nix, nixpkgs, + treefmt-nix, }: let - inherit (nixpkgs.lib) optional; + inherit (nixpkgs.lib) optional mkForce; in flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; @@ -32,6 +35,13 @@ }; cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + treefmtEval = treefmt-nix.lib.evalModule pkgs { + projectRootFile = "flake.nix"; + programs.alejandra.enable = true; + programs.rustfmt.enable = true; + settings.formatter.rustfmt.command = mkForce "${toolchain}/bin/rustfmt"; + }; in { packages.default = craneLib.buildPackage ( commonArgs @@ -52,5 +62,9 @@ pkgs.mob ]; }; + + formatter = treefmtEval.config.build.wrapper; + + checks.formatting = treefmtEval.config.build.check self; }); }