Skip to content

Instantly share code, notes, and snippets.

@LnL7
Last active July 13, 2020 12:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LnL7/c2ff93e635a0779c839277d730829c12 to your computer and use it in GitHub Desktop.
Save LnL7/c2ff93e635a0779c839277d730829c12 to your computer and use it in GitHub Desktop.
Git deploy hook
#!/usr/bin/env bash
set -e
BRANCH=master
TARGET=/etc/nixos
ref="$1"
oldrev="$2"
newrev="$3"
echo >&2
echo " System generations" >&2
echo >&2
nix-env --list-generations -p /nix/var/nix/profiles/system | tail -3
echo >&2
if [ "$ref" = "refs/heads/$BRANCH" ]; then
echo >&2
echo " Deploying branch $BRANCH." >&2
echo >&2
git --work-tree="$TARGET" diff --stat --summary --find-copies-harder "$oldrev".."$newrev"
git --work-tree="$TARGET" checkout -f "$newrev"
git --work-tree="$TARGET" status
echo >&2
echo >&2
echo " Activating system..." >&2
echo >&2
nixos-rebuild switch --show-trace
echo >&2
echo >&2
echo " System deployed" >&2
echo >&2
nix-env --list-generations -p /nix/var/nix/profiles/system | tail -1
echo >&2
else
echo "Warning: doing nothing, only the $BRANCH branch will be deployed." >&2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment