on iko/ghcjs-patch-master help sign in
Use fixed output derivations for bootstrap plans (#286)

Currently when a dependency of cabal-install or plan-to-nix changes the cabal new-configure and plan-to-nix have to be rebuilt in order to recalculate the plan-nix for bootstrap packages alex, happy and hscolour. We have pinned the inputs such as hackage index-state so that the plan generated should be the same. Unfortunately it can still result in a long wait. Haskell.nix does cache the result via haskellNixRoots when built on iohk's hydra server. But if you use a different version of nixpkgs it is unlikely to work. If you have access to a CI that populates a nix cache you can add haskellNixRoots to your CI build, but if not you are kind of stuck. One option to help with this would be to include the plan-to-nix output in the haskell.nix git repository. But intermediate files in git is not nice. Instead this PR adds just the hashes of the output to the derivations that runs plan-to-nix. Since the inputs are fixed or should have no affect on the result (GCC version for instance), we should be able to rely on them remaining constant.

commit4d27798d6d297d3fa764e1104c63c8d10cb95c6d authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateSat 2 Nov 2019, 01:21 (7 years ago) parent686fa37
3 files changed+29−5
docs/reference/library.md+13 lib/call-cabal-project-to-nix.nix+13−5 overlays/bootstrap.nix+3
docs/reference/library.md+13
@@ -208,6 +208,19 @@ needed for `importAndFilterProject`.
208208 })).pkgs;
209209```
210210
211+| Argument | Type | Description |
212+|------------------|------|---------------------|
213+| `name` | String | Optional name for better error messages. |
214+| `src` | Path | Location of the cabal project files. |
215+| `index-state` | Timestamp | Optional hackage index-state, eg. "2019-10-10T00:00:00Z". |
216+| `index-sha256` | Sha256 | Optional hash of the truncated hackage index-state. |
217+| `plan-sha256` | Sha256 | Optional hash of the plan-to-nix output (makes the plan-to-nix step a fixed output derivation). |
218+| `cabalProject` | Path | Optional cabal project file (defaults to "${src}/cabal.project"). |
219+| `ghc` | | Optional ghc to use |
220+| `nix-tools` | | Optional nix-tools to use |
221+| `hpack` | | Optional hpack to use |
222+| `cabal-install` | | Optional cabal-install to use |
223+
211224## importAndFilterProject
212225
213226Imports from a derivation created by `callStackToNix`
lib/call-cabal-project-to-nix.nix+13−5
@@ -1,9 +1,10 @@
11{ dotCabal, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack, symlinkJoin, cacert, index-state-hashes, haskellLib }@defaults:
22{ name ? null # optional name for better error messages
33, src
4−, index-state ? null
5−, index-sha256 ? null
6−, cabalProject ? null
4+, index-state ? null # Hackage index-state, eg. "2019-10-10T00:00:00Z"
5+, index-sha256 ? null # The hash of the truncated hackage index-state
6+, plan-sha256 ? null # The hash of the plan-to-nix output (makes the plan-to-nix step a fixed output derivation)
7+, cabalProject ? null # Cabal project file (when null uses "${src}/cabal.project")
78, ghc ? defaults.ghc
89, nix-tools ? defaults.nix-tools
910, hpack ? defaults.hpack
@@ -149,11 +150,18 @@ let
149150 }
150151 else replaceSoureRepos rawCabalProject;
151152
152− plan-nix = runCommand "plan-to-nix-pkgs" {
153+ plan-nix = runCommand "plan-to-nix-pkgs" ({
153154 nativeBuildInputs = [ nix-tools ghc hpack cabal-install pkgs.rsync pkgs.git ];
154155 # Needed or stack-to-nix will die on unicode inputs
155156 LANG = "en_US.UTF-8";
156− } (''
157+ } // (if plan-sha256 == null
158+ then {}
159+ else {
160+ outputHashMode = "recursive";
161+ outputHashAlgo = "sha256";
162+ outputHash = plan-sha256;
163+ })
164+ ) (''
157165 tmp=$(mktemp -d)
158166 cd $tmp
159167 cp -r ${maybeCleanedSource}/* .
overlays/bootstrap.nix+3
@@ -271,6 +271,7 @@ self: super: rec {
271271 inherit (bootstrap.haskell.packages) cabal-install nix-tools hpack;
272272 name = "alex"; version = "3.2.4";
273273 index-state = "2019-10-20T00:00:00Z";
274+ plan-sha256 = "086kd6aa5bir3y4aqb1wl5zkj6agz5q4wp4snvdnf6cidz5wra06";
274275 };
275276 alex = bootstrap.haskell.packages.alex-project.alex.components.exes.alex;
276277 happy-project = hackage-project {
@@ -278,6 +279,7 @@ self: super: rec {
278279 inherit (bootstrap.haskell.packages) cabal-install nix-tools hpack;
279280 name = "happy"; version = "1.19.11";
280281 index-state = "2019-10-20T00:00:00Z";
282+ plan-sha256 = "011bxlxdv239psgi80j00km2wcgb68j16sz3fng67d03sqf5i37w";
281283 };
282284 happy = bootstrap.haskell.packages.happy-project.happy.components.exes.happy;
283285 hscolour-project = hackage-project {
@@ -285,6 +287,7 @@ self: super: rec {
285287 inherit (bootstrap.haskell.packages) cabal-install nix-tools hpack;
286288 name = "hscolour"; version = "1.24.4";
287289 index-state = "2019-10-20T00:00:00Z";
290+ plan-sha256 = "021rwcmkshibc3mfr833ay5hfr19kq6k32lxyrrb6vp9vmihgw4b";
288291 };
289292 hscolour = bootstrap.haskell.packages.hscolour-project.hscolour.components.exes.HsColour;
290293 };