From f202c5b3eb662580b07078f75dce261e754dccb0 Mon Sep 17 00:00:00 2001 From: Nate Anderson Date: Tue, 30 Sep 2025 23:50:11 -0600 Subject: [PATCH] Added flake with dev deps and git hooks --- .direnv/bin/nix-direnv-reload | 19 +++++++++++ .envrc | 1 + .githooks/pre-commit | 52 +++++++++++++++++++++++++++++ .gitignore | 3 ++ flake.lock | 61 +++++++++++++++++++++++++++++++++++ flake.nix | 37 +++++++++++++++++++++ scripts/install_hooks.sh | 29 +++++++++++++++++ 7 files changed, 202 insertions(+) create mode 100755 .direnv/bin/nix-direnv-reload create mode 100644 .envrc create mode 100755 .githooks/pre-commit create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 scripts/install_hooks.sh diff --git a/.direnv/bin/nix-direnv-reload b/.direnv/bin/nix-direnv-reload new file mode 100755 index 0000000..2f3641f --- /dev/null +++ b/.direnv/bin/nix-direnv-reload @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -e +if [[ ! -d "/home/nate/source/fosscat-site" ]]; then + echo "Cannot find source directory; Did you move it?" + echo "(Looking for "/home/nate/source/fosscat-site")" + echo 'Cannot force reload with this script - use "direnv reload" manually and then try again' + exit 1 +fi + +# rebuild the cache forcefully +_nix_direnv_force_reload=1 direnv exec "/home/nate/source/fosscat-site" true + +# Update the mtime for .envrc. +# This will cause direnv to reload again - but without re-building. +touch "/home/nate/source/fosscat-site/.envrc" + +# Also update the timestamp of whatever profile_rc we have. +# This makes sure that we know we are up to date. +touch -r "/home/nate/source/fosscat-site/.envrc" "/home/nate/source/fosscat-site/.direnv"/*.rc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..3b913c3 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +set -e + +echo "Running pre-commit checks..." + +# Get list of staged markdown files +STAGED_MD_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.md$' || true) + +if [ -z "$STAGED_MD_FILES" ]; then + echo "No markdown files to check." + exit 0 +fi + +echo "Checking markdown files..." + +# Check markdown formatting with markdownlint-cli +if command -v markdownlint &> /dev/null; then + echo "Running markdownlint..." + markdownlint $STAGED_MD_FILES || { + echo "❌ Markdown linting failed. Fix issues or use 'git commit --no-verify' to skip." + exit 1 + } +else + echo "⚠️ markdownlint not found, skipping markdown linting" +fi + +# Spell check +if command -v aspell &> /dev/null; then + echo "Running spell check..." + MISSPELLED=0 + for file in $STAGED_MD_FILES; do + # Extract text, strip markdown syntax, check spelling + ERRORS=$(cat "$file" | aspell list --mode=markdown --personal=./.aspell.personal 2>/dev/null | sort -u) + if [ ! -z "$ERRORS" ]; then + echo "⚠️ Possible misspellings in $file:" + echo "$ERRORS" | sed 's/^/ /' + MISSPELLED=1 + fi + done + if [ $MISSPELLED -eq 1 ]; then + echo "" + echo "Review spelling errors above. Add correct terms to .aspell.personal" + echo "Use 'git commit --no-verify' to skip if needed." + exit 1 + fi +else + echo "⚠️ aspell not found, skipping spell check" +fi + +echo "✅ Pre-commit checks passed!" +exit 0 diff --git a/.gitignore b/.gitignore index 86c95ef..27775eb 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ hugo.linux # Temporary lock file while building /.hugo_build.lock + +# direnv stuff +.direnv/** diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5850e1a --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1759036355, + "narHash": "sha256-0m27AKv6ka+q270dw48KflE0LwQYrO7Fm4/2//KCVWg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e9f00bd893984bc8ce46c895c3bf7cac95331127", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..5497b40 --- /dev/null +++ b/flake.nix @@ -0,0 +1,37 @@ +{ + description = "Hugo static site development environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + hugo + marksman # Markdown LSP server + nodePackages.prettier # Format markdown and other files + markdownlint-cli + aspell + aspellDicts.en + ]; + + shellHook = '' + echo "Hugo development environment loaded" + echo "Hugo version: $(hugo version)" + # Auto-install git hooks if not already installed + if [ ! -L .git/hooks/pre-commit ]; then + bash scripts/install_hooks.sh + fi + echo "Hugo development environment loaded" + ''; + }; + } + ); +} diff --git a/scripts/install_hooks.sh b/scripts/install_hooks.sh new file mode 100644 index 0000000..6d7e0ba --- /dev/null +++ b/scripts/install_hooks.sh @@ -0,0 +1,29 @@ + +#!/usr/bin/env bash + +set -e + +HOOKS_DIR=".githooks" +GIT_HOOKS_DIR=".git/hooks" + +echo "Installing git hooks..." + +# Create .git/hooks directory if it doesn't exist +mkdir -p "$GIT_HOOKS_DIR" + +# Symlink all hooks from .githooks to .git/hooks +for hook in "$HOOKS_DIR"/*; do + hook_name=$(basename "$hook") + target="$GIT_HOOKS_DIR/$hook_name" + + # Remove existing hook or symlink + [ -e "$target" ] && rm "$target" + + # Create symlink + ln -s "../../$HOOKS_DIR/$hook_name" "$target" + chmod +x "$hook" + + echo "✅ Installed $hook_name" +done + +echo "Git hooks installed successfully!"