logos-delivery/tools/gen-nix-deps.sh
Ivan FB f5762af4c4
Start using nimble and deprecate vendor dependencies (#3798)
Co-authored-by: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com>
Co-authored-by: Darshan K <35736874+darshankabariya@users.noreply.github.com>
2026-04-08 12:42:14 +02:00

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"