add treefmt

This commit is contained in:
Jörg Thalheim 2023-09-10 19:27:00 +02:00
parent 114758a6d4
commit 47b1beff0e
3 changed files with 78 additions and 2 deletions

View File

@ -55,7 +55,28 @@
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1693817438,
"narHash": "sha256-fg3+n4Ky1gCzDtPm0MomMTFw0YkH05Y8ojy5t7bkfHg=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "b8d3a059f5487d6767d07c3716386753e3132d9f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},

View File

@ -4,10 +4,14 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } ({ lib, ... }: {
imports = [ ./treefmt.nix ];
systems = [
"aarch64-linux"
"x86_64-linux"
@ -16,8 +20,15 @@
"aarch64-darwin"
];
perSystem = { pkgs, self', ... }: {
packages.nix-ci-builds = pkgs.callPackage ./default.nix {};
packages.nix-ci-builds = pkgs.callPackage ./default.nix { };
packages.default = self'.packages.nix-ci-builds;
checks =
let
packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") self'.packages;
devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") self'.devShells;
in
packages // devShells;
};
});
}

44
treefmt.nix Normal file
View File

@ -0,0 +1,44 @@
{ lib, inputs, ... }: {
imports = [
inputs.treefmt-nix.flakeModule
];
perSystem = { pkgs, ... }: {
treefmt = {
# Used to find the project root
projectRootFile = "flake.lock";
programs.mypy.enable = true;
settings.formatter = {
nix = {
command = "sh";
options = [
"-eucx"
''
# First deadnix
${lib.getExe pkgs.deadnix} --edit "$@"
# Then nixpkgs-fmt
${lib.getExe pkgs.nixpkgs-fmt} "$@"
''
"--"
];
includes = [ "*.nix" ];
};
python = {
command = "sh";
options = [
"-eucx"
''
${lib.getExe pkgs.ruff} --fix "$@"
${lib.getExe pkgs.black} "$@"
''
"--" # this argument is ignored by bash
];
includes = [ "*.py" ];
};
};
};
};
}