Skip to content
This repository was archived by the owner on May 20, 2021. It is now read-only.

Move fetching into Nix and allow custom fetching #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thefloweringash
Copy link

The idea here is to make yarn2nix (the program) emit pure data instead of code, and then interpret that on the Nix side. For the case of tarring up git dependencies, it means not having to embed the tar call in the generated file. It also allows custom fetchers which can embed authentication for access to private registries.

While I'm here, remove instances of % in names. I observed this in a url escaped slash (%2f).

This is is a breaking change to the generated dependency file format. All consumers will have to regenerate their yarn.nix files.

Introduces a `yarnFetch` argument that can be used to specify a custom
fetcher. This is useful to weave in calls to fetchgitPrivate, or
fetchurl with authentication via `netrcPhase` and
`netrcImpureEnvVars`.

Implementations of yarnFetch must return the resulting path, and can
chain to the default behavior by calling `defaultYarnFetch`.
Copy link
Member

@zimbatm zimbatm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I guess the next evolution of this PR will be to write a yarn.lock parser in nix :)

@@ -15,7 +15,7 @@ function urlToName(url) {

return url
.replace('https://registry.yarnpkg.com/', '') // prevents having long directory names
.replace(/[@/:-]/g, '_') // replace @ and : and - characters with underscore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to add a test-case that reproduces the issue?

I think this happens when the URL contains %2f for example which might mean the URL has to be url-decoded instead.

# Loads the generated offline cache. This will be used by yarn as
# the package source.
importOfflineCache = yarnNix:
let
pkg = callPackage yarnNix { };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's nice that callPackage is not needed anymore

ref = "${branch}";
rev = "${rev}";
};
}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is an opportunity to return JSON data here and process the result with a JSON2nix converter function higher in the call stack

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants