@@ -39,11 +39,11 @@ Lets say we want to build `hlint`. We might start with an `hlint`
3939file that looks like this:
4040
4141```nix
42−let inherit (import ./. {}) sources nixpkgsArgs;
42+let inherit (import ./. {}) sources nixpkgsArgs;
4343 pkgs = import sources.nixpkgs-default nixpkgsArgs;
4444 hlint = pkgs.haskell-nix.hackage-package {
4545 name = "hlint";
46− version = "2.2.4";
46+ version = "2.2.11";
4747 };
4848in hlint.components.exes.hlint
4949```
@@ -52,10 +52,10 @@ Building this may result in a lot of output, but if you build
5252it again it should give just:
5353
5454```
55−$ nix-build hlint.nix
55+$ nix-build hlint.nix
5656trace: Using latest index state for hlint!
57−trace: Using index-state: 2019-12-09T00:00:00Z for hlint
58−/nix/store/7wwqq5v42gm6iiz2d3ngbnkyw7i4py11-hlint-2.2.4-exe-hlint
57+trace: Using index-state: 2020-04-15T00:00:00Z for hlint
58+/nix/store/rnfz66v7k8i38c8rsmchzsyqjrmrbdpk-hlint-2.2.11-exe-hlint
5959```
6060
6161To materialize the nix files we need to take care to pin down the
@@ -63,12 +63,12 @@ inputs. For `cabalProject` and `hackage-package` this means
6363we must specify the `index-state` of hackage we want to use:
6464
6565```nix
66−let inherit (import ./. {}) sources nixpkgsArgs;
67− pkgs = import sources.nixpkgs-default nixpkgsArgs;
66+let inherit (import ./. {}) sources nixpkgsArgs;
67+ pkgs = import sources.nixpkgs-default nixpkgsArgs;
6868 hlint = pkgs.haskell-nix.hackage-package {
6969 name = "hlint";
70− version = "2.2.4";
71− index-state = "2019-12-03T00:00:00Z";
70+ version = "2.2.11";
71+ index-state = "2020-04-15T00:00:00Z";
7272 };
7373in hlint.components.exes.hlint
7474```
@@ -78,26 +78,26 @@ calculate a suitable sha256 hash to turn the derivation
7878containing the nix files into a fixed output derivation:
7979
8080```
81−$ nix-build hlint.nix
82−trace: Using index-state: 2019-12-03T00:00:00Z for hlint
83−trace: Get `plan-sha256` with `nix-hash --base32 --type sha256 /nix/store/qk1fvza1alkvs51vzmpjp2xsg8xklyxk-hlint-plan-to-nix-pkgs/`
84−/nix/store/7wwqq5v42gm6iiz2d3ngbnkyw7i4py11-hlint-2.2.4-exe-hlint
81+$ nix-build hlint.nix
82+trace: Using index-state: 2020-04-15T00:00:00Z for hlint
83+trace: Get `plan-sha256` with `nix-hash --base32 --type sha256 /nix/store/8z6p4237rin3c6c1lmjwshmj8rdqrhw2-hlint-plan-to-nix-pkgs/`
84+/nix/store/rnfz66v7k8i38c8rsmchzsyqjrmrbdpk-hlint-2.2.11-exe-hlint
8585
86−$ nix-hash --base32 --type sha256 /nix/store/qk1fvza1alkvs51vzmpjp2xsg8xklyxk-hlint-plan-to-nix-pkgs/
87−1a4rhv3h2daz6dzwzfl3w7l1v556n7aqfiagw6m0rvqq230iabss
86+$ nix-hash --base32 --type sha256 /nix/store/8z6p4237rin3c6c1lmjwshmj8rdqrhw2-hlint-plan-to-nix-pkgs/
87+02hasr27a994sml1fzf8swb716lm6lgixxr53y0gxkhw437xkck4
8888```
8989
9090We can add the hash as `plan-sha256` or (`stack-sha256` for
9191`stackProject`)
9292
9393```nix
94−let inherit (import ./. {}) sources nixpkgsArgs;
95− pkgs = import sources.nixpkgs-default nixpkgsArgs;
94+let inherit (import ./. {}) sources nixpkgsArgs;
95+ pkgs = import sources.nixpkgs-default nixpkgsArgs;
9696 hlint = pkgs.haskell-nix.hackage-package {
9797 name = "hlint";
98− version = "2.2.4";
99− index-state = "2019-12-03T00:00:00Z";
100− plan-sha256 = "1a4rhv3h2daz6dzwzfl3w7l1v556n7aqfiagw6m0rvqq230iabss";
98+ version = "2.2.11";
99+ index-state = "2020-04-15T00:00:00Z";
100+ plan-sha256 = "02hasr27a994sml1fzf8swb716lm6lgixxr53y0gxkhw437xkck4";
101101 };
102102in hlint.components.exes.hlint
103103```
@@ -111,22 +111,22 @@ to wait while they are built or downloaded.
111111Running nix build again gives us a hint on what we can do next:
112112
113113```
114−$ nix-build hlint.nix
115−trace: Using index-state: 2019-12-03T00:00:00Z for hlint
116−trace: To materialize, point `materialized` to a copy of /nix/store/0xalcphb7ifvy5fc9dpwj40fij6nn5av-hlint-plan-to-nix-pkgs
117−/nix/store/7wwqq5v42gm6iiz2d3ngbnkyw7i4py11-hlint-2.2.4-exe-hlint
114+$ nix-build hlint.nix
115+trace: Using index-state: 2020-04-15T00:00:00Z for hlint
116+trace: To materialize, point `materialized` to a copy of /nix/store/kk047cqsjvbj4w8psv4l05abdcnyrqdc-hlint-plan-to-nix-pkgs
117+/nix/store/rnfz66v7k8i38c8rsmchzsyqjrmrbdpk-hlint-2.2.11-exe-hlint
118118```
119119
120120To capture the nix we can do something like:
121121
122122```nix
123−let inherit (import ./. {}) sources nixpkgsArgs;
124− pkgs = import sources.nixpkgs-default nixpkgsArgs;
123+let inherit (import ./. {}) sources nixpkgsArgs;
124+ pkgs = import sources.nixpkgs-default nixpkgsArgs;
125125 hlint = pkgs.haskell-nix.hackage-package {
126126 name = "hlint";
127− version = "2.2.4";
128− index-state = "2019-12-03T00:00:00Z";
129− plan-sha256 = "1a4rhv3h2daz6dzwzfl3w7l1v556n7aqfiagw6m0rvqq230iabss";
127+ version = "2.2.11";
128+ index-state = "2020-04-15T00:00:00Z";
129+ plan-sha256 = "02hasr27a994sml1fzf8swb716lm6lgixxr53y0gxkhw437xkck4";
130130 materialized = ./hlint.materialized;
131131 };
132132in hlint.components.exes.hlint
@@ -135,9 +135,9 @@ in hlint.components.exes.hlint
135135Now we can copy the nix files needed and build with:
136136
137137```
138−$ cp -r /nix/store/0xalcphb7ifvy5fc9dpwj40fij6nn5av-hlint-plan-to-nix-pkgs hlint.materialized
139−$ nix-build hlint.nix
140−/nix/store/7wwqq5v42gm6iiz2d3ngbnkyw7i4py11-hlint-2.2.4-exe-hlint
138+$ cp -r /nix/store/8z6p4237rin3c6c1lmjwshmj8rdqrhw2-hlint-plan-to-nix-pkgs hlint.materialized
139+$ nix-build hlint.nix
140+/nix/store/rnfz66v7k8i38c8rsmchzsyqjrmrbdpk-hlint-2.2.11-exe-hlint
141141```
142142
143143We may want to run `chmod -R +w hlint.materialized` as the files copied from the
@@ -145,74 +145,44 @@ store will be read only.
145145
146146## How can we check `sha256` and `materialized` are up to date?
147147
148−Let's pretend we had to go back to `hlint` version `2.2.3`.
149−We can change `version` and temporarily add
150−`checkMaterialization = true;`:
148+Let's pretend we had to go back to `hlint` version `2.2.10`.
149+We can tell haskell.nix to check the materialiazation either by:
150+
151+* Removing the materialization files with `rm -rf hlint.materialized`
152+* Temporarily adding `checkMaterialization = true;`
153+
154+If we choose to add the `checkMaterialization` flag you would have:
151155
152156```nix
153−let inherit (import ./. {}) sources nixpkgsArgs;
154− pkgs = import sources.nixpkgs-default nixpkgsArgs;
157+let inherit (import ./. {}) sources nixpkgsArgs;
158+ pkgs = import sources.nixpkgs-default nixpkgsArgs;
155159 hlint = pkgs.haskell-nix.hackage-package {
156160 name = "hlint";
157− version = "2.2.4";
158− index-state = "2019-12-03T00:00:00Z";
159− plan-sha256 = "1a4rhv3h2daz6dzwzfl3w7l1v556n7aqfiagw6m0rvqq230iabss";
161+ version = "2.2.10";
162+ index-state = "2020-04-15T00:00:00Z";
163+ plan-sha256 = "02hasr27a994sml1fzf8swb716lm6lgixxr53y0gxkhw437xkck4";
160164 materialized = ./hlint.materialized;
161165 checkMaterialization = true;
162166 };
163167in hlint.components.exes.hlint
164168```
165169
166−This will fail and report the details of what is wrong:
170+This will fail and report the details of what is wrong and how to fix it:
167171
168172```
169−$ nix-build hlint.nix
170−trace: Using index-state: 2019-12-03T00:00:00Z for hlint
171−building '/nix/store/zmif4gk52ynh57pf4dikzgsk30haqi2b-hlint-plan-to-nix-pkgs.drv'...
172−Changes to hlint-plan-to-nix-pkgs not reflected in plan-sha256
173−diff -ru /nix/store/0xalcphb7ifvy5fc9dpwj40fij6nn5av-hlint-plan-to-nix-pkgs/.plan.nix/hlint.nix /nix/store/h5j8k3y5lansyfss25gd7knbninzr6z4-hlint-plan-to-nix-pkgs/.plan.nix/hlint.nix
174−--- /nix/store/0xalcphb7ifvy5fc9dpwj40fij6nn5av-hlint-plan-to-nix-pkgs/.plan.nix/hlint.nix 1970-01-01 00:00:01.000000000 +0000
175−+++ /nix/store/h5j8k3y5lansyfss25gd7knbninzr6z4-hlint-plan-to-nix-pkgs/.plan.nix/hlint.nix 1970-01-01 00:00:01.000000000 +0000
176−@@ -42,7 +42,7 @@
177− flags = { threaded = true; gpl = true; ghc-lib = false; };
178− package = {
179− specVersion = "1.18";
180−- identifier = { name = "hlint"; version = "2.2.4"; };
181−+ identifier = { name = "hlint"; version = "2.2.3"; };
182− license = "BSD-3-Clause";
183− copyright = "Neil Mitchell 2006-2019";
184− maintainer = "Neil Mitchell <ndmitchell@gmail.com>";
185−@@ -95,7 +95,6 @@
186− (hsPkgs."extra" or (buildDepError "extra"))
187− (hsPkgs."refact" or (buildDepError "refact"))
188− (hsPkgs."aeson" or (buildDepError "aeson"))
189−- (hsPkgs."filepattern" or (buildDepError "filepattern"))
190− (hsPkgs."syb" or (buildDepError "syb"))
191− (hsPkgs."mtl" or (buildDepError "mtl"))
192− ] ++ (if !flags.ghc-lib && (compiler.isGhc && (compiler.version).ge "8.8.0") && (compiler.isGhc && (compiler.version).lt "8.9.0")
193−diff -ru /nix/store/0xalcphb7ifvy5fc9dpwj40fij6nn5av-hlint-plan-to-nix-pkgs/default.nix /nix/store/h5j8k3y5lansyfss25gd7knbninzr6z4-hlint-plan-to-nix-pkgs/default.nix
194−--- /nix/store/0xalcphb7ifvy5fc9dpwj40fij6nn5av-hlint-plan-to-nix-pkgs/default.nix 1970-01-01 00:00:01.000000000 +0000
195−+++ /nix/store/h5j8k3y5lansyfss25gd7knbninzr6z4-hlint-plan-to-nix-pkgs/default.nix 1970-01-01 00:00:01.000000000 +0000
196−@@ -76,7 +76,7 @@
197− "tagged".revision = (((hackage."tagged")."0.8.6").revisions).default;
198− "tagged".flags.transformers = true;
199− "tagged".flags.deepseq = true;
200−- "haskell-src-exts".revision = (((hackage."haskell-src-exts")."1.22.0").revisions).default;
201−+ "haskell-src-exts".revision = (((hackage."haskell-src-exts")."1.21.1").revisions).default;
202− "unliftio-core".revision = (((hackage."unliftio-core")."0.1.2.0").revisions).default;
203− "ghc-lib-parser".revision = (((hackage."ghc-lib-parser")."8.8.1").revisions).default;
204− "containers".revision = (((hackage."containers")."0.6.0.1").revisions).default;
205−@@ -116,7 +116,6 @@
206− "hpc".revision = (((hackage."hpc")."0.6.0.3").revisions).default;
207− "filepath".revision = (((hackage."filepath")."1.4.2.1").revisions).default;
208− "process".revision = (((hackage."process")."1.6.5.0").revisions).default;
209−- "filepattern".revision = (((hackage."filepattern")."0.1.1").revisions).default;
210− "libyaml".revision = (((hackage."libyaml")."0.1.1.1").revisions).default;
211− "libyaml".flags.system-libyaml = false;
212− "libyaml".flags.no-unicode = false;
213−Calculated hash is 1qjmhlb4rw6mggs7y57f6zr5zjmkhkx7sn9q8pb18308n5nxgxcs expected hash was 1a4rhv3h2daz6dzwzfl3w7l1v556n7aqfiagw6m0rvqq230iabss for hlint-plan-to-nix-pkgs
214−builder for '/nix/store/zmif4gk52ynh57pf4dikzgsk30haqi2b-hlint-plan-to-nix-pkgs.drv' failed with exit code 1
215−error: build of '/nix/store/zmif4gk52ynh57pf4dikzgsk30haqi2b-hlint-plan-to-nix-pkgs.drv' failed
173+$ nix-build hlint.nix
174+
175+...
176+
177+Calculated hash for hlint-plan-to-nix-pkgs was not 02hasr27a994sml1fzf8swb716lm6lgixxr53y0gxkhw437xkck4. New hash is :
178+ plan-sha256 = "0zsi3wv92qax33ic4n5dfsqd1r9qam1k75za3c5jqgdxl3hy8vph";
179+Materialized nix used for hlint-plan-to-nix-pkgs incorrect. To fix run :
180+ rm -rf /Users/hamish/iohk/haskell.nix/hlint.materialized
181+ cp -r /nix/store/ywdhbx9rzzkfc60c5vzk7cins2hnvkgx-hlint-plan-to-nix-pkgs /Users/hamish/iohk/haskell.nix/hlint.materialized
182+ chmod -R +w /Users/hamish/iohk/haskell.nix/hlint.materialized
183+builder for '/nix/store/a5zmgfjfxahapw0q8hd2da5bg7knqvbx-hlint-plan-to-nix-pkgs.drv' failed with exit code 1
184+error: build of '/nix/store/a5zmgfjfxahapw0q8hd2da5bg7knqvbx-hlint-plan-to-nix-pkgs.drv' failed
185+(use '--show-trace' to show detailed location information)
216186```
217187
218188Checking the materialization requires nix to do all the work that materialization
@@ -228,21 +198,21 @@ hash and materialized nix we can find out what nix files should be.
228198For instance:
229199
230200```nix
231−let inherit (import ./. {}) sources nixpkgsArgs;
232− pkgs = import sources.nixpkgs-default nixpkgsArgs;
201+let inherit (import ./. {}) sources nixpkgsArgs;
202+ pkgs = import sources.nixpkgs-default nixpkgsArgs;
233203 hlint = pkgs.haskell-nix.hackage-project {
234204 name = "hlint";
235− version = "2.2.4";
236− index-state = "2019-12-03T00:00:00Z";
205+ version = "2.2.10";
206+ index-state = "2020-04-15T00:00:00Z";
237207 };
238208in hlint
239209```
240210
241211```
242212$ nix-build hlint.nix -A plan-nix
243−trace: Using index-state: 2019-12-03T00:00:00Z for hlint
244−trace: Get `plan-sha256` with `nix-hash --base32 --type sha256 /nix/store/qk1fvza1alkvs51vzmpjp2xsg8xklyxk-hlint-plan-to-nix-pkgs/`
245−/nix/store/qk1fvza1alkvs51vzmpjp2xsg8xklyxk-hlint-plan-to-nix-pkgs
213+trace: Using index-state: 2020-04-15T00:00:00Z for hlint
214+trace: Get `plan-sha256` with `nix-hash --base32 --type sha256 /nix/store/ywdhbx9rzzkfc60c5vzk7cins2hnvkgx-hlint-plan-to-nix-pkgs/`
215+/nix/store/ywdhbx9rzzkfc60c5vzk7cins2hnvkgx-hlint-plan-to-nix-pkgs
246216```
247217
248218We can have the script copy `$(nix-build hlint.nix -A plan-nix --no-out-link)`
@@ -257,17 +227,23 @@ Yes and it gives us the same speed improvement, however:
257227* Users will still wind up building or downloading the dependencies
258228 needed to build the nix fileds (if they do not have them).
259229
260−For instance:
230+For those reasons it might be best to make a copy instead
231+of using the `/nix/store/...` path directly.
232+
233+If you really want to use the `/nix/store/...` path directly
234+you should gaurd against the path not existing as passing in
235+a non-existing path is now an error:
261236
262237```nix
263−let inherit (import ./. {}) sources nixpkgsArgs;
264− pkgs = import sources.nixpkgs-default nixpkgsArgs;
238+let inherit (import ./. {}) sources nixpkgsArgs;
239+ pkgs = import sources.nixpkgs-default nixpkgsArgs;
240+ hlintPlan = /nix/store/kk047cqsjvbj4w8psv4l05abdcnyrqdc-hlint-plan-to-nix-pkgs;
265241 hlint = pkgs.haskell-nix.hackage-package {
266242 name = "hlint";
267− version = "2.2.4";
268− index-state = "2019-12-03T00:00:00Z";
269− plan-sha256 = "1a4rhv3h2daz6dzwzfl3w7l1v556n7aqfiagw6m0rvqq230iabss";
270− materialized = /nix/store/qk1fvza1alkvs51vzmpjp2xsg8xklyxk-hlint-plan-to-nix-pkgs;
243+ version = "2.2.11";
244+ index-state = "2020-04-15T00:00:00Z";
245+ plan-sha256 = "02hasr27a994sml1fzf8swb716lm6lgixxr53y0gxkhw437xkck4";
246+ materialized = if __pathExists hlintPlan then hlintPlan else null;
271247 };
272248in hlint.components.exes.hlint
273249```
@@ -275,17 +251,17 @@ in hlint.components.exes.hlint
275251Running when no building is needed is still slow in restricted evaluation mode.
276252
277253```
278−$ time nix-build --option restrict-eval true -I . --option allowed-uris "https://github.com/NixOS https://github.com/input-output-hk" hlint.nix
279−trace: Using index-state: 2019-12-03T00:00:00Z for hlint
280−/nix/store/7wwqq5v42gm6iiz2d3ngbnkyw7i4py11-hlint-2.2.4-exe-hlint
281−
282−real 0m10.066s
283−user 0m8.563s
284−sys 0m0.630s
285−$ time nix-build hlint.nix
286−/nix/store/7wwqq5v42gm6iiz2d3ngbnkyw7i4py11-hlint-2.2.4-exe-hlint
287−
288−real 0m4.628s
289−user 0m3.889s
290−sys 0m0.389s
254+$ time nix-build --option restrict-eval true -I . --option allowed-uris "https://github.com/NixOS https://github.com/input-output-hk" hlint.nix --show-trace
255+trace: Using index-state: 2020-04-15T00:00:00Z for hlint
256+/nix/store/rnfz66v7k8i38c8rsmchzsyqjrmrbdpk-hlint-2.2.11-exe-hlint
257+
258+real 0m4.463s
259+user 0m4.440s
260+sys 0m0.461s
261+$ time nix-build hlint.nix
262+/nix/store/rnfz66v7k8i38c8rsmchzsyqjrmrbdpk-hlint-2.2.11-exe-hlint
263+
264+real 0m2.206s
265+user 0m1.665s
266+sys 0m0.332s
291267```