Skip to content

Instantly share code, notes, and snippets.

@jb55
Last active April 23, 2018 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jb55/d883c58ca042390d2e8d52318f622c0e to your computer and use it in GitHub Desktop.
Save jb55/d883c58ca042390d2e8d52318f622c0e to your computer and use it in GitHub Desktop.
nix git deploys
{
pkg-json = lib.importJSON /var/git/project/deploy.json;
pkg = (import (pkgs.fetchgit pkg-json) {}).package;
}
#! /run/current-system/sw/bin/bash
IFS=' ' read -r old rev branch
HOME=/home/jb55
UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1)
LOGURL="http://localhost:8899/deploy-$UUID.txt"
export HTTPIPE_URL='http://localhost:8899'
builder=$(cat <<EOF
(/run/current-system/sw/bin/nixos-rebuild switch -j 4 \
-I jb55pkgs=$HOME/etc/jb55pkgs \
-I dotfiles=$HOME/dotfiles \
-I nixpkgs=$HOME/etc/nixpkgs \
-I nixos-config=$HOME/etc/nix-files/configuration.nix; echo "==== DONE ====") \
|& /nix/store/y9pk3qa64y2sa0c3z7mwr5874v6w1dg6-node-httpipe-1.0.0/bin/httpipe "deploy-$UUID.txt"
EOF
)
if test "$branch" = "refs/heads/deploy-testing"; then
unset GIT_DIR
/nix/store/acwm577ib0lps0sx3y23wgn1109xilp6-nix-prefetch-scripts/bin/nix-prefetch-git \
--url /var/git/project \
--rev "$rev" \
2>/tmp/project-git-deploy.stderr \
| /nix/store/z08hl8df7wy9x9b848rjys2x4c5mnc9v-jq-1.5/bin/jq '{rev,sha256,url: "http://git.project.com/project"}' \
> /var/git/project/deploy.json
nohup /run/current-system/sw/bin/bash -c "$builder" &>/dev/null &
printf 'deploying...\n' "$UUID"
printf "logs:\ncurl '%s'\n" "http://logs.project.com/deploy-$UUID.txt"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment