mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-24 23:14:12 +03:00
simplify git shortcut + add versionField
This commit is contained in:
parent
2ea153f320
commit
a3c542fa6d
@ -35,6 +35,19 @@ rec {
|
||||
fetchViaShortcut = shortcut:
|
||||
let
|
||||
|
||||
checkArgs = fetcherName: args:
|
||||
let
|
||||
fetcher = fetchers."${fetcherName}";
|
||||
unknownArgNames = lib.filter (argName: ! lib.elem argName fetcher.inputs) (lib.attrNames args);
|
||||
missingArgNames = lib.filter (inputName: ! args ? "${inputName}") fetcher.inputs;
|
||||
in
|
||||
if lib.length unknownArgNames > 0 then
|
||||
throw "Received unknown arguments for fetcher '${fetcherName}': ${b.toString unknownArgNames}"
|
||||
else if lib.length missingArgNames > 0 then
|
||||
throw "Missing arguments for fetcher '${fetcherName}': ${b.toString missingArgNames}"
|
||||
else
|
||||
args;
|
||||
|
||||
fetchViaHttpUrl =
|
||||
let
|
||||
fetcher = fetchers.fetchurl;
|
||||
@ -60,7 +73,7 @@ rec {
|
||||
));
|
||||
fetcher = fetchers.git;
|
||||
args = params // { inherit url; };
|
||||
fetcherOutputs = fetcher.outputs args;
|
||||
fetcherOutputs = fetcher.outputs (checkArgs "git" args);
|
||||
in
|
||||
rec {
|
||||
hash = fetcherOutputs.calcHash "sha256";
|
||||
|
@ -17,16 +17,28 @@ in
|
||||
"rev"
|
||||
];
|
||||
|
||||
outputs = { url, ref ? null, rev ? null, ... }@inp:
|
||||
if ref == null && rev == null then
|
||||
throw "At least 'rev' or 'ref' must be specified for fetcher 'git'"
|
||||
else if rev != null && ! (builtins.match "[a-f0-9]*" rev) then
|
||||
throw "Argument 'rev' for fetcher git must be a sha1 hash. Try using 'ref' instead"
|
||||
else if ref != null && b.match "refs/(heads|tags)/.*" ref == null then
|
||||
throw ''ref must be of format "refs/heads/branch-name" or "refs/tags/tag-name"''
|
||||
versionField = "rev";
|
||||
|
||||
outputs = { url, rev }@inp:
|
||||
if b.match "refs/(heads|tags)/.*" rev == null && builtins.match "[a-f0-9]*" rev == null then
|
||||
throw ''rev must either be a sha1 hash or "refs/heads/branch-name" or "refs/tags/tag-name"''
|
||||
else
|
||||
let
|
||||
|
||||
b = builtins;
|
||||
|
||||
ref =
|
||||
if b.match "refs/(heads|tags)/.*" inp.rev != null then
|
||||
inp.rev
|
||||
else
|
||||
null;
|
||||
|
||||
rev =
|
||||
if b.match "refs/(heads|tags)/.*" inp.rev != null then
|
||||
null
|
||||
else
|
||||
inp.rev;
|
||||
|
||||
refAndRev =
|
||||
(lib.optionalAttrs (ref != null) {
|
||||
inherit ref;
|
||||
@ -35,6 +47,7 @@ in
|
||||
(lib.optionalAttrs (rev != null) {
|
||||
inherit rev;
|
||||
});
|
||||
|
||||
in
|
||||
{
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
"rev"
|
||||
];
|
||||
|
||||
versionField = "rev";
|
||||
|
||||
outputs = { owner, repo, rev, ... }@inp:
|
||||
let
|
||||
b = builtins;
|
||||
|
@ -14,6 +14,8 @@
|
||||
"rev"
|
||||
];
|
||||
|
||||
versionField = "rev";
|
||||
|
||||
outputs = { owner, repo, rev, ... }@inp:
|
||||
let
|
||||
b = builtins;
|
||||
|
33
src/fetchers/pypi-sdist/default.nix
Normal file
33
src/fetchers/pypi-sdist/default.nix
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
python3,
|
||||
|
||||
utils,
|
||||
# config
|
||||
allowBuiltinFetchers,
|
||||
...
|
||||
}:
|
||||
{
|
||||
|
||||
inputs = [
|
||||
"pname"
|
||||
"version"
|
||||
];
|
||||
|
||||
versionField = "version";
|
||||
|
||||
outputs = { pname, version, extension ? "tar.gz", ... }@inp:
|
||||
let
|
||||
b = builtins;
|
||||
in
|
||||
{
|
||||
|
||||
calcHash = algo: utils.hashPath algo (b.fetchurl {
|
||||
url = "https://files.pythonhosted.org/packages/${builtins.substring 0 1 pname}/${pname}/${pname}-${version}.${extension}";
|
||||
});
|
||||
|
||||
fetched = hash:
|
||||
python3.pkgs.fetchPypi {
|
||||
inherit pname version extension hash;
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user