Saturday, May 14, 2022

Stack

  • basic concept (from link)
    • ghc only knows about packages that are installed. Installed packages live in package databases
    • ghc-pkg is package tool from ghc and ghc know two database
      • database is a directory, usually called package.conf.d, that contains a file for each package, together with a binary cache of the package data in the file package.cache
      • global package database, which comes with your GHC installation, e.g. /usr/lib/ghc-6.12.1/package.conf.d.
      • user package database private to each user, e.g. $XDG_DATA_HOME/ghc/arch-os-version/package.conf.
    • LTS is may also not incomplete
      • While we assume in general that LTS snapshots never change, there's nothing that technically prohibits that from happening. Instead, the complete version of that field is
        resolver:  size: 496662
          url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/13/9.yaml
          sha256: 83de9017d911cf7795f19353dba4d04bd24cd40622b7567ff61fc3f7223aa3ea
  • package in stack.yaml and package.yaml
    • package.yaml:
      • dependencies: package in LTS
    • stack.yaml
      • packages  : local package in local computer
      • extra-deps: package from upstreams
    • information in these two yaml just tells stack which packages are needed. Then stack download package and register them through ghc-pkg
    • database name is decided by hash of snapshot and extra-deps
      • .stack/snapshots/x86_64-linux-tinfo6/  => 02ca0c488465697d85d7ca7acaae14ad5743f138dce267e2ea1b93bd8c3bb3ab
    • stack install xx will update local database and register xx package with ghc-pkg database, then these ghci could import these modules
    • but database name may change if xx is new package in extra-deps
  • global ghci: stack ghci out of any haskell program folder
    • ~/.stack/global-project/stack.yaml
    • package.yaml, cabal.project, global-project.cabal doesn't work
  • stack exec (from link)
    • The only issue is how to distinguish flags to be passed to stack versus those for the underlying program. Thanks to the optparse-applicative library, stack follows the Unix convention of -- to separate these, e.g.:
    • stack exec --package stm -- echo I installed the stm package via --package stm
    • "--package foo" can be used to force a package to be installed before running the given command