-
Notifications
You must be signed in to change notification settings - Fork 0
/
2024-03-14-hackage-revisions-in-nix.html
90 lines (81 loc) · 5.36 KB
/
2024-03-14-hackage-revisions-in-nix.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="alternate"
type="application/rss+xml"
href="https://magnus.therning.org/feed.xml"
title="RSS feed for https://magnus.therning.org/">
<title>Hackage revisions in Nix</title>
<meta name="author" content="Magnus Therning"><meta name="referrer" content="no-referrer"><link href= "static/style.css" rel="stylesheet" type="text/css" /><link href= "static/htmlize.css" rel="stylesheet" type="text/css" /><link href= "static/extra_style.css" rel="stylesheet" type="text/css" /></head>
<body>
<div id="preamble" class="status"><div class="nav-bar"><a class="nav-link" href="./index.html">Top</a><a class="nav-link" href="./archive.html">Archive</a><a class="nav-link align-right" href="./feed.xml"><img src="static/rss-feed-icon.png" style="height: 24px;" /></a></div></div>
<div id="content">
<div class="post-date">14 Mar 2024</div><h1 class="post-title"><a href="https://magnus.therning.org/2024-03-14-hackage-revisions-in-nix.html">Hackage revisions in Nix</a></h1>
<p>
Today I got very confused when using <code>callHackageDirect</code> to add the <code>openapi3</code>
package gave me errors like this
</p>
<pre class="example" id="org957ddd8">
> Using Parsec parser
> Configuring openapi3-3.2.3...
> CallStack (from HasCallStack):
> withMetadata, called at libraries/Cabal/Cabal/src/Distribution/Simple/Ut...
> Error: Setup: Encountered missing or private dependencies:
> base >=4.11.1.0 && <4.18,
> base-compat-batteries >=0.11.1 && <0.13,
> template-haskell >=2.13.0.0 && <2.20
</pre>
<p>
When looking at its <a href="https://hackage.haskell.org/package/openapi3-3.2.3">entry on Hackage</a> those weren't the version ranges for the
dependencies. Also, running <code>ghc-pkg list</code> told me that I already had all
required packages at versions matching what Hackage said. So, what's actually
happening here?
</p>
<p>
It took me a while before remembering about <a href="https://hackage.haskell.org/package/openapi3-3.2.3/revisions/">revisions</a> but once I did it was
clear that <code>callHackageDirect</code> always fetches the initial revision of a package
(i.e. it fetches the original tar-ball uploaded by the author). After realising
this it makes perfect sense – it's the only revision that's guaranteed to be
there and won't change. However, it would be very useful to be able to pick a
revision that actually builds.
</p>
<p>
I'm not the first one to find this, of course. It's been noted and written about
on the <a href="https://discourse.nixos.org/t/watch-out-hackage-revisions/14588">discource</a> several years ago. What I didn't find though was a way to
influence what revision that's picked. It took a bit of rummaging around in the
<code>nixpkgs</code> code but finally I found two variables that's used in the Hackage
derivation to control this
</p>
<ul class="org-ul">
<li><code>revision</code> - a string with the number of the revision, and</li>
<li><code>editedCabalFile</code> - the SHA256 of the modified Cabal file.</li>
</ul>
<p>
Setting them is done using the <code>overrideCabal</code> function. This is a piece of my
setup for a modified set of Haskell packages:
</p>
<div class="org-src-container">
<pre class="src src-nix"><span class="org-nix-attribute">hl</span> = nixpkgs.haskell.lib.compose;
<span class="org-nix-attribute">hsPkgs</span> = nixpkgs.haskell.packages.ghc963.override <span class="org-rainbow-delimiters-depth-1">{</span>
<span class="org-nix-attribute">overrides</span> = newpkgs: oldpkgs: <span class="org-rainbow-delimiters-depth-2">{</span>
<span class="org-nix-attribute">openapi3</span> = hl.overrideCabal <span class="org-rainbow-delimiters-depth-3">(</span>drv: <span class="org-rainbow-delimiters-depth-4">{</span>
<span class="org-nix-attribute">revision</span> = <span class="org-string">"4"</span>;
<span class="org-nix-attribute">editedCabalFile</span> =
<span class="org-string">"sha256-a5C58iYrL7eAEHCzinICiJpbNTGwiOFFAYik28et7fI="</span>;
<span class="org-rainbow-delimiters-depth-4">}</span><span class="org-rainbow-delimiters-depth-3">)</span> <span class="org-rainbow-delimiters-depth-3">(</span>oldpkgs.callHackageDirect <span class="org-rainbow-delimiters-depth-4">{</span>
<span class="org-nix-attribute">pkg</span> = <span class="org-string">"openapi3"</span>;
<span class="org-nix-attribute">ver</span> = <span class="org-string">"3.2.3"</span>;
<span class="org-nix-attribute">sha256</span> = <span class="org-string">"sha256-0F16o3oqOB5ri6KBdPFEFHB4dv1z+Pw6E5f1rwkqwi8="</span>;
<span class="org-rainbow-delimiters-depth-4">}</span> <span class="org-rainbow-delimiters-depth-4">{</span> <span class="org-rainbow-delimiters-depth-4">}</span><span class="org-rainbow-delimiters-depth-3">)</span>;
</pre>
</div>
<p>
It's not very ergonomic, and I think an extended version of <code>callHackageDirect</code>
would make sense.
</p>
<div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-haskell.html">haskell</a> <a href="https://magnus.therning.org/tag-nix.html">nix</a> </div>
<div id="comments">Comment <a href=mailto:[email protected]?subject=Comment%20on%20INSERT%20POST%20URL%20HERE>here</a>.</div></div>
<div id="postamble" class="status"><!-- org-static-blog-page-postamble --></div>
</body>
</html>