Last active
July 13, 2020 12:33
-
-
Save LnL7/c2ff93e635a0779c839277d730829c12 to your computer and use it in GitHub Desktop.
Git deploy hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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