Skip to content

Instantly share code, notes, and snippets.

@zimbatm
Created May 20, 2021 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zimbatm/f041fae33b8d9ff34fb0952ca5b2ad95 to your computer and use it in GitHub Desktop.
Save zimbatm/f041fae33b8d9ff34fb0952ca5b2ad95 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Run this script to update the dependencies
set -euo pipefail
# This is the list of dependencies that should be generated using `cabal2nix`.
# The left-hand side is the name of the package, and .nix file that will be
# generated.
# The right-hand side is a `cabal2nix`-compatible URI.
declare -A dependencies=(
[protolude]=cabal://protolude-0.3.0 # password-instances depends on this
[generic-lens]=cabal://generic-lens-1.2.0.1
[servant]=cabal://servant-0.17
[servant-aeson-specs]=cabal://servant-aeson-specs-0.6.2.0
[servant-auth]=https://github.com/pwm/servant-auth
[servant-auth-server]=https://github.com/pwm/servant-auth
[servant-client]=cabal://servant-client-0.17
[servant-client-core]=cabal://servant-client-core-0.17
[servant-docs]=cabal://servant-docs-0.11.5
[servant-foreign]=cabal://servant-foreign-0.15.1
[servant-multipart]=cabal://servant-multipart-0.11.5
[servant-openapi3]=https://github.com/kcsongor/servant-openapi3
[servant-server]=cabal://servant-server-0.17
[openapi3]=https://github.com/kcsongor/openapi3
)
# Run in this folder
cd "$(dirname "$0")"
# Update the hackage index
# cabal update
# Remove all of the old files
rm ./*.nix
# Re-generate all of the nix files using cabal2nix
for name in "${!dependencies[@]}"; do
echo "--- $name ---"
uri=${dependencies[$name]}
if [[ $uri =~ ^https://.+$ ]]; then
# Use nix/sources.json as the canonical pin for github pulls
sha256=$(jq -r .\""$name"\".sha256 ../sources.json)
rev=$(jq -r .\""$name"\".rev ../sources.json)
case "$name" in
# repos where cabal files are in subdirs
"servant-auth"|"servant-auth-server")
cabal2nix --sha256 "$sha256" --revision "$rev" --subpath "$name" "$uri" > "$name.nix"
;;
*)
cabal2nix --sha256 "$sha256" --revision "$rev" "$uri" > "$name.nix"
;;
esac
else
cabal2nix "$uri" > "$name.nix"
fi
done
# Generate the index file
{
echo "lib: prev: {"
for name in "${!dependencies[@]}"; do
echo " $name = lib.doJailbreak (lib.dontCheck (prev.callPackage ./$name.nix {}));"
done
echo "}"
} > default.nix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment