From 1c5a478ad499356e0c6a11eeba02fdd701ee43f1 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Wed, 11 Sep 2024 09:00:57 +0100 Subject: [PATCH] chore: setup treefmt and pre-commit --- .gitignore | 1 + flake.lock | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 29 ++++++++++++++++++++ 3 files changed, 107 insertions(+) diff --git a/.gitignore b/.gitignore index 07c12f2..91ce0fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target result +.pre-commit-config.yaml diff --git a/flake.lock b/flake.lock index d09d2d9..1b89ce2 100644 --- a/flake.lock +++ b/flake.lock @@ -53,6 +53,22 @@ "type": "github" } }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -73,6 +89,27 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1725634671, @@ -89,6 +126,45 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1725513492, + "narHash": "sha256-tyMUA6NgJSvvQuzB7A1Sf8+0XCHyfSPRx/b00o6K0uo=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "7570de7b9b504cfe92025dd1be797bf546f66528", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "advisory-db": "advisory-db", @@ -96,6 +172,7 @@ "fenix": "fenix", "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks", "systems": "systems", "treefmt-nix": "treefmt-nix" } diff --git a/flake.nix b/flake.nix index ecf691d..0374be8 100644 --- a/flake.nix +++ b/flake.nix @@ -19,6 +19,11 @@ treefmt-nix.url = "github:numtide/treefmt-nix"; treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; + + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = { self, @@ -28,11 +33,16 @@ } @ inputs: flake-parts.lib.mkFlake {inherit self inputs;} { systems = import inputs.systems; + imports = [ + inputs.pre-commit-hooks.flakeModule + inputs.treefmt-nix.flakeModule + ]; perSystem = { pkgs, inputs', self', + config, ... }: let rustToolchain = inputs'.fenix.packages.fromToolchainFile { @@ -74,8 +84,27 @@ devShells.default = craneLib.devShell { inherit (self') checks; + inputsFrom = [config.pre-commit.devShell config.treefmt.build.devShell]; packages = []; }; + + pre-commit = { + check.enable = false; + settings.hooks = { + alejandra.enable = true; + deadnix.enable = true; + rustfmt.enable = true; + }; + }; + + treefmt.config = { + projectRootFile = "flake.nix"; + programs = { + alejandra.enable = true; + deadnix.enable = true; + rustfmt.enable = true; + }; + }; }; };