on e94de40 help sign in
haskell.nix/docs/tutorials/source-repository-hashes.md
75 lines 2.4 kB history raw
1# Handling git repositories in projects
3Both `stack.yaml` and `cabal.project` files can contain references
4to git repositories containing the version of a particular package
5that we wish to use. This is mostly handled automatically by
6`nix-tools` and `haskell.nix` however when we want to use a nix
7system that is configured to use restricted mode (typically hydra)
8it will need additional hashes for the referenced repositories.
10When using `project`, `cabalProject` or `stackProject` functions
11you can include the hash needed in a comment.
13To calculate the hash use `nix-prefetch-git`:
15```
16$ nix-prefetch-git https://github.com/input-output-hk/haskell.nix.git bc01ebc05a8105035c9449943046b46c8364b932
17...
19 "url": "https://github.com/input-output-hk/haskell.nix.git",
20 "rev": "bc01ebc05a8105035c9449943046b46c8364b932",
21 "date": "2019-05-30T13:13:18+08:00",
22 "sha256": "003lm3pm024vhbfmii7xcdd9v2rczpflxf7gdl2pyxia7p014i8z",
23 "fetchSubmodules": false
25```
27## Cabal.project
29Add a `--sha256` comment to the `cabal.project` file:
31```
32source-repository-package
33 type: git
34 location: https://github.com/input-output-hk/haskell.nix.git
35 tag: bc01ebc05a8105035c9449943046b46c8364b932
36 subdir: test/cabal-simple
37 --sha256: 003lm3pm024vhbfmii7xcdd9v2rczpflxf7gdl2pyxia7p014i8z
38```
40## Stack
42Add a `# nix-sha256` comment to the `stack.yaml` file:
44```
45extra-deps:
46- git: https://github.com/input-output-hk/haskell.nix.git
47 commit: bc01ebc05a8105035c9449943046b46c8364b932
48 subdirs:
49 - test/cabal-simple
50 # nix-sha256: 003lm3pm024vhbfmii7xcdd9v2rczpflxf7gdl2pyxia7p014i8z
51```
53## Avoiding modifying cabal.project and stack.yaml
55In some cases we cannot modify the `cabal.project` or `stack.yaml` file to add
56sha256 comments. As an alternative we can pass in a `sha256map`. For instance,
57pandoc includes a `cabal.project` file on hackage which includes a
58`source-repository-package` stanza for `pandoc-citeproc`:
60```nix
61{ haskell-nix, testSrc } :
62let
63 pandoc = haskell-nix.hackage-package {
64 name = "pandoc";
65 version = "2.9.2.1";
66 index-state = "2020-04-15T00:00:00Z";
67 # Function that returns a sha256 string by looking up the location
68 # and tag in a nested attrset
69 sha256map =
70 { "https://github.com/jgm/pandoc-citeproc"."0.17"
71 = "0dxx8cp2xndpw3jwiawch2dkrkp15mil7pyx7dvd810pwc22pm2q"; };
72 };
73in
74 pandoc.components.exes.pandoc
75```