Add treefmt for code formatting
This commit is contained in:
parent
508bbd316e
commit
a8bbb068a2
3 changed files with 55 additions and 16 deletions
37
flake.lock
37
flake.lock
|
@ -96,6 +96,22 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_3": {
|
||||
"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": {
|
||||
"advisory-db": "advisory-db",
|
||||
|
@ -103,7 +119,8 @@
|
|||
"flake-utils": "flake-utils",
|
||||
"nix-filter": "nix-filter",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay"
|
||||
"rust-overlay": "rust-overlay",
|
||||
"treefmt-nix": "treefmt-nix"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
|
@ -138,6 +155,24 @@
|
|||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"treefmt-nix": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs_3"
|
||||
},
|
||||
"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",
|
||||
|
|
30
flake.nix
30
flake.nix
|
@ -9,6 +9,7 @@
|
|||
nix-filter.url = "github:numtide/nix-filter";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
treefmt-nix.url = "github:numtide/treefmt-nix";
|
||||
};
|
||||
|
||||
outputs =
|
||||
|
@ -20,6 +21,7 @@
|
|||
nix-filter,
|
||||
nixpkgs,
|
||||
rust-overlay,
|
||||
treefmt-nix,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
|
@ -54,23 +56,25 @@
|
|||
};
|
||||
|
||||
commonArgs = {
|
||||
inherit
|
||||
src
|
||||
stdenv
|
||||
nativeBuildInputs
|
||||
;
|
||||
inherit src stdenv nativeBuildInputs;
|
||||
strictDeps = true;
|
||||
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
|
||||
};
|
||||
|
||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||
|
||||
my-project = craneLib.buildPackage (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
}
|
||||
);
|
||||
treefmtEval = treefmt-nix.lib.evalModule pkgs {
|
||||
projectRootFile = "flake.nix";
|
||||
programs = {
|
||||
nixfmt.enable = true;
|
||||
nixfmt.package = pkgs.nixfmt-rfc-style;
|
||||
shfmt.enable = true;
|
||||
rustfmt.enable = true;
|
||||
};
|
||||
settings.formatter.rustfmt.command = pkgs.lib.mkForce "${pkgs.rust-toolchain}/bin/rustfmt";
|
||||
};
|
||||
|
||||
my-project = craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; });
|
||||
in
|
||||
rec {
|
||||
# `nix build`
|
||||
|
@ -100,8 +104,8 @@
|
|||
);
|
||||
};
|
||||
|
||||
# Formatter for the Nix code
|
||||
formatter = pkgs.nixpkgs-fmt;
|
||||
# For `nix fmt`
|
||||
formatter = treefmtEval.config.build.wrapper;
|
||||
|
||||
# `nix develop`
|
||||
devShells.default = pkgs.mkShell {
|
||||
|
|
4
justfile
4
justfile
|
@ -10,11 +10,11 @@ check:
|
|||
|
||||
# Lint all source code
|
||||
lint:
|
||||
echo FIXME: Add linter(s) here
|
||||
cargo clippy
|
||||
|
||||
# Format all source code
|
||||
fmt:
|
||||
echo FIXME: Add formatter here
|
||||
nix fmt
|
||||
|
||||
# Update all dependencies
|
||||
update: update-nix-pkgs update-rust-deps
|
||||
|
|
Loading…
Reference in a new issue