mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-04-17 05:33:07 +00:00
81 lines
1.6 KiB
Bash
Executable File
81 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Generates nix/deps.nix from nimble.lock using nix-prefetch-git.
|
|
# Usage: ./tools/gen-nix-deps.sh [nimble.lock] [nix/deps.nix]
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage:
|
|
$0 <nimble.lock> <output.nix>
|
|
|
|
Example:
|
|
$0 nimble.lock nix/deps.nix
|
|
EOF
|
|
}
|
|
|
|
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
|
|
usage; exit 0
|
|
fi
|
|
|
|
if [[ $# -ne 2 ]]; then
|
|
usage; exit 1
|
|
fi
|
|
|
|
LOCKFILE="$1"
|
|
OUTFILE="$2"
|
|
|
|
command -v jq >/dev/null || { echo "error: jq required"; exit 1; }
|
|
command -v nix-prefetch-git >/dev/null || { echo "error: nix-prefetch-git required"; exit 1; }
|
|
|
|
if [[ ! -f "$LOCKFILE" ]]; then
|
|
echo "[!] $LOCKFILE not found"
|
|
echo "[*] Generating $LOCKFILE via 'nimble lock'"
|
|
nimble lock
|
|
fi
|
|
|
|
echo "[*] Generating $OUTFILE from $LOCKFILE"
|
|
mkdir -p "$(dirname "$OUTFILE")"
|
|
|
|
cat > "$OUTFILE" <<'EOF'
|
|
# AUTOGENERATED from nimble.lock — do not edit manually.
|
|
# Regenerate with: ./tools/gen-nix-deps.sh nimble.lock nix/deps.nix
|
|
{ pkgs }:
|
|
|
|
{
|
|
EOF
|
|
|
|
jq -c '
|
|
.packages
|
|
| to_entries[]
|
|
| select(.value.downloadMethod == "git")
|
|
| select(.key != "nim" and .key != "nimble")
|
|
' "$LOCKFILE" | while read -r entry; do
|
|
name=$(jq -r '.key' <<<"$entry")
|
|
url=$(jq -r '.value.url' <<<"$entry")
|
|
rev=$(jq -r '.value.vcsRevision' <<<"$entry")
|
|
|
|
echo " [*] Prefetching $name @ $rev"
|
|
|
|
sha=$(nix-prefetch-git \
|
|
--url "$url" \
|
|
--rev "$rev" \
|
|
--fetch-submodules \
|
|
| jq -r '.sha256')
|
|
|
|
cat >> "$OUTFILE" <<EOF
|
|
${name} = pkgs.fetchgit {
|
|
url = "${url}";
|
|
rev = "${rev}";
|
|
sha256 = "${sha}";
|
|
fetchSubmodules = true;
|
|
};
|
|
|
|
EOF
|
|
done
|
|
|
|
cat >> "$OUTFILE" <<'EOF'
|
|
}
|
|
EOF
|
|
|
|
echo "[✓] Wrote $OUTFILE"
|