Search code examples
haskellcabal

how to revert cabal update on a different computer


I needed to compile a Haskell program an machine A which failed (for the cryptonite bug, which is not the issue here) but compiled on machine B. The difference was, that I had run cabal update on A but not on B recently. I was compiling with an older state of hackage on B than on A.

To fix the issue I need to

task 1: see which state of hackage I have on B.

task 2: force a cabal update to the same state on A.

I tried to find the required commands with cabal update -h and with search on the web, but could not identify them (and had to revert to use stack lts to progress).

what are the commands for task 1 and 2? with these commands, I could use cabal in a more controlled way and avoid surprises when some package in hackage breaks.

I am using linux (Debian 5.10.179-1 Debian 5.10.179-1) with

cabal --version
cabal-install version 3.6.2.0
compiled using version 3.6.2.0 of the Cabal library 

Solution

  • While I don't know of a command to specifically query the timestamp, there are a few ways of getting cabal to display it. The least invasive one is possibly using cabal list with verbose output:

    $ cabal -v --installed list base
    Reading available packages of hackage.haskell.org...
    Using historical state as of 2022-12-25T11:36:12Z specified from most recent
    cabal update
    index-state(hackage.haskell.org) = 2022-12-25T11:36:12Z (HEAD =
    2023-06-08T09:48:09Z)
    * base
        Synopsis: Basic libraries
        Default available version: 4.17.0.0
        Installed versions: 4.17.0.0
        License:  BSD-3-Clause
    

    Once you have the desired timestamp, you can specify it when using cabal update in the other computer:

    $ cabal update 'hackage.haskell.org,2022-12-25T11:36:12Z'
    Downloading the latest package list from hackage.haskell.org
    Package list of hackage.haskell.org is up to date.
    The index-state is set to 2022-12-25T11:36:12Z.
    To revert to previous state run:
        cabal v2-update 'hackage.haskell.org,2023-06-08T09:48:09Z'
    

    Since cabal update prints the old index timestamp, another option to find the timestamp would be updating, jotting down the old timestamp, and immediately reverting it. That's a bit more of a hassle than a read-only method, though.