add treefmt-nix to repository

This commit is contained in:
Jörg Thalheim 2022-12-31 07:18:49 +01:00
parent d4b7281357
commit fea7e110c2
5 changed files with 86 additions and 2 deletions

2
ci.nix
View file

@ -12,4 +12,4 @@ in
# FIXME: maybe find a more generic solution here?
devShell-x86_64 = self.outputs.devShells.x86_64-linux.default;
devShell-aarch64 = self.outputs.devShells.aarch64-linux.default;
}
} // self.outputs.checks.x86_64-linux # mainly for treefmt at the moment...

18
flake.lock generated
View file

@ -223,7 +223,8 @@
"nixpkgs-update-pypi-releases": "nixpkgs-update-pypi-releases",
"nur-update": "nur-update",
"sops-nix": "sops-nix",
"srvos": "srvos"
"srvos": "srvos",
"treefmt-nix": "treefmt-nix"
}
},
"sops-nix": {
@ -266,6 +267,21 @@
"repo": "srvos",
"type": "github"
}
},
"treefmt-nix": {
"locked": {
"lastModified": 1672170030,
"narHash": "sha256-hvTMwlutePPQ4eNMVHiI0crixCyeSTKJIDhLD/66t2g=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "c97bb3db343ccd2f04dd4e5fa8750e821560e9ca",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",

View file

@ -31,6 +31,8 @@
disko.url = "github:nix-community/disko";
disko.inputs.nixpkgs.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs = inputs @ {flake-parts, ...}:
@ -39,13 +41,19 @@
{
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
imports = [
./treefmt.nix
];
perSystem = {
inputs',
pkgs,
self',
...
}: {
devShells.default = pkgs.callPackage ./shell.nix {
inherit (inputs'.sops-nix.packages) sops-import-keys-hook;
inherit (self'.packages) treefmt;
};
};
flake.nixosConfigurations = let

View file

@ -1,5 +1,6 @@
{ pkgs
, sops-import-keys-hook
, treefmt
}:
with pkgs;
@ -26,6 +27,7 @@ mkShellNoCC {
]
))
rsync
treefmt
sops-import-keys-hook
];

58
treefmt.nix Normal file
View file

@ -0,0 +1,58 @@
{ inputs, ... }: {
imports = [
inputs.treefmt-nix.flakeModule
];
perSystem = { pkgs, ... }: {
treefmt = {
# Used to find the project root
projectRootFile = "flake.lock";
programs.terraform.enable = true;
settings.formatter = {
nix = {
command = "sh";
options = [
"-eucx"
''
# First deadnix
${pkgs.lib.getExe pkgs.deadnix} --edit "$@"
# Then nixpkgs-fmt
${pkgs.lib.getExe pkgs.nixpkgs-fmt} "$@"
''
"--"
];
includes = [ "*.nix" ];
excludes = [ "nix/sources.nix" ];
};
shell = {
command = "sh";
options = [
"-eucx"
''
# First shellcheck
${pkgs.lib.getExe pkgs.shellcheck} --external-sources --source-path=SCRIPTDIR "$@"
# Then format
${pkgs.lib.getExe pkgs.shfmt} -i 2 -s -w "$@"
''
"--"
];
includes = [ "*.sh" ];
};
python = {
command = "sh";
options = [
"-eucx"
''
${pkgs.lib.getExe pkgs.ruff} --fix "$@"
${pkgs.lib.getExe pkgs.python3.pkgs.black} "$@"
''
"--" # this argument is ignored by bash
];
includes = [ "*.py" ];
};
};
};
};
}