Skip to content

Instantly share code, notes, and snippets.

@andreabedini
Created October 27, 2023 05:58
#!/usr/bin/env -S jq --raw-output --null-input --slurpfile plan dist-newstyle/cache/plan.json -f
#
# Download all packages needed for a plan.json into something that can be used as a local repository
#
# This script produces a file that can be stored and then passed to curl with the "--config".
# The downloaded files are reproducible.
#
def pkgId:
"\(."pkg-name")-\(."pkg-version")"
;
def pkgSrc:
(."pkg-src".repo.uri | rtrimstr("/") + "/packages/") + pkgId + ".tar.gz"
;
def casa($hash):
"https://casa.stackage.org/\($hash)"
;
def curl($url; $output):
"url = \($url)", "output = \($output)"
;
"
#
# You can download these files with curl, i.e.
#
# curl --parallel --create-dir --output-dir my-local-repository --config filename
#
",
($plan[0]."install-plan"
| INDEX(pkgId)[]
| # skip pre-existing packages
select(.type == "configured")
| # select only packages from repositories (this could be extended)
select(."pkg-src".type == "repo-tar")
| # compose the output
(curl(pkgSrc; pkgId + ".tar.gz")
, "# sha256 = \(."pkg-src-sha256")"
, "")
, (curl(casa(."pkg-cabal-sha256"); pkgId + ".cabal")
, "# sha256 = \(."pkg-cabal-sha256")"
, "")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment