on e94de40 help sign in
haskell.nix/lib/fetch-resolver.nix
33 lines 1.2 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 # Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
9 # access to the store is restricted. If origSrc was already in the store
10 # you can pass the project in as a string.
11 rawStackYaml = builtins.readFile ((src.origSrcSubDir or src) + ("/" + stackYaml));
13 # Determine the resolver as it may point to another file we need
14 # to look at.
15 resolver =
16 let
17 rs = pkgs.lib.lists.concatLists (
18 pkgs.lib.lists.filter (l: l != null)
19 (builtins.map (l: builtins.match "^resolver: *(.*)" l)
20 (pkgs.lib.splitString "\n" rawStackYaml)));
21 in
22 pkgs.lib.lists.head (rs ++ [ null ]);
24 # If we found a resolver and we have a resolverSha256 then we should download it.
25 fetchedResolver =
26 if resolver != null && resolverSha256 != null
27 then pkgs.fetchurl {
28 url = resolver;
29 sha256 = resolverSha256;
30 }
31 else null;
33in { inherit resolver fetchedResolver; }