NixOS configuration 馃獎
1{ lib, ... }:
2{
3 perSystem =
4 { pkgs, ... }:
5 {
6 formatter = pkgs.treefmt.withConfig {
7 runtimeInputs = with pkgs; [
8 nixfmt # nix formating tool
9 deadnix # find and remove unused nix files
10 statix # Lints and suggestions for the nix programming language
11 shellcheck # shell script analysis tool
12 shfmt # format .sh files
13 taplo # TOML toolkit
14 yamlfmt # format .yaml or yml files
15
16 # useful script for statix commands to work
17 # https://github.com/isabelroses/dotfiles/blob/23c7db61455348653703d32ffdc2135fd045f6b8/modules/flake/programs/formatter.nix#L22C1-L26C14
18 (writeShellScriptBin "statix-fix" ''
19 for file in "$@"; do
20 ${lib.getExe statix} fix "$file"
21 done
22 '')
23 ];
24
25 settings = {
26 on-unmatched = "info";
27 tree-root-file = "flake.nix";
28
29 excludes = [
30 "secrets/*"
31 "assets/*"
32 ];
33
34 formatter = {
35 nixfmt = {
36 command = "nixfmt";
37 includes = [ "*.nix" ];
38 };
39
40 deadnix = {
41 command = "deadnix";
42
43 # Warn if there was any dead nix files
44 options = [ "--edit" ];
45 includes = [ "*.nix" ];
46 };
47
48 statix = {
49 command = "statix-fix";
50 includes = [ "*.nix" ];
51 };
52
53 shellcheck = {
54 command = "shellcheck";
55
56 includes = [
57 "*.sh"
58 "*.bash"
59 "*.envrc"
60 "*.envrc.*"
61 ];
62 };
63
64 shfmt = {
65 command = "shfmt";
66 options = [
67 "-s" # simplify the code
68 "-w" # write changes if found changes
69 "-i"
70 "2" # indent files for 2 spaces
71 ];
72
73 includes = [
74 "*.sh"
75 "*.bash"
76 "*.envrc"
77 "*.envrc.*"
78 ];
79 };
80
81 taplo = {
82 command = "taplo";
83 options = "format";
84 includes = [ "*.toml" ];
85 };
86
87 yamlfmt = {
88 command = "yamlfmt";
89 options = [
90 "-formatter"
91 ];
92
93 includes = [
94 "*.yml"
95 "*.yaml"
96 ];
97 };
98 };
99 };
100 };
101 };
102}