GitHub has deprecated setting the environment variables and paths via
echoing to the stdout:
https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
Thus, this PR brings the code up to data with the recommendations in the
linked post. In short, paths are exposed to subsequent steps by
appending to the file named in `$GITHUB_PATH`, while environment
variables are set by appending `name=value` to the file named in
`$GITHUB_ENV`.
Whereas before niv would simply say that git didn't produce any output,
it now points out that the branch may not exist:
```
*Niv> :main add git git@github.com:nmattia/niv -b foobar
Adding package niv
FATAL: Could not read the output of 'git'.
command: git ls-remote git@github.com:nmattia/niv refs/heads/foobar
Git didn't produce any output. Does the branch 'foobar' exist?
FATAL: One or more packages failed to update:
niv: ExitFailure 1
ERROR: ExitFailure 1
*** Exception: ExitFailure 1
```
Here we make sure that some environment variables are prepended
(GITHUB_PATH, GITHUB_INSECURE). For consistency's sake, other
environment variables (GITHUB_TOKEN, etc) _can_ also be prepended with
NIV_. This also issues a warning if `GITHUB_PATH` or `GITHUB_INSECURE`
is set.
This should hopefully clarify that `--version` shouldn't be used for
GitHub repositories; moreover setting a particular revision is used much
more often than changing the repo name.
When combining Nix Flakes with niv, `builtins.currentSystem` is
disabled. This allows to bootstrap nixpkgs by passing the system from
the flake evaluation.
Instead, sources now record either `branch` or `tag`. The fetcher
specifies the correct ref (`/refs/heads/...` or `/refs/tags/...`) which
works in the newest version of Nix. The `ref` attribute can still be set
to override the logic.
This updates the sources.nix to replace the `outPath` field of package
`foo` with the content of envionment variable `NIV_OVERRIDE_foo`. In the
environment variable name, all characters outside of `[a-zA-Z0-9_]` are
escaped to `_`.
Some results were fetched _way_ too many times. All IO operations run in
updates are now cached. This makes `niv` effectively twice as fast.
*before:*
```
~/niv$ time niv add git git@github.com:nmattia/niv
Adding package niv
Writing new sources file
Done: Adding package niv
real 0m3.603s
user 0m0.079s
sys 0m0.031s
```
*after:*
```
~/niv$ time niv add git git@github.com:nmattia/niv
Adding package niv
Writing new sources file
Done: Adding package niv
real 0m1.387s
user 0m0.049s
sys 0m0.007s
```