pantry: Content addressable Haskell package management

[ bsd3, development, library ] [ Propose Tags ] [ Report a vulnerability ]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.1.0, 0.1.1.1, 0.1.1.2, 0.2.0.0, 0.3.0.0, 0.4.0.0, 0.4.0.1, 0.4.0.2, 0.5.0.0, 0.5.1.0, 0.5.1.1, 0.5.1.2, 0.5.1.3, 0.5.1.4, 0.5.1.5, 0.5.2, 0.5.2.1, 0.5.2.2, 0.5.2.3, 0.5.3, 0.5.4, 0.5.5, 0.5.6, 0.5.7, 0.6.0, 0.7.0, 0.7.1, 0.8.0, 0.8.1, 0.8.2, 0.8.2.1, 0.8.2.2, 0.8.3, 0.9.0, 0.9.1, 0.9.2, 0.9.3, 0.9.3.1, 0.9.3.2, 0.10.0
Change log ChangeLog.md
Dependencies aeson (>=1.2.4.0 && <1.3 || >=1.3.1.1 && <1.4 || >=1.4.2.0 && <1.5), ansi-terminal (>=0.9 && <0.10), array (>=0.5.2.0 && <0.6), base (>=4.10 && <5), base-orphans (>=0.7 && <0.8 || >=0.8.1 && <0.9), base64-bytestring (>=1.0.0.1 && <1.1), bytestring (>=0.10.8.2 && <0.11), Cabal (>=2.4.0.1 && <2.5), conduit (>=1.3.0.3 && <1.4), conduit-extra (>=1.3.0 && <1.4), containers (>=0.5.10.2 && <0.6 || >=0.6.0.1 && <0.7), contravariant (>=1.4.1 && <1.5 || >=1.5.2 && <1.6), cryptonite (>=0.25 && <0.27), cryptonite-conduit (>=0.2.2 && <0.3), deepseq (>=1.4.3.0 && <1.5), digest (>=0.0.1.2 && <0.1), directory (>=1.3.0.2 && <1.4), filelock (>=0.1.1.2 && <0.2), filepath (>=1.4.1.2 && <1.5), generic-deriving (>=1.12.2 && <1.13), ghc-prim (>=0.5.1.1 && <0.6), hackage-security (>=0.5.3.0 && <0.6), hashable (>=1.2.7.0 && <1.3), hpack (>=0.31.2 && <0.32), http-client (>=0.5.13.1 && <0.7), http-client-tls (>=0.3.5.3 && <0.4), http-conduit (>=2.3.2 && <2.4), http-download (>=0.1.0.0 && <0.2), http-types (>=0.12.1 && <0.13), integer-gmp (>=1.0.1.0 && <1.1), memory (>=0.14.16 && <0.15), mono-traversable (>=1.0.9.0 && <1.1), mtl (>=2.2.2 && <2.3), network (>=2.6.3.6 && <2.7 || >=2.8.0.1 && <2.9), network-uri (>=2.6.1.0 && <2.7), path (>=0.6.1 && <0.7), path-io (>=1.3.3 && <1.4 || >=1.4.2 && <1.5), persistent (>=2.9.2 && <2.10), persistent-sqlite (>=2.9.3 && <2.10), persistent-template (>=2.5.4 && <2.6 || >=2.6.0 && <2.7), primitive (>=0.6.3.0 && <0.7), resourcet (>=1.2.1 && <1.3), rio (>=0.1.9.2 && <0.2), rio-orphans (>=0.1.1.0 && <0.2), rio-prettyprint (>=0.1.0.0 && <0.2), safe (>=0.3.17 && <0.4), syb (>=0.7 && <0.8), tar-conduit (>=0.3.0 && <0.4), template-haskell (>=2.12.0.0 && <2.13 || >=2.13.0.0 && <2.14 || >=2.14.0.0 && <2.15), text (>=1.2.3.0 && <1.3), text-metrics (>=0.3.0 && <0.4), th-lift (>=0.7.10 && <0.8 || >=0.8.0.1 && <0.9), th-lift-instances (>=0.1.11 && <0.2), th-orphans (>=0.13.6 && <0.14), th-reify-many (>=0.1.8 && <0.2), th-utilities (>=0.2.0.1 && <0.3), time (>=1.8.0.2 && <1.9), transformers (>=0.5.2.0 && <0.6), unix-compat (>=0.5.0.1 && <0.6), unliftio (>=0.2.8.0 && <0.3), unordered-containers (>=0.2.9.0 && <0.3), vector (>=0.12.0.1 && <0.13), yaml (>=0.10.4.0 && <0.11 || >=0.11.0.0 && <0.12), zip-archive (>=0.3.3 && <0.4 || >=0.4.1 && <0.5) [details]
License BSD-3-Clause
Copyright 2018-2019 FP Complete
Author Michael Snoyman
Maintainer michael@snoyman.com
Revised Revision 1 made by borsboom at 2019-07-11T19:55:59Z
Category Development
Home page https://github.com/commercialhaskell/stack#readme
Bug tracker https://github.com/commercialhaskell/stack/issues
Source repo head: git clone https://github.com/commercialhaskell/stack
Uploaded by borsboom at 2019-07-11T19:54:03Z
Distributions Arch:0.5.7, Debian:0.4.0.2, Fedora:0.8.3, LTSHaskell:0.9.3.2, NixOS:0.9.3.2, Stackage:0.10.0
Reverse Dependencies 1 direct, 4 indirect [details]
Downloads 18307 total (292 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-07-11 [all 1 reports]

Readme for pantry-0.1.0.0

[back to package description]

pantry

TODO: Add Travis and AppVeyor badges

Content addressable Haskell package management, providing for secure, reproducible acquisition of Haskell package contents and metadata.

What is Pantry

  • A Haskell library, command line executable, storage specification, and network protocol
  • Intended for content-addressable storage of Haskell packages
  • Allows non-centralized package storage
  • Primarily for use by Stackage and Stack, hopefully other tools as well

Goals

  • Efficient, distributed package storage for Haskell
  • Superset of existing storage mechanisms
  • Security via content addressable storage
  • Allow more Stackage-style snapshots to exist
  • Allow authors to bypass Hackage for uploads
  • Allow Stackage to create forks of packages on Hackage

TODO

Content below needs to be updated.

  • Support for hpack in PackageLocationImmutable?

Package definition

Pantry defines the following concepts:

  • Blob: a raw byte sequence, identified by its key (SHA256 of the contents)
  • Tree entry: contents of a single file (identified by blob key) and whether or not it is executable.
    • NOTE: existing package formats like tarballs support more sophisticated options. We explicitly do not support those. If such functionality is needed, fallback to those mechanism is required.
  • Tree: mapping from relative path to a tree entry. Some basic sanity rules apply to the paths: no . or .. directory components, no newlines in filepaths, does not begin with /, no \\ (we normalize to POSIX-style paths). A tree is identified by a tree key (SHA256 of the tree's serialized format).
  • Package: a tree key for the package contents, package name, version number, and cabal file blob key. Requirements: there must be a single file with a .cabal file extension at the root of the tree, and it must match the cabal file blob key. The cabal file must be located at pkgname.cabal. Each tree can be in at most one package, and therefore tree keys work as package keys too.

Note that with the above, a tree key is all the information necessary to uniquely identify a package. However, including additional information (package name, version, cabal key) in config files may be useful for optimizations or user friendliness. If such extra information is ever included, it must be validated to concur with the package contents itself.

Package location

Packages will optionally be sourced from some location:

  • Hackage requires the package name, version number, and revision number. Each revision of a package will end up with a different tree key.
  • Archive takes a URL pointing to a tarball (gzipped or not) or a ZIP file. An implicit assumption is that archives remain immutable over time. Use tree keys to verify this assumption. (Same applies to Hackage for that matter.)
  • Repository takes a repo type (Git or Mercurial), URL, and commit. Assuming the veracity of the cryptographic hashes on the repos, this should guarantee a unique set of files.

In order to deal with megarepos (repos and archives containing more than one package), there is also a subdirectory for the archive and repository cases. An empty subdir "" would be the case for a standard repo/archive.

In order to meet the rules of a package listed above, the following logic is applied to all three types above:

  • Find all of the files in the raw location, and represent as Map FilePath TreeEntry (or equivalent).
  • Remove a wrapper directory. If all filepaths in that Map are contained within the same directory, strip it from all of the paths. For example, if the paths are foo/bar and foo/baz, the paths will be reduced to bar and baz.
  • After this wrapper is removed, then subdirectory logic is applied, essentially applying stripPrefix to the filepaths. If the subdir is yesod-bin and files exist called yesod-core/yesod-core.cabal and yesod-bin/yesod-bin.cabal, the only file remaining after subdir stripping would be yesod-bin.cabal. Note that trailing slashes must be handled appropriately, and that an empty subdir string results in this step being a noop.

The result of all of this is that, given one of the three package locations above, we can receive a tree key which will provide an installable package. That tree key will remain immutable.

How tooling refers to packages

We'll get to the caching mechanism for Pantry below. However, the recommended approach for tooling is to support some kind of composite of the Pantry keys, parsed info, and raw package location. This allows for more efficient lookups when available, with a fallback when mirrors don't have the needed information.

An example:

extra-deps:
- name: foobar
  version: 1.2.3.4
  pantry: deadbeef # tree key
  cabal-file: 12345678 # blob key
  archive: https://example.com/foobar-1.2.3.4.tar.gz

It is also recommended that tooling provide an easy way to generate such complete information from, e.g., just the URL of the tarball, and that upon reading information, hashes, package names, and version numbers are all checked for correctness.

Pantry caching

One simplistic option for Pantry would be that, every time a piece of data is needed, Pantry downloads the necessary tarball/Git repo/etc. However, this would in practice be highly wasteful, since downloading Git repos and archives just to get a single cabal file (for plan construction purposes) is overkill. Instead, here's the basic idea for how caching works:

  • All data for Pantry can be stored in a SQL database. Local tools like Stack will use an SQLite database. Servers will use PostgreSQL.
  • We'll define a network protocol (initially just HTTP, maybe extending to something more efficient if desired) for querying blobs and trees.
  • When a blob or tree is needed, it is first checked for in the local SQLite cache. If it's not available there, a request to the Pantry mirrors (configurable) will be made for the data. Since everything is content addressable, it is safe to use untrusted mirrors.
  • If the data is not available in a mirror, and a location is provided, the location will be downloaded and cached locally.

We may also allow these Pantry mirrors to provide some kind of query interface to find out, e.g., the latest version of a package on Hackage. That's still TBD.

Example: resolving a package location

To work through a full example, the following three stanzas are intended to have equivalent behavior:

- archive: https://example.com/foobar-1.2.3.4.tar.gz

- name: foobar
  version: 1.2.3.4
  pantry: deadbeef # tree key
  cabal-file: 12345678 # blob key
  archive: https://example.com/foobar-1.2.3.4.tar.gz

- pantry: deadbeef

The question is: how does the first one (presumably what a user would want to enter) be resolved into the second and third? Pantry would follow this set of steps:

  • Download the tarball from the given URL
  • Place each file in the tarball into its store as a blob, getting a blob key for each. The tarball is now represented as Map FilePath BlobKey
  • Perform the root directory stripping step, removing a shared path
  • Since there's no subdirectory: no subdirectory stripping would be performed
  • Serialize the Map FilePath BlobKey to a binary format and take its hash to get a tree key
  • Store the tree in the store referenced by its tree key. In our example: the tree key is deadbeef.
  • Ensure that the tree is a valid package by checking for a single cabal file at the root. In our example, that's found in foobar.cabal with blob key 12345678.
  • Parse the cabal file and ensure that it is a valid cabal file, and that its package name is foobar. Grab the version number (1.2.3.4).
  • We now know that tree key deadbeef is a valid package, and can refer to it by tree key exclusively. However, including the other information allows us to verify our assumptions, provide user-friendly readable data, and provide a fallback if the package isn't in the Pantry cache.

More advanced content discovery

There are three more advanced cases to consider:

  • Providing fall-back locations for content, such as out of concern for a single URL being removed in the future
  • Closed corporate setups, where access to the general internet may either be impossible or undesirable
  • Automatic discovery of missing content by hash

The following extensions are possible to address these cases:

  • Instead of a single package location, provide a list of package locations with fallback semantics.
  • Corporate environments will be encouraged to run a local Pantry mirror, and configure clients like Stack to speak to these mirrors instead of the default ones (or in addition to).
  • Provide some kind of federation protocol for Pantry where servers can registry with each other and requests for content can be pinged to each other.

Providing override at the client level for Pantry mirror locations is a MUST. Making it easy to run in a corporate environment is a SHOULD. Providing the fallback package locations seems easy enough that we should include it initially, but falls under a SHOULD. The federated protocol should be added on-demand.