Files
haskell.nix/lib/fetch-resolver.nix
Hamish Mackenzie 44ecbc8ff8 Improve cleaning of stack projects (#1074)
Should help with #1013
2021-03-19 10:25:32 +13:00

38 lines
1.3 KiB
Nix

# Find the resolver in the stack.yaml file and fetch it if a sha256 value is provided
{ pkgs }:
{ src
, stackYaml ? "stack.yaml"
, resolverSha256 ? null
}:
let
srcDir = src.origSrcSubDir or src;
# Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
# access to the store is restricted. If origSrc was already in the store
# you can pass the project in as a string.
rawStackYaml = builtins.readFile (srcDir + "/${stackYaml}");
# Determine the resolver as it may point to another file we need
# to look at.
resolver =
let
rs = pkgs.lib.lists.concatLists (
pkgs.lib.lists.filter (l: l != null)
(builtins.map (l: builtins.match "^resolver: *(.*)" l)
(pkgs.lib.splitString "\n" rawStackYaml)));
in
pkgs.lib.lists.head (rs ++ [ null ]);
# If we found a resolver and we have a resolverSha256 then we should download it.
fetchedResolver =
if resolver != null && resolverSha256 != null
then pkgs.fetchurl {
url = resolver;
sha256 = resolverSha256;
}
else if resolver != null && __pathExists (srcDir + "/${resolver}")
then pkgs.copyPathToStore (srcDir + "/${resolver}")
else null;
in { inherit resolver fetchedResolver; }