1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-11 07:10:39 +02:00

feat: add treefmt and switch to nixfmt-rfc-style

This commit is contained in:
oddlama 2024-11-26 13:30:28 +01:00
parent 5cea27f592
commit deca311c68
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
3 changed files with 111 additions and 90 deletions

21
flake.lock generated
View file

@ -2071,6 +2071,7 @@
"nixvim": "nixvim", "nixvim": "nixvim",
"pre-commit-hooks": "pre-commit-hooks_6", "pre-commit-hooks": "pre-commit-hooks_6",
"stylix": "stylix", "stylix": "stylix",
"treefmt-nix": "treefmt-nix_5",
"whisper-overlay": "whisper-overlay", "whisper-overlay": "whisper-overlay",
"wired-notify": "wired-notify" "wired-notify": "wired-notify"
} }
@ -2511,6 +2512,26 @@
"type": "github" "type": "github"
} }
}, },
"treefmt-nix_5": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1732292307,
"narHash": "sha256-5WSng844vXt8uytT5djmqBCkopyle6ciFgteuA9bJpw=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "705df92694af7093dfbb27109ce16d828a79155f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
},
"treefmt_2": { "treefmt_2": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [

View file

@ -95,6 +95,11 @@
inputs.home-manager.follows = "home-manager"; inputs.home-manager.follows = "home-manager";
}; };
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
whisper-overlay = { whisper-overlay = {
url = "github:oddlama/whisper-overlay"; url = "github:oddlama/whisper-overlay";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -106,8 +111,9 @@
}; };
}; };
outputs = inputs: outputs =
inputs.flake-parts.lib.mkFlake {inherit inputs;} { inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ imports = [
./nix/agenix-rekey.nix ./nix/agenix-rekey.nix
./nix/devshell.nix ./nix/devshell.nix

View file

@ -1,99 +1,93 @@
{inputs, ...}: { { inputs, ... }:
{
imports = [ imports = [
inputs.devshell.flakeModule inputs.devshell.flakeModule
inputs.pre-commit-hooks.flakeModule inputs.pre-commit-hooks.flakeModule
inputs.treefmt-nix.flakeModule
]; ];
perSystem = { perSystem =
config, {
pkgs, config,
... pkgs,
}: { ...
pre-commit.settings.hooks = { }:
alejandra.enable = true; {
deadnix.enable = true; pre-commit.settings.hooks.treefmt.enable = true;
statix.enable = true; treefmt = {
#gitleaks = { projectRootFile = "flake.nix";
# enable = true; programs = {
# name = "gitleaks"; deadnix.enable = true;
# entry = "${pkgs.gitleaks}/bin/gitleaks protect --verbose --redact --staged"; statix.enable = true;
# language = "system"; nixfmt.enable = true;
# pass_filenames = false; rustfmt.enable = true;
#}; };
}; };
devshells.default = { devshells.default = {
packages = [ packages = [
pkgs.nix # Always use the nix version from this flake's nixpkgs version, so that nix-plugins (below) doesn't fail because of different nix versions. pkgs.nix # Always use the nix version from this flake's nixpkgs version, so that nix-plugins (below) doesn't fail because of different nix versions.
]; ];
commands = [ commands = [
{ {
package = pkgs.deploy; package = config.treefmt.build.wrapper;
help = "Build and deploy this nix config to nodes"; help = "Format all files";
} }
{ {
package = pkgs.alejandra; package = pkgs.deploy;
help = "Format nix code"; help = "Build and deploy this nix config to nodes";
} }
{ {
package = pkgs.statix; package = pkgs.nix-tree;
help = "Lint nix code"; help = "Interactively browse dependency graphs of Nix derivations";
} }
{ {
package = pkgs.deadnix; package = pkgs.nvd;
help = "Find unused expressions in nix code"; help = "Diff two nix toplevels and show which packages were upgraded";
} }
{ {
package = pkgs.nix-tree; package = pkgs.nix-diff;
help = "Interactively browse dependency graphs of Nix derivations"; help = "Explain why two Nix derivations differ";
} }
{ {
package = pkgs.nvd; package = pkgs.nix-output-monitor;
help = "Diff two nix toplevels and show which packages were upgraded"; help = "Nix Output Monitor (a drop-in alternative for `nix` which shows a build graph)";
} }
{ {
package = pkgs.nix-diff; package = pkgs.writeShellApplication {
help = "Explain why two Nix derivations differ"; name = "build";
} text = ''
{ set -euo pipefail
package = pkgs.nix-output-monitor; [[ "$#" -ge 1 ]] \
help = "Nix Output Monitor (a drop-in alternative for `nix` which shows a build graph)"; || { echo "usage: build <HOST>..." >&2; exit 1; }
} HOSTS=()
{ for h in "$@"; do
package = pkgs.writeShellApplication { HOSTS+=(".#nixosConfigurations.$h.config.system.build.toplevel")
name = "build"; done
text = '' nom build --no-link --print-out-paths --show-trace "''${HOSTS[@]}"
set -euo pipefail '';
[[ "$#" -ge 1 ]] \ };
|| { echo "usage: build <HOST>..." >&2; exit 1; } help = "Build a host configuration";
HOSTS=() }
for h in "$@"; do ];
HOSTS+=(".#nixosConfigurations.$h.config.system.build.toplevel")
done devshell.startup.pre-commit.text = config.pre-commit.installationScript;
nom build --no-link --print-out-paths --show-trace "''${HOSTS[@]}"
env = [
{
# Additionally configure nix-plugins with our extra builtins file.
# We need this for our repo secrets.
name = "NIX_CONFIG";
value = ''
plugin-files = ${pkgs.nix-plugins}/lib/nix/plugins
extra-builtins-file = ${./..}/nix/extra-builtins.nix
''; '';
}; }
help = "Build a host configuration"; ];
} };
];
devshell.startup.pre-commit.text = config.pre-commit.installationScript; # `nix fmt`
formatter = pkgs.alejandra;
env = [
{
# Additionally configure nix-plugins with our extra builtins file.
# We need this for our repo secrets.
name = "NIX_CONFIG";
value = ''
plugin-files = ${pkgs.nix-plugins}/lib/nix/plugins
extra-builtins-file = ${./..}/nix/extra-builtins.nix
'';
}
];
}; };
# `nix fmt`
formatter = pkgs.alejandra;
};
} }