From cc62f8a2b97f0f748f61f43811367f3ac1384b77 Mon Sep 17 00:00:00 2001 From: Lukas Wurzinger Date: Sun, 1 Dec 2024 16:43:53 +0000 Subject: [PATCH] hooks --- .gitignore | 2 + disk.sh | 4 +- flake.lock | 138 +++++++++++++++++++++++++++++++++++++++++++++++++--- flake.nix | 45 +++++++++++++++-- lib.nix | 2 +- treefmt.nix | 19 ++++++++ 6 files changed, 198 insertions(+), 12 deletions(-) mode change 100644 => 100755 disk.sh create mode 100644 treefmt.nix diff --git a/.gitignore b/.gitignore index 9b42106..b9c4c40 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .direnv/ + +.pre-commit-config.yaml diff --git a/disk.sh b/disk.sh old mode 100644 new mode 100755 index d4be5c4..739a820 --- a/disk.sh +++ b/disk.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + set -o errexit set -o nounset set -o pipefail @@ -72,7 +74,7 @@ while true; do printf '\n' read -r -s -p 'Re-enter password: ' repassword printf '\n' - if [[ "$password" == "$repassword" ]]; then + if [[ $password == "$repassword" ]]; then break fi done diff --git a/flake.lock b/flake.lock index 7b88d23..9aa85ff 100644 --- a/flake.lock +++ b/flake.lock @@ -43,6 +43,22 @@ "type": "github" } }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" @@ -61,13 +77,55 @@ "type": "github" } }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1732021966, + "narHash": "sha256-mnTbjpdqF0luOkou8ZFi2asa1N3AA2CchR/RqCNmsGE=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "3308484d1a443fc5bc92012435d79e80458fe43c", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "hardware": { "locked": { - "lastModified": 1732483221, - "narHash": "sha256-kF6rDeCshoCgmQz+7uiuPdREVFuzhIorGOoPXMalL2U=", + "lastModified": 1733066523, + "narHash": "sha256-aQorWITXZu7b095UwnpUvcGt9dNJie/GO9r4hZfe2sU=", "owner": "NixOS", "repo": "nixos-hardware", - "rev": "45348ad6fb8ac0e8415f6e5e96efe47dd7f39405", + "rev": "fe01780d356d70fd119a19277bff71d3e78dad00", "type": "github" }, "original": { @@ -99,7 +157,7 @@ }, "hxwrap": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_3" }, "locked": { "lastModified": 1730417950, @@ -143,7 +201,39 @@ "url": "https://github.com/NixOS/nixpkgs/archive/cc2f28000298e1269cea6612cd06ec9979dd5d7f.tar.gz" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1730741070, + "narHash": "sha256-edm8WG19kWozJ/GqyYx2VjW99EdhjKwbY3ZwdlPAAlo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d063c1dd113c91ab27959ba540c0d9753409edf3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { + "locked": { + "lastModified": 1730768919, + "narHash": "sha256-8AKquNnnSaJRXZxc5YmF/WfmxiHX6MMZZasRP6RRQkE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a04d33c0c3f1a59a2c1cb0c6e34cd24500e5a1dc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1730200266, "narHash": "sha256-l253w0XMT8nWHGXuXqyiIC/bMvh1VRszGXgdpQlfhvU=", @@ -159,7 +249,7 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_4": { "locked": { "lastModified": 1732837521, "narHash": "sha256-jNRNr49UiuIwaarqijgdTR2qLPifxsVhlJrKzQ8XUIE=", @@ -175,13 +265,31 @@ "type": "github" } }, + "nixpkgs_5": { + "locked": { + "lastModified": 1731890469, + "narHash": "sha256-D1FNZ70NmQEwNxpSSdTXCSklBH1z2isPR84J6DQrJGs=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5083ec887760adfe12af64830a66807423a859a7", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "agenix": "agenix", "flake-parts": "flake-parts", + "git-hooks": "git-hooks", "hardware": "hardware", "hxwrap": "hxwrap", - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_4", + "treefmt": "treefmt" } }, "systems": { @@ -198,6 +306,24 @@ "repo": "default", "type": "github" } + }, + "treefmt": { + "inputs": { + "nixpkgs": "nixpkgs_5" + }, + "locked": { + "lastModified": 1732894027, + "narHash": "sha256-2qbdorpq0TXHBWbVXaTqKoikN4bqAtAplTwGuII+oAc=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "6209c381904cab55796c5d7350e89681d3b2a8ef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 6fb3fcb..7b40c6f 100644 --- a/flake.nix +++ b/flake.nix @@ -4,6 +4,8 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; + git-hooks.url = "github:cachix/git-hooks.nix"; + treefmt.url = "github:numtide/treefmt-nix"; hardware.url = "github:NixOS/nixos-hardware"; agenix.url = "github:ryantm/agenix"; hxwrap.url = "github:lukaswrz/hxwrap"; @@ -12,9 +14,15 @@ outputs = { nixpkgs, flake-parts, + treefmt, ... } @ inputs: flake-parts.lib.mkFlake {inherit inputs;} { + imports = [ + inputs.git-hooks.flakeModule + inputs.treefmt.flakeModule + ]; + systems = ["x86_64-linux" "aarch64-linux"]; flake = let @@ -31,15 +39,44 @@ }; perSystem = { - inputs', + config, pkgs, + inputs', ... }: { - devShells.default = pkgs.mkShellNoCC { - packages = [inputs'.agenix.packages.agenix]; + treefmt = ./treefmt.nix; + + pre-commit = { + check.enable = true; + + settings = { + hooks = { + treefmt.enable = true; + deadnix.enable = true; + statix.enable = true; + shellcheck = { + enable = true; + excludes = [ + "^\.envrc$" + ]; + }; + flake-checker.enable = true; + }; + }; }; - formatter = pkgs.alejandra; + devShells.default = pkgs.mkShellNoCC { + inherit (config.pre-commit.devShell) shellHook; + + inputsFrom = [ + config.pre-commit.devShell + config.treefmt.build.devShell + ]; + + packages = [ + inputs'.agenix.packages.agenix + ]; + }; packages.disk = pkgs.writeShellApplication { name = "disk"; diff --git a/lib.nix b/lib.nix index 1280330..28184c3 100644 --- a/lib.nix +++ b/lib.nix @@ -69,7 +69,7 @@ lib: _: { class: map (name: {inherit class name;}) (dirsIn (hostsDir + "/${class}")) ) classes) - (map (obj: lib.nameValuePair obj.name (commonNixosSystem obj))) + (map (args: lib.nameValuePair args.name (commonNixosSystem args))) builtins.listToAttrs ]; } diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..c152dbc --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,19 @@ +{ + projectRootFile = ".git/config"; + enableDefaultExcludes = true; + + settings.global.excludes = [ + "LICENSE" + "*.age" + "*.envrc" + ]; + + programs = { + alejandra.enable = true; + shfmt = { + enable = true; + indent_size = 2; + }; + mdformat.enable = true; + }; +}