简体   繁体   中英

How to use the Tsinghua mirrors of Hackage and Stackage with Haskell Stack package manager

I'm using version 2.1.1 of the Haskell Stack package manager.

Tsinghua University provides a mirror of Hackage that is available behind the Chinese firewall, as described on https://mirrors.tuna.tsinghua.edu.cn/help/hackage/ .

When I follow those instructions, however, adding

package-indices:
  - name: Tsinghua
    download-prefix: http://mirrors.tuna.tsinghua.edu.cn/hackage/package/
    http: http://mirrors.tuna.tsinghua.edu.cn/hackage/00-index.tar.gz
    hackage-security:
        keyids:
        - 0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d
        - 1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42
        - 280b10153a522681163658cb49f632cde3f38d768b736ddbc901d99a1a772833
        - 2a96b1889dc221c17296fcc2bb34b908ca9734376f0f361660200935916ef201
        - 2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3
        - 51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921
        - 772e9f4c7db33d251d5c6e357199c819e569d130857dc225549b40845ff0890d
        - aa315286e6ad281ad61182235533c41e806e5a787e0b6d1e7eef3f09d137d2e9
        - fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0
        key-threshold: 3 # number of keys required

        # ignore expiration date, see https://github.com/commercialhaskell/stack/pull/4614
        ignore-expiry: yes

to ~/.stack/config.yml, then when I run stack run in my project directory, I see:

Cabal file info not found for aeson-1.4.2.0@sha256:8166752a9669597db375343df19805069595fed9c613f98504e418849f40fe18,7007, updating Selected mirror http://mirrors.tuna.tsinghua.edu.cn/hackage/package/ Downloading root Could not deserialize /root.json: Malformed: (line 1, column 1): unexpected "<" expecting white space or JSON value

It also has a Stackage mirror; I tried adding changing the Stackage resolver by adding resolver: https://mirrors.tuna.tsinghua.edu.cn/stackage/lts-haskell/lts-13.25.yaml to the stack.yaml for my project, but that fails with:

Exception while reading snapshot from https://mirrors.tuna.tsinghua.edu.cn/stackage/lts-haskell/lts-13.25.yaml : Couldn't parse snapshot from https://mirrors.tuna.tsinghua.edu.cn/stackage/lts-haskell/lts-13.25.yaml : Error in $: Snapshot must have either resolver or compiler

My project is just a default project created with stack new myProjectName , and the only other config change I've made is adding

setup-info: "http://mirrors.tuna.tsinghua.edu.cn/stackage/stack-setup.yaml"
urls:
  latest-snapshot: http://mirrors.tuna.tsinghua.edu.cn/stackage/snapshots.json
  lts-build-plans: http://mirrors.tuna.tsinghua.edu.cn/stackage/lts-haskell/
  nightly-build-plans: http://mirrors.tuna.tsinghua.edu.cn/stackage/stackage-nightly/  

to ~/.stack/config.yaml as suggested on https://mirrors.tuna.tsinghua.edu.cn/help/stackage/ . That allowed me to download GHC from that mirror, but doesn't seem to enable pulling packages from there.

What is the recommended way to make Stackage/Hackage (whatever is used by stack (build|run) ) use the Tsinghua mirror? Ideally I don't want anything to be pulled from the default AWS mirror.

I found a solution of sorts: https://github.com/commercialhaskell/stack/issues/4866 and https://github.com/commercialhaskell/stack/issues/4870 . Seems Slack 2 deprecated the package format it previously used, which is the format the Tsinghua mirror uses, so Stack 2 doesn't support the mirror. The solution is to use pre-2.0 Slack or switch to Cabal.

[ Updated Jan 2021 ]

Tsinghua University has updated their guide on how to adapt to Stackage >= v2.1.1.

To save you a few clicks:

# ADD THESE LINES TO `~/.stack/config.yaml`

package-indices:
  - download-prefix: http://mirrors.tuna.tsinghua.edu.cn/hackage/
    hackage-security:
        keyids:
        - 0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d
        - 1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42
        - 280b10153a522681163658cb49f632cde3f38d768b736ddbc901d99a1a772833
        - 2a96b1889dc221c17296fcc2bb34b908ca9734376f0f361660200935916ef201
        - 2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3
        - 51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921
        - 772e9f4c7db33d251d5c6e357199c819e569d130857dc225549b40845ff0890d
        - aa315286e6ad281ad61182235533c41e806e5a787e0b6d1e7eef3f09d137d2e9
        - fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0
        key-threshold: 3 # number of keys required

        # ignore expiration date, see https://github.com/commercialhaskell/stack/pull/4614
        ignore-expiry: no

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM