#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
flakeref="${1-}"
name="${2-}"
if [ -z "$flakeref" ] || [ -z "$name" ];
then
echo "Usage: $0 FLAKEREF NAME"
exit 1
fi
imagename=$(nix eval --no-allow-dirty --raw $flakeref.imageName)
imagetag=$(nix eval --no-allow-dirty --raw $flakeref.imageTag)
image=$(nix build --no-allow-dirty $flakeref --print-out-paths --no-link)
gitrev=$(git rev-parse HEAD)
docker load < $image
docker tag $imagename:$imagetag git.kun.is/home/$name:$gitrev
docker push git.kun.is/home/$name:$gitrev