1# Generate cache entries for dependencies of package defined in `src`
5, stackYaml ? "stack.yaml"
7 # An alternative to adding `# nix-sha256:` comments into the
10 # { "https://github.com/jgm/pandoc-citeproc"."0.17"
11 # = "0dxx8cp2xndpw3jwiawch2dkrkp15mil7pyx7dvd810pwc22pm2q"; };
13 # A way to specify in which branch a git commit can
17 then { location, tag, ...}: branchMap."${location}"."${tag}" or null
19, resolverSha256 ? null
20, nix-tools ? pkgs.haskell-nix.internal-nix-tools # When building stack projects we use the internal nix-tools (compiled with a fixed GHC version)
24 # We only care about the stackYaml file. If src is a local directory
25 # we want to avoid recalculating the cache unless the stack.yaml file
28 inherit (haskellLib.fetchResolver {
29 inherit src stackYaml resolverSha256;
30 }) resolver fetchedResolver;
32 # Filter just the stack yaml file and any resolver yaml file it points to.
33 maybeCleanedSource = haskellLib.cleanSourceWith {
37 origSrc = if src ? _isLibCleanSourceWith then src.origSrc else src;
38 origSubDir = if src ? _isLibCleanSourceWithEx then src.origSubDir else "";
39 relPath = pkgs.lib.removePrefix (toString origSrc + origSubDir + "/") path;
41 # checks if path1 is a parent directory for path2
42 isParent = path1: path2: pkgs.lib.hasPrefix "${path1}/" path2;
45 (relPath == stackYaml)
46 || (resolver != null && (relPath == resolver || isParent relPath resolver))
50 # All repos served via ssh or git protocols are usually private
51 private = url: pkgs.lib.substring 0 4 url != "http";
53 repos = builtins.fromJSON (builtins.readFile (pkgs.runCommand "stack-repos" {
54 buildInputs = [ nix-tools ];
58 cp -r "${maybeCleanedSource}/." $TMP
60 substituteInPlace ${stackYaml} --replace "# nix-sha256:" "nix-sha256:"
61 ${pkgs.lib.optionalString (fetchedResolver != null) ''
62 substituteInPlace ${stackYaml} --replace "${resolver}" "${fetchedResolver}"
64 stack-repos --stack-yaml ${stackYaml}
68 cabalName = path: builtins.readFile (pkgs.runCommand "cabal-name" {
69 buildInputs = [ nix-tools ];
71 cabal-name ${path} > $out
75 builtins.readFile (pkgs.runCommand "hash-path" { preferLocalBuild = true; }
76 "echo -n $(${pkgs.nix}/bin/nix-hash --type sha256 --base32 ${path}) > $out");
80 is-private = private dep.url;
82 if dep.sha256 != null then dep.sha256
83 else if sha256map != null then sha256map."${dep.url}"."${dep.rev}"
85 branch = lookupBranch {
90 if !is-private && sha256 != null
92 inherit (dep) url rev;
95 else builtins.fetchGit ({
96 inherit (dep) url rev;
97 } // pkgs.lib.optionalAttrs (branch != null) { ref = branch; });
99 name = cabalName "${pkgsrc}/${subdir}";
100 inherit (dep) url rev;
102 sha256 = if !is-private then hashPath pkgsrc else null;
103 } // (optionalAttrs (subdir != "") { inherit subdir; }))
104 (dep.subdirs or [ "" ])) repos
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list