on 19052d8 help sign in
haskell.nix/lib/fetch-resolver.nix
37 lines 1.3 kB history raw
1# Find the resolver in the stack.yaml file and fetch it if a sha256 value is provided
2{ pkgs }:
3{ src
4, stackYaml ? "stack.yaml"
5, resolverSha256 ? null
6}:
7let
8 srcDir = src.origSrcSubDir or src;
10 # Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
11 # access to the store is restricted. If origSrc was already in the store
12 # you can pass the project in as a string.
13 rawStackYaml = builtins.readFile (srcDir + "/${stackYaml}");
15 # Determine the resolver as it may point to another file we need
16 # to look at.
17 resolver =
18 let
19 rs = pkgs.lib.lists.concatLists (
20 pkgs.lib.lists.filter (l: l != null)
21 (builtins.map (l: builtins.match "^resolver: *(.*)" l)
22 (pkgs.lib.splitString "\n" rawStackYaml)));
23 in
24 pkgs.lib.lists.head (rs ++ [ null ]);
26 # If we found a resolver and we have a resolverSha256 then we should download it.
27 fetchedResolver =
28 if resolver != null && resolverSha256 != null
29 then pkgs.fetchurl {
30 url = resolver;
31 sha256 = resolverSha256;
32 }
33 else if resolver != null && __pathExists (srcDir + "/${resolver}")
34 then pkgs.copyPathToStore (srcDir + "/${resolver}")
35 else null;
37in { inherit resolver fetchedResolver; }