build(nix): enable rustfmt check+formatter

with this, the gh actions ci will fail if submitted code does not adhere
to rustfmt rules.

additionally, running `nix fmt` will also format rust code.

because we want rules only supported by nightly rustfmt, and nixpkgs
doesn't have a nightly toolchain, we need to pull in another flake
input: fenix.
This commit is contained in:
Thomas Mühlbacher 2024-05-27 17:04:24 +02:00 committed by Kent Overstreet
parent 0e414b462f
commit ce01c61ba5
2 changed files with 52 additions and 0 deletions

View File

@ -1,5 +1,26 @@
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1716791293,
"narHash": "sha256-zxFADJsXhODHH9rrF7gXjN+BYVkMoNY2NpLyjGQDOJA=",
"owner": "nix-community",
"repo": "fenix",
"rev": "9af557bccdfa8fb6a425661c33dbae46afef0afa",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
@ -64,12 +85,30 @@
},
"root": {
"inputs": {
"fenix": "fenix",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1716714715,
"narHash": "sha256-xJ5vzVr5Et6wxHRQLOYicsa0gN2bwm4mj6AFHc8ugJc=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "71a816a90facb6546a0a06010da17598e11812f7",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [

View File

@ -11,6 +11,11 @@
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
@ -23,6 +28,7 @@
nixpkgs,
flake-parts,
treefmt-nix,
fenix,
flake-compat,
...
}:
@ -41,8 +47,12 @@
self',
config,
pkgs,
system,
...
}:
let
rustfmtToml = builtins.fromTOML (builtins.readFile ./rustfmt.toml);
in
{
packages.default = config.packages.bcachefs-tools;
packages.bcachefs-tools = pkgs.callPackage ./build.nix { };
@ -74,6 +84,9 @@
programs = {
nixfmt-rfc-style.enable = true;
rustfmt.edition = rustfmtToml.edition;
rustfmt.enable = true;
rustfmt.package = fenix.packages.${system}.default.rustfmt;
};
};
};