Files
haskell.nix/docs/tutorials/source-repository-hashes.md
T
Toon Nolten 5c4a0de2a1 Minor documentation fixes (#722)
* Make the haskell.nix import in the examples explicit

The examples used `import ./. {}` without explaining the commands should
be run from the haskell.nix repo root. To avoid confusion like this I
added fetching a tarball of the repo. This is less efficient when run
from the repo but works when run from anywhere and makes it clear we're
importing haskell.nix.

Added a couple urls and removed the urls on the lens component so as not
to confuse components with packages.

* Fix rephrase

The phrasing was left in a partially-rewritten state.

* Change wording and fix typo

* Minor fixes for consistency
2020-06-23 08:10:41 +10:00

2.3 KiB

Handling git repositories in projects

Both stack.yaml and cabal.project files can contain references to git repositories containing the version of a particular package that we wish to use. This is mostly handled automatically by nix-tools and haskell.nix however when we want to use a nix system that is configured to use restricted mode (typically hydra) it will need an aditionaly hash.

When using project, cabalProject or stackProject functions you can include the hash needed in a comment.

To calculate the hash use nix-prefetch-git:

$ nix-prefetch-git https://github.com/input-output-hk/haskell.nix.git bc01ebc05a8105035c9449943046b46c8364b932
...
{
  "url": "https://github.com/input-output-hk/haskell.nix.git",
  "rev": "bc01ebc05a8105035c9449943046b46c8364b932",
  "date": "2019-05-30T13:13:18+08:00",
  "sha256": "003lm3pm024vhbfmii7xcdd9v2rczpflxf7gdl2pyxia7p014i8z",
  "fetchSubmodules": false
}

Cabal.project

Add a --sha256 comment to the cabal.project file:

source-repository-package
  type: git
  location: https://github.com/input-output-hk/haskell.nix.git
  tag: bc01ebc05a8105035c9449943046b46c8364b932
  subdir: test/cabal-simple
  --sha256: 003lm3pm024vhbfmii7xcdd9v2rczpflxf7gdl2pyxia7p014i8z

Stack

Add a # nix-sha256 comment to the stack.yaml file:

extra-deps:
- git: https://github.com/input-output-hk/haskell.nix.git
  commit: bc01ebc05a8105035c9449943046b46c8364b932
  subdirs:
    - test/cabal-simple
  # nix-sha256: 003lm3pm024vhbfmii7xcdd9v2rczpflxf7gdl2pyxia7p014i8z

Avoiding modifying cabal.project and stack.yaml

In some cases we cannot modify the cabal.project or stack.yaml file to add sha256 comments. As an alternative we can pass in a sha256map. For instance, pandoc includes a cabal.project file on hackage which includes a source-repository-package stanza for pandoc-citeproc:

{ haskell-nix, testSrc } :
let
  pandoc = haskell-nix.hackage-package {
    name         = "pandoc";
    version      = "2.9.2.1";
    index-state  = "2020-04-15T00:00:00Z"; 
    # Function that returns a sha256 string by looking up the location
    # and tag in a nested attrset
    sha256map =
      { "https://github.com/jgm/pandoc-citeproc"."0.17"
          = "0dxx8cp2xndpw3jwiawch2dkrkp15mil7pyx7dvd810pwc22pm2q"; };
  };
in
  pandoc.components.exes.pandoc