···1515# password-command: pass hackage.haskell.org (this can be any command, but not an arbitrary shell expression. Like cabal we only read the first output line and ignore the rest.)
1616# Those fields are specified under `upload` on the `cabal` man page.
17171818+if test -z "$CABAL_DIR"; then
1919+ dirs=(
2020+ "$HOME/.cabal"
2121+ "${XDG_CONFIG_HOME:-$HOME/.config}/cabal"
2222+ )
2323+ missing=true
2424+2525+ for dir in "${dirs[@]}"; do
2626+ if test -d "$dir"; then
2727+ export CABAL_DIR="$dir"
2828+ missing=false
2929+ break
3030+ fi
3131+ done
3232+3333+ if $missing; then
3434+ echo "Could not find the cabal configuration directory in any of: ${dirs[@]}" >&2
3535+ exit 101
3636+ fi
3737+fi
3838+1839package_list="$(nix-build -A haskell.package-list)/nixos-hackage-packages.csv"
1919-username=$(grep "^username:" ~/.cabal/config | sed "s/^username: //")
2020-password_command=$(grep "^password-command:" ~/.cabal/config | sed "s/^password-command: //")
4040+username=$(grep "^username:" "$CABAL_DIR/config" | sed "s/^username: //")
4141+password_command=$(grep "^password-command:" "$CABAL_DIR/config" | sed "s/^password-command: //")
2142curl -u "$username:$($password_command | head -n1)" --digest -H "Content-type: text/csv" -T "$package_list" http://hackage.haskell.org/distro/NixOS/packages.csv
2243echo