Nix flakes on the AT protocol
3

Configure Feed

Select the types of activity you want to include in your feed.

feat: add initial nixat implementation

+91
+91
nixat
··· 1 + #!/usr/bin/env bash 2 + 3 + set -euo pipefail 4 + 5 + check_login() { 6 + if ! goat account check-auth >/dev/null 2>&1; then 7 + echo "Please make sure you have logged in before-hand. Try:" 8 + echo "" 9 + printf "\t%s\n" "goat account login -u your_username_here -p your_app_password_here" 10 + echo "" 11 + echo "If you don't want to supply your password on the command-line, use a CLI password manager like \`pass\`:" 12 + echo "" 13 + printf "\t%s\n" "pass insert atproto/nixat" 14 + printf "\t%s\n" "goat account login -u your_username_here -p \"\$(pass show atproto/nixat)\"" 15 + exit 1 16 + fi 17 + } 18 + 19 + build() { 20 + local aturi="$1" 21 + shift 22 + echo "building flake pointed to by \`${aturi}\`:" 23 + check_login 24 + record="$(goat get "$aturi")" 25 + source="$(jq -r '.source' <<<"$record")" 26 + rev="$(jq -r '.rev' <<<"$record")" 27 + 28 + echo "TODO: this is broken" 29 + exit 1 30 + # nix build "git+ssh://${source}?rev=${rev}" "$@" 31 + } 32 + 33 + publish() { 34 + local path="$(realpath "$1")" version="$2" 35 + shift 36 + shift 37 + echo "publishing flake at ${path} with version ${version}" 38 + 39 + local rev source narHash publishedAt record 40 + rev="$(git -C "$path" rev-parse HEAD)" 41 + source="$(git -C "$path" remote get-url origin)" 42 + narHash="$(nix flake metadata --json "git+file://${path}?rev=${rev}" | jq -r .locked.narHash)" 43 + publishedAt="$(date -u +%Y-%m-%dT%H:%M:%SZ)" 44 + 45 + check_login 46 + record="$(printf '{"$type":"space.stau.nix.release","rev":"%s","source":"%s","narHash":"%s","publishedAt":"%s"}' "$rev" "$source" "$narHash" "$publishedAt")" 47 + jq -n "$record" | goat record create --rkey "$version" --no-validate - 48 + } 49 + 50 + usage() { 51 + echo "Usage: $0 <subcmd>" 52 + echo "" 53 + echo "The subcommands are:" 54 + echo "" 55 + printf "\t%s\n" "build <aturi> build a flake pointed at by <aturi>" 56 + printf "\t%s\n" "publish <path> <version> publish the flake at <path> with version <version>" 57 + printf "\t%s\n" "help | -h | --help | ? show this help" 58 + } 59 + 60 + if [ $# -gt 0 ]; then 61 + case $1 in 62 + "build") 63 + if [ $# -gt 1 ]; then 64 + build "$2" 65 + else 66 + echo "expected an AT URI as an argument" 67 + usage 68 + exit 1 69 + fi 70 + ;; 71 + "publish") 72 + if [ $# -gt 2 ]; then 73 + publish "$2" "$3" 74 + else 75 + echo "expected a path and a version name as arguments" 76 + usage 77 + exit 1 78 + fi 79 + ;; 80 + "help"|"-h"|"--help"|"?") 81 + usage 82 + ;; 83 + *) 84 + usage 85 + exit 1 86 + ;; 87 + esac 88 + else 89 + usage 90 + exit 1 91 + fi