Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail

# Check if we're in a nix environment
if command -v nix >/dev/null 2>&1 && [ -f "flake.nix" ]; then
# Use nix develop for consistent environment
if ! nix develop -c cargo fmt --check 2>/dev/null; then
echo "❌ Code is not formatted. Please run 'nix develop -c cargo fmt' before committing."
echo ""
echo "To see what needs formatting:"
echo " nix develop -c cargo fmt --check --verbose"
exit 1
fi
else
# Fallback to regular cargo
if ! cargo fmt --check 2>/dev/null; then
echo "❌ Code is not formatted. Please run 'cargo fmt' before committing."
echo ""
echo "To see what needs formatting:"
echo " cargo fmt --check --verbose"
exit 1
fi
fi

echo "✅ Code formatting check passed"
68 changes: 68 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
set -euo pipefail

echo "🔍 Running pre-push checks..."
echo ""

# Check if we're in a nix environment
if command -v nix >/dev/null 2>&1 && [ -f "flake.nix" ]; then
# Check formatting
echo "📝 Checking code formatting..."
if ! nix develop -c cargo fmt --check 2>/dev/null; then
echo ""
echo "❌ Code is not formatted. Please run 'nix develop -c cargo fmt' before pushing."
echo ""
echo "To see what needs formatting:"
echo " nix develop -c cargo fmt --check --verbose"
exit 1
fi
echo "✅ Formatting check passed"
echo ""

# Run clippy
echo "🔎 Running clippy linting..."
if ! nix develop -c cargo clippy --workspace -- -D warnings 2>&1; then
echo ""
echo "❌ Clippy found issues. Please fix them before pushing."
echo ""
echo "To see all issues:"
echo " nix develop -c cargo clippy --workspace"
echo ""
echo "To attempt automatic fixes:"
echo " nix develop -c cargo clippy --workspace --fix --allow-dirty"
exit 1
fi
echo "✅ Clippy check passed"
else
# Fallback to regular cargo
echo "📝 Checking code formatting..."
if ! cargo fmt --check 2>/dev/null; then
echo ""
echo "❌ Code is not formatted. Please run 'cargo fmt' before pushing."
echo ""
echo "To see what needs formatting:"
echo " cargo fmt --check --verbose"
exit 1
fi
echo "✅ Formatting check passed"
echo ""

# Run clippy
echo "🔎 Running clippy linting..."
if ! cargo clippy --workspace -- -D warnings 2>&1; then
echo ""
echo "❌ Clippy found issues. Please fix them before pushing."
echo ""
echo "To see all issues:"
echo " cargo clippy --workspace"
echo ""
echo "To attempt automatic fixes:"
echo " cargo clippy --workspace --fix --allow-dirty"
exit 1
fi
echo "✅ Clippy check passed"
fi

echo ""
echo "✅ All pre-push checks passed! Proceeding with push..."
echo ""
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,55 @@ $ nix develop
$ cargo build --release -F alkali
```

## Development

This project uses Git hooks for maintaining code quality. When you enter the development environment, hooks are automatically configured:

```bash
$ nix develop
📎 Setting up Git hooks for code quality checks...
✅ Git hooks configured automatically!
• pre-commit: Checks code formatting
• pre-push: Runs formatting and clippy checks
```

### Git Hooks

The project includes two Git hooks that help maintain code quality:

1. **pre-commit**: Ensures code is properly formatted before committing
2. **pre-push**: Runs both formatting and clippy checks before pushing

These hooks are automatically configured when you enter the nix development shell. To manually configure them:

```bash
git config core.hooksPath .githooks
```

To disable the hooks temporarily:

```bash
git config --unset core.hooksPath
```

### Running Checks Manually

You can run the quality checks manually at any time:

```bash
# Check formatting
nix develop -c cargo fmt --check

# Fix formatting
nix develop -c cargo fmt

# Run clippy
nix develop -c cargo clippy --workspace -- -D warnings

# Run all checks
nix develop -c cargo fmt --check && nix develop -c cargo clippy --workspace -- -D warnings
```

## CLI quick‑start

Note: salt is a hex encoded string of 16 bytes. It's good enough to generate it once and reuse for multiple keys. You can generate with:
Expand Down
17 changes: 17 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@

CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = "${pkgs.pkgsStatic.stdenv.cc}/bin/${pkgs.pkgsStatic.stdenv.cc.targetPrefix}cc";
CC_x86_64_unknown_linux_musl = "${pkgs.pkgsStatic.stdenv.cc}/bin/${pkgs.pkgsStatic.stdenv.cc.targetPrefix}cc";

# Automatically configure Git hooks for code quality
shellHook = ''
# Set up Git hooks if not already configured
if [ -d .git ] && [ -d .githooks ]; then
current_hooks_path=$(git config core.hooksPath || echo "")
if [ "$current_hooks_path" != ".githooks" ]; then
echo "📎 Setting up Git hooks for code quality checks..."
git config core.hooksPath .githooks
echo "✅ Git hooks configured automatically!"
echo " • pre-commit: Checks code formatting"
echo " • pre-push: Runs formatting and clippy checks"
echo ""
echo "To disable: git config --unset core.hooksPath"
fi
fi
'';
};
}
);
Expand Down