justinwoo / spago2nix

Generate a derivation of (old) Spago dependencies, and use them to install them into the directory structure used by Spago.
MIT License
42 stars 23 forks source link

Bad fetch on a branch name in package version (troubleshooting proposal) #3

Closed chekoopa closed 4 years ago

chekoopa commented 5 years ago

Tried using it with my project which involves an override with a branch version, got a broke fetch.

errors from fetching packages:
(MissingRevOrRepoResult "{ packageName: \"hedwig\", repo: (Remote \"https://github.com/chekoopa/purescript-hedwig.git\"), version: \"vnode-hooks\" }")

Resolved by providing a particular commit hash as a version. Luckily, it even works with plain Spago runs.

We should put this detail in README. Like, better use version tags or commit hashes instead of branch names.

justinwoo commented 5 years ago

Seems strange, but probably it stems from forgetting to use some random flags for nix-prefetch-git: https://github.com/justinwoo/spago2nix/blob/master/src/Generate.purs#L66-L74

chekoopa commented 5 years ago

As using the branch name as a version is discouraged, so that's a stone in my own garden. Even if it works in plain Spago fetches, it goes cheesy on Nix.

The issue is mostly on its side, I'm afraid. rev parameter is only for commit hashes and tags, AFAIK.

Here's a nix-prefetch-git output without --quiet flag:

$ nix-prefetch-git https://github.com/chekoopa/purescript-hedwig.git --rev vnode-hooks

fatal: couldn't find remote ref refs/tags/vnode-hooks
remote: Enumerating objects: 30, done.
remote: Counting objects: 100% (30/30), done.
<... here it clones the repo ...>
fatal: empty string is not a valid pathspec. please use . instead if you meant to match all paths
Unable to checkout refs/tags/vnode-hooks from https://github.com/chekoopa/purescript-hedwig.git.

It should checkout refs/heads/vnode-hooks, but whatever, it's Nix.

UPD: it is sure about the Nix way of fetching.

$ nix-prefetch-git --help
< ... >
  --rev ref       Any sha1 or references (such as refs/heads/master) 
< ... >

$ nix-prefetch-git https://github.com/chekoopa/purescript-hedwig.git --rev refs/heads/vnode-hooks
Initialized empty Git repository in /tmp/git-checkout-tmp-sRP1Y1pU/purescript-hedwig/.git/
remote: Enumerating objects: 34, done.
remote: Counting objects: 100% (34/34), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 34 (delta 1), reused 19 (delta 0), pack-reused 0
Unpacking objects: 100% (34/34), done.
From https://github.com/chekoopa/purescript-hedwig
 * branch            vnode-hooks -> FETCH_HEAD
 * [new branch]      vnode-hooks -> origin/vnode-hooks
Switched to a new branch 'fetchgit'
removing `.git'...

git revision is 56706df8a9a1f4faedaebceac07dfa8775169ff5
path is /nix/store/7ls6ipmx4d9xhfyyr8a5may7s0ngkbga-purescript-hedwig
git human-readable version is -- none --
Commit date is 2019-06-08 01:15:30 +0800
hash is 03f8hn6nzmrz742b6by5q6y8isjmyh29a3ipy355dysf1ksk8kam
{
  "url": "https://github.com/chekoopa/purescript-hedwig.git",
  "rev": "56706df8a9a1f4faedaebceac07dfa8775169ff5",
  "date": "2019-06-08T01:15:30+08:00",
  "sha256": "03f8hn6nzmrz742b6by5q6y8isjmyh29a3ipy355dysf1ksk8kam",
  "fetchSubmodules": false
}

Really!

justinwoo commented 5 years ago

You probably need to do refs/heads/branchname for the rev

chekoopa commented 5 years ago

I've done that (my earlier comment was updated).

And it seems to be compatible with Spago, too. However, a commit hash is more robust and explicit.

That's one of the things which should be documented. PR is on its way. 👀

justinwoo commented 4 years ago

Closing this issue as it seems resolved.