mirror of
https://github.com/nix-community/dream2nix.git
synced 2025-01-04 12:46:26 +03:00
add: support git URLs in package-lock parser
This commit is contained in:
parent
39b3851ceb
commit
3cbac60c4d
@ -15,7 +15,7 @@
|
||||
{
|
||||
fetchedSources,
|
||||
dreamLock,
|
||||
packageOverrides,
|
||||
packageOverrides ? {},
|
||||
|
||||
# custom opts:
|
||||
standalonePackageNames ? [],
|
||||
|
@ -31,20 +31,24 @@ let
|
||||
|
||||
node2nixDependencies =
|
||||
let
|
||||
makeSource = name: {
|
||||
name = lib.head (lib.splitString "#" name);
|
||||
packageName = lib.head (lib.splitString "#" name);
|
||||
version = dreamLock.sources."${name}".version;
|
||||
src = fetchedSources."${name}";
|
||||
dependencies =
|
||||
lib.forEach
|
||||
(lib.filter
|
||||
(depName: ! builtins.elem depName dreamLock.generic.dependencyGraph."${mainPackageName}")
|
||||
(dreamLock.generic.dependencyGraph."${name}" or []))
|
||||
(dependency:
|
||||
makeSource dependency
|
||||
);
|
||||
};
|
||||
makeSource = name:
|
||||
let
|
||||
packageName = lib.head (lib.splitString "#" name);
|
||||
in
|
||||
{
|
||||
inherit packageName;
|
||||
name = lib.strings.sanitizeDerivationName packageName;
|
||||
version = dreamLock.sources."${name}".version;
|
||||
src = fetchedSources."${name}";
|
||||
dependencies =
|
||||
lib.forEach
|
||||
(lib.filter
|
||||
(depName: ! builtins.elem depName dreamLock.generic.dependencyGraph."${mainPackageName}")
|
||||
(dreamLock.generic.dependencyGraph."${name}" or []))
|
||||
(dependency:
|
||||
makeSource dependency
|
||||
);
|
||||
};
|
||||
in
|
||||
lib.forEach
|
||||
dreamLock.generic.dependencyGraph."${mainPackageName}"
|
||||
@ -52,8 +56,8 @@ let
|
||||
|
||||
callNode2Nix = funcName: args:
|
||||
node2nixEnv."${funcName}" rec {
|
||||
name = lib.head (lib.splitString "#" mainPackageName);
|
||||
packageName = name;
|
||||
name = lib.strings.sanitizeDerivationName packageName;
|
||||
packageName = lib.head (lib.splitString "#" mainPackageName);
|
||||
version = dreamLock.sources."${mainPackageName}".version;
|
||||
dependencies = node2nixDependencies;
|
||||
# buildInputs ? []
|
||||
|
@ -28,6 +28,7 @@ rec {
|
||||
constructSource =
|
||||
{
|
||||
type,
|
||||
reComputeHash ? false,
|
||||
...
|
||||
}@args:
|
||||
let
|
||||
@ -42,7 +43,7 @@ rec {
|
||||
version = args."${fetcher.versionField}";
|
||||
})
|
||||
# if the hash was not provided, calculate hash on the fly (impure)
|
||||
// (lib.optionalAttrs (! args ? hash) {
|
||||
// (lib.optionalAttrs reComputeHash {
|
||||
hash = fetcherOutputs.calcHash "sha256";
|
||||
});
|
||||
|
||||
@ -59,6 +60,7 @@ rec {
|
||||
in
|
||||
constructSource (argsKeep // {
|
||||
version = newVersion;
|
||||
reComputeHash = true;
|
||||
} // {
|
||||
"${fetcher.versionField}" = newVersion;
|
||||
});
|
||||
|
@ -61,7 +61,7 @@ in
|
||||
throw "Cannot fetch git repo without integrity. Specify at least 'rev' or 'sha256'"
|
||||
else
|
||||
b.fetchGit (
|
||||
{ inherit url;} // refAndRev
|
||||
{ inherit url; allRefs = true; } // refAndRev
|
||||
)
|
||||
else
|
||||
fetchgit {
|
||||
|
@ -19,6 +19,9 @@
|
||||
...
|
||||
}@args:
|
||||
let
|
||||
|
||||
b = builtins;
|
||||
|
||||
packageLock =
|
||||
if inputDirectories != [] then
|
||||
"${lib.elemAt inputDirectories 0}/package-lock.json"
|
||||
@ -27,14 +30,19 @@
|
||||
|
||||
parsed = externals.npmlock2nix.readLockfile packageLock;
|
||||
|
||||
parseGithubDependency = dependency:
|
||||
externals.npmlock2nix.parseGitHubRef dependency.version;
|
||||
identifyGitSource = dependencyObject:
|
||||
# TODO: when integrity is there, and git url is github then use tarball instead
|
||||
# ! (dependencyObject ? integrity) &&
|
||||
utils.identifyGitUrl dependencyObject.version;
|
||||
|
||||
# parseGithubDependency = dependency:
|
||||
# externals.npmlock2nix.parseGitHubRef dependency.version;
|
||||
|
||||
getVersion = dependencyObject:
|
||||
if dependencyObject ? from && dependencyObject ? version then
|
||||
builtins.substring 0 8 (parseGithubDependency dependencyObject).rev
|
||||
else
|
||||
dependencyObject.version;
|
||||
if identifyGitSource dependencyObject then
|
||||
builtins.substring 0 8 (utils.parseGitUrl dependencyObject.version).rev
|
||||
else
|
||||
dependencyObject.version;
|
||||
|
||||
pinVersions = dependencies: parentScopeDeps:
|
||||
lib.mapAttrs
|
||||
@ -97,22 +105,15 @@
|
||||
inherit getVersion;
|
||||
|
||||
getSourceType = dependencyObject:
|
||||
if dependencyObject ? from && dependencyObject ? version then
|
||||
"github"
|
||||
if identifyGitSource dependencyObject then
|
||||
"git"
|
||||
else
|
||||
"fetchurl";
|
||||
|
||||
sourceConstructors = {
|
||||
github = dependencyObject:
|
||||
let
|
||||
githubData = parseGithubDependency dependencyObject;
|
||||
in
|
||||
rec {
|
||||
version = builtins.substring 0 8 githubData.rev;
|
||||
owner = githubData.org;
|
||||
repo = githubData.repo;
|
||||
rev = githubData.rev;
|
||||
};
|
||||
|
||||
git = dependencyObject:
|
||||
utils.parseGitUrl dependencyObject.version;
|
||||
|
||||
fetchurl = dependencyObject:
|
||||
rec {
|
||||
|
@ -19,10 +19,14 @@ let
|
||||
|
||||
overrideUtils = callPackageDream ./override.nix {};
|
||||
|
||||
parseUtils = callPackageDream ./parsing.nix {};
|
||||
|
||||
translatorUtils = callPackageDream ./translator.nix {};
|
||||
|
||||
in
|
||||
|
||||
parseUtils
|
||||
//
|
||||
overrideUtils
|
||||
//
|
||||
translatorUtils
|
||||
@ -100,5 +104,6 @@ rec {
|
||||
''
|
||||
+ old.postFetch;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
35
src/utils/parsing.nix
Normal file
35
src/utils/parsing.nix
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
|
||||
b = builtins;
|
||||
|
||||
identifyGitUrl = url:
|
||||
lib.hasPrefix "git+" url;
|
||||
|
||||
parseGitUrl = url:
|
||||
let
|
||||
splitUrlRev = lib.splitString "#" url;
|
||||
rev = lib.last splitUrlRev;
|
||||
urlOnly = lib.head splitUrlRev;
|
||||
in
|
||||
if lib.hasPrefix "git+ssh://" urlOnly then
|
||||
{
|
||||
inherit rev;
|
||||
url = "https://${(lib.last (lib.splitString "@" url))}";
|
||||
}
|
||||
else if lib.hasPrefix "git+https://" urlOnly then
|
||||
{
|
||||
inherit rev;
|
||||
url = lib.removePrefix "git+" urlOnly;
|
||||
}
|
||||
else
|
||||
throw "Cannot parse git url: ${url}";
|
||||
|
||||
|
||||
in
|
||||
{
|
||||
inherit identifyGitUrl parseGitUrl;
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
{
|
||||
lib,
|
||||
|
||||
# dream2nix
|
||||
fetchers,
|
||||
...
|
||||
}:
|
||||
let
|
||||
@ -51,9 +54,11 @@ let
|
||||
"${getName pkgData}#${getVersion pkgData}" =
|
||||
let
|
||||
type = getSourceType pkgData;
|
||||
constructedArgs =
|
||||
(sourceConstructors."${type}" pkgData)
|
||||
// { inherit type; };
|
||||
in
|
||||
(sourceConstructors."${type}" pkgData)
|
||||
// { inherit type; };
|
||||
fetchers.constructSource constructedArgs;
|
||||
})
|
||||
{}
|
||||
serializedPackagesList;
|
||||
|
27
tests/defaut.nix
Normal file
27
tests/defaut.nix
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
lib,
|
||||
|
||||
# dream2nix
|
||||
utils,
|
||||
}:
|
||||
|
||||
let
|
||||
b = builtins;
|
||||
|
||||
testParseGitUrl =
|
||||
let
|
||||
testCases = [
|
||||
{
|
||||
input = "git+ssh://git@github.com/mattermost/marked.git#6ca9a6b3f4bdd35dbf58d06f5e53369791e05915";
|
||||
output = { owner = "mattermost"; repo = "marked"; rev = "6ca9a6b3f4bdd35dbf58d06f5e53369791e05915"; };
|
||||
}
|
||||
{
|
||||
input = "git+https://gitlab.com/openengiadina/js-eris.git#cbe42c8d1921837cc1780253dc9113622cd0826a";
|
||||
output = { owner = "openengiadina"; repo = "js-eris"; rev = "cbe42c8d1921837cc1780253dc9113622cd0826a"; };
|
||||
}
|
||||
];
|
||||
|
||||
in
|
||||
assert ! testParseGithu ->
|
||||
throw "failed";
|
||||
true
|
Loading…
Reference in New Issue
Block a user