1#! /usr/bin/env nix-shell
2#! nix-shell -i bash -p nix curl gnused -I nixpkgs=.
3
4# On Hackage every package description shows a category "Distributions" which
5# lists a "NixOS" version.
6# This script uploads a csv to hackage which will update the displayed versions
7# based on the current versions in nixpkgs. This happens with a simple http
8# request.
9
10# For authorization you just need to have any valid hackage account. This
11# script uses the `username` and `password-command` field from your
12# ~/.cabal/config file.
13
14# e.g. username: maralorn
15# 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.)
16# Those fields are specified under `upload` on the `cabal` man page.
17
18if test -z "$CABAL_DIR"; then
19 dirs=(
20 "$HOME/.cabal"
21 "${XDG_CONFIG_HOME:-$HOME/.config}/cabal"
22 )
23 missing=true
24
25 for dir in "${dirs[@]}"; do
26 if test -d "$dir"; then
27 export CABAL_DIR="$dir"
28 missing=false
29 break
30 fi
31 done
32
33 if $missing; then
34 echo "Could not find the cabal configuration directory in any of: ${dirs[@]}" >&2
35 exit 101
36 fi
37fi
38
39package_list="$(nix-build -A haskell.package-list)/nixos-hackage-packages.csv"
40username=$(grep "^username:" "$CABAL_DIR/config" | sed "s/^username: //")
41password_command=$(grep "^password-command:" "$CABAL_DIR/config" | sed "s/^password-command: //")
42curl -u "$username:$($password_command | head -n1)" --digest -H "Content-type: text/csv" -T "$package_list" https://hackage.haskell.org/distro/NixOS/packages.csv
43echo