59 lines
1.8 KiB
Bash
59 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
# https://direnv.net/man/direnv-stdlib.1.html
|
|
|
|
# for when i spawn a bunch of tabs
|
|
if command -v git-wait >/dev/null; then
|
|
git() { git-wait "$@"; }
|
|
fi
|
|
|
|
# TODO:
|
|
# git config --local core.hooksPath "$PWD"/.githooks
|
|
|
|
# ensure (dirty) updated flake lock
|
|
# TODO: cache this on gitea? Run in background?
|
|
now="$(date +%Y-%m-%d)"
|
|
if [[ ! -d .direnv/tmp ]]; then
|
|
mkdir -p .direnv/tmp
|
|
elif command -v find >/dev/null; then
|
|
find .direnv/tmp/ -mindepth 1 -maxdepth 1 -type d -and ! -newermt "4 hours ago" -delete
|
|
fi
|
|
if [[ ! -s .direnv/pull-date || "$now" != "$(cat .direnv/pull-date)" ]]; then
|
|
tmp=$(mktemp -p .direnv/tmp -d)
|
|
trap 'rm -rf "$tmp" >&/dev/null' ERR EXIT RETURN
|
|
if ! $GIT diff --exit-code --quiet HEAD -- flake.lock >&/dev/null; then
|
|
cp flake.lock "$tmp"/dirty-flake.lock
|
|
$GIT reset -- flake.lock
|
|
$GIT restore -- flake.lock
|
|
cp flake.lock "$tmp"/clean-flake.lock # we could instead preserve the current $GIT rev
|
|
fi
|
|
$GIT pull --rebase --autostash
|
|
if grep -q "^=======" flake.lock; then
|
|
# TODO: can this happen anymore?
|
|
$GIT reset -- flake.lock
|
|
rm flake.lock # restore?
|
|
$GIT checkout -- flake.lock
|
|
elif [[ -s "$tmp"/clean-flake.lock ]] && ! diff -q "$tmp"/clean-flake.lock flake.lock >&/dev/null; then
|
|
cp "$tmp"/flake-dirty.lock flake.lock
|
|
fi
|
|
# nix flake update
|
|
nix eval --file flake.nix --apply 'x: builtins.attrNames x.inputs' --json \
|
|
| jq .[] -r \
|
|
| grep -v '^nixpkgs-expensive$' \
|
|
| nix flake update # --output-lock-file "$tmp"/new-flake.lock
|
|
printf "%s\n" "$now" > .direnv/pull-date
|
|
fi
|
|
|
|
# source env
|
|
if [[ ! -f .remote.toml ]]; then
|
|
use flake .#envrc-local
|
|
else
|
|
use flake .#envrc-remote
|
|
printf "\n"
|
|
just motd
|
|
printf "\n"
|
|
fi
|
|
|
|
unset -f git
|
|
|
|
export QEMU_NET_OPTS="hostfwd=tcp::10022-:22,hostfwd=tcp::10080-:80,hostfwd=tcp::10443-:443"
|