Skip to content
Open
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
101 changes: 58 additions & 43 deletions .githooks/pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

set -Eeuo pipefail

_source_nix_profile_if_not_in_path() {
command -v nix &>/dev/null && return
local nixMultiUserDaemonProfile="/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
local nixSingleUserProfile="${HOME}/.nix-profile/etc/profile.d/nix.sh"
if [[ -f "$nixMultiUserDaemonProfile" ]]; then
# shellcheck source=/dev/null
. "$nixMultiUserDaemonProfile"
elif [[ -f "$nixSingleUserProfile" ]]; then
# shellcheck source=/dev/null
. "$nixSingleUserProfile"
fi
}

_source_nix_profile_if_not_in_path

[ "${SKIP_HOOKS:-0}" = "1" ] && exit 0

readonly REPO_ROOT=$(git rev-parse --show-toplevel)
Expand All @@ -11,61 +26,61 @@ readonly REPO_ROOT=$(git rev-parse --show-toplevel)
cd "$REPO_ROOT"

main() {
_run_check "statix" nix run nixpkgs#statix -- check . --ignore 'result*'
_run_check "deadnix" nix run nixpkgs#deadnix -- .
_run_check "nixfmt" bash -c "find . -name '*.nix' -not -path './result*' -not -path './.worktrees/*' -exec nix run nixpkgs#nixfmt-rfc-style -- --check {} +"
_run_check "validate-skill-frontmatter" ./tests/validate-skill-frontmatter.sh agents/skills
_run_quick_bats_tests
_remind_nix_tests_if_openclaw_changed

echo "All pre-push checks passed."
_run_check "statix" nix run nixpkgs#statix -- check . --ignore 'result*'
_run_check "deadnix" nix run nixpkgs#deadnix -- .
_run_check "nixfmt" bash -c "find . -name '*.nix' -not -path './result*' -not -path './.worktrees/*' -exec nix run nixpkgs#nixfmt-rfc-style -- --check {} +"
_run_check "validate-skill-frontmatter" ./tests/validate-skill-frontmatter.sh agents/skills
_run_quick_bats_tests
_remind_nix_tests_if_openclaw_changed

echo "All pre-push checks passed."
}

_run_check() {
local checkName="$1"
shift
echo "==> $checkName"
"$@"
echo ""
local checkName="$1"
shift
echo "==> $checkName"
"$@"
echo ""
}

_run_quick_bats_tests() {
echo "==> bats (quick)"
local testFiles=()
for testFile in tests/bin-scripts/*.bats; do
[[ "$(basename "$testFile")" == *-docker.bats ]] && continue
testFiles+=("$testFile")
done
nix shell nixpkgs#bats --command bats "${testFiles[@]}"
echo ""
echo "==> bats (quick)"
local testFiles=()
for testFile in tests/bin-scripts/*.bats; do
[[ "$(basename "$testFile")" == *-docker.bats ]] && continue
testFiles+=("$testFile")
done
nix shell nixpkgs#bats --command bats "${testFiles[@]}"
echo ""
}

_remind_nix_tests_if_openclaw_changed() {
if _openclaw_files_changed; then
echo ""
echo "NOTE: OpenClaw files changed. Run 'tests/run-all.sh --nix' to verify nix eval tests."
echo ""
fi
if _openclaw_files_changed; then
echo ""
echo "NOTE: OpenClaw files changed. Run 'tests/run-all.sh --nix' to verify nix eval tests."
echo ""
fi
}

_openclaw_files_changed() {
local watchedPaths=(
"home/modules/openclaw"
"users/zanoni/home/openclaw"
"users/lucas.zanoni/home/openclaw"
"tests/openclaw"
)

local changedFiles
changedFiles=$(git diff --name-only origin/main...HEAD 2>/dev/null || true)

for watchedPath in "${watchedPaths[@]}"; do
if echo "$changedFiles" | grep -q "^$watchedPath"; then
return 0
fi
done

return 1
local watchedPaths=(
"home/modules/openclaw"
"users/zanoni/home/openclaw"
"users/lucas.zanoni/home/openclaw"
"tests/openclaw"
)

local changedFiles
changedFiles=$(git diff --name-only origin/main...HEAD 2>/dev/null || true)

for watchedPath in "${watchedPaths[@]}"; do
if echo "$changedFiles" | grep -q "^$watchedPath"; then
return 0
fi
done

return 1
}

main "$@"
29 changes: 29 additions & 0 deletions home/modules/nix-path-bootstrap.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ config, ... }:
let
nixMultiUserDaemonBinPath = "/nix/var/nix/profiles/default/bin";
nixUserProfileBinPath = "${config.home.homeDirectory}/.nix-profile/bin";
nixDaemonProfileScript = "/etc/profile.d/nix.sh";
nixSingleUserProfileScript = "${config.home.homeDirectory}/.nix-profile/etc/profile.d/nix.sh";
in
{
home.sessionPath = [
nixMultiUserDaemonBinPath
nixUserProfileBinPath
];

home.file.".config/environment.d/10-nix-path.conf".text = ''
PATH=${nixMultiUserDaemonBinPath}:${nixUserProfileBinPath}:$PATH
'';

programs.bash.enable = true;

programs.bash.initExtra = ''
if ! command -v nix &>/dev/null; then
if [[ -f ${nixDaemonProfileScript} ]]; then
source ${nixDaemonProfileScript}
elif [[ -f ${nixSingleUserProfileScript} ]]; then
source ${nixSingleUserProfileScript}
fi
fi
'';
}
2 changes: 2 additions & 0 deletions users/lucas.zanoni/home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

../../home/core.nix
../../home/scripts
../../home/modules/nix-path-bootstrap.nix

../../home/modules/agenix.nix
../../home/modules/atuin.nix
../../home/modules/bad-apple.nix
Expand Down
Loading