flake: enable treefmt for formatting

- for now, uses only `nixfmt-rfc-style`
- can be invoked with `nix flake check` and `nix fmt`
This commit is contained in:
Trolli Schmittlauch 2024-03-16 17:14:33 +01:00
parent d25fffc899
commit 3a31c21ae2
2 changed files with 38 additions and 1 deletions

View file

@ -307,6 +307,7 @@
"nixos-unstable": "nixos-unstable",
"nixpkgs": "nixpkgs_2",
"nur": "nur",
"treefmt-nix": "treefmt-nix",
"utils": "utils"
}
},
@ -365,6 +366,26 @@
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1710278050,
"narHash": "sha256-Oc6BP7soXqb8itlHI8UKkdf3V9GeJpa1S39SR5+HJys=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "35791f76524086ab4b785a33e4abbedfda64bd22",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems_2"

View file

@ -14,6 +14,10 @@
# deliberately do _not_ follow the nixpkgs input here, because paranoia and test coverage
};
utils.url = "github:numtide/flake-utils";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
nur.url = "github:nix-community/NUR";
# TODO: possible make this a flake as well
@ -25,7 +29,7 @@
};
outputs =
{ self, nixpkgs, nur, lanzaboote, utils, home-manager, ... }@inputs:
{ self, nixpkgs, nur, lanzaboote, utils, home-manager, treefmt-nix, ... }@inputs:
let
# FIXME: allow different systems
systems = utils.lib.system;
@ -71,6 +75,10 @@
inherit inputs system;
};
};
treefmtConf = {pkgs, ...}:{
projectRootFile = "flake.nix";
programs.nixfmt-rfc-style.enable = true;
};
in
{
overlays.default = import ./packages;
@ -85,11 +93,19 @@
inherit system;
overlays = nixpkgs.lib.attrValues self.overlays;
};
nixpkgs_unstable = import inputs.nixos-unstable {
inherit system;
overlays = nixpkgs.lib.attrValues self.overlays;
};
pkgs = inputs.nixpkgs.legacyPackages.${system};
pkgs_unstable = inputs.nixos-unstable.legacyPackages.${system};
treefmtEval = treefmt-nix.lib.evalModule pkgs_unstable treefmtConf;
in {
devShells.default = pkgs.mkShell {
buildInputs = [];
};
formatter = treefmtEval.config.build.wrapper;
checks.formatting = treefmtEval.config.build.check self;
# expose nixpkgs with overlay; TODO: figure out role of config
#legacyPackages = nixpkgs;
});