mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-29 01:14:09 +03:00
feat: pass version and pname to fetchers (#60)
* feat: pass version and pname to fetchers, adjust schema for new behaviour * fix: name -> pname * refactor: move override warning to simpleTranslate, flatten dependencyInfo
This commit is contained in:
parent
c5126b2053
commit
0903f5ea43
@ -8,10 +8,7 @@
|
||||
}:
|
||||
{
|
||||
|
||||
inputs = [
|
||||
"pname"
|
||||
"version"
|
||||
];
|
||||
inputs = [ "pname" "version" ];
|
||||
|
||||
versionField = "version";
|
||||
|
||||
|
@ -33,7 +33,12 @@ let
|
||||
else
|
||||
"${fetchedSources."${mainPackageName}"."${mainPackageVersion}"}/${source.path}"
|
||||
else if fetchers.fetchers ? "${source.type}" then
|
||||
fetchSource { inherit source; sourceVersion = version; }
|
||||
fetchSource {
|
||||
source = source // {
|
||||
pname = name;
|
||||
inherit version;
|
||||
};
|
||||
}
|
||||
else throw "unsupported source type '${source.type}'")
|
||||
versions)
|
||||
sources;
|
||||
|
@ -25,17 +25,15 @@ rec {
|
||||
constructSource =
|
||||
{
|
||||
type,
|
||||
sourceVersion ? null,
|
||||
reComputeHash ? false,
|
||||
...
|
||||
}@args:
|
||||
let
|
||||
fetcher = fetchers."${type}";
|
||||
argsKeep = b.removeAttrs args [ "reComputeHash" "version" ];
|
||||
versionAttrset = lib.optionalAttrs (sourceVersion != null) { version = sourceVersion; };
|
||||
fetcherOutputs = fetcher.outputs (args // versionAttrset);
|
||||
argsKeep = b.removeAttrs args [ "reComputeHash" ];
|
||||
fetcherOutputs = fetcher.outputs argsKeep;
|
||||
in
|
||||
argsKeep
|
||||
(b.removeAttrs argsKeep [ "pname" "version" ])
|
||||
# if the hash was not provided, calculate hash on the fly (impure)
|
||||
// (lib.optionalAttrs reComputeHash {
|
||||
hash = fetcherOutputs.calcHash "sha256";
|
||||
@ -45,7 +43,6 @@ rec {
|
||||
updateSource =
|
||||
{
|
||||
source,
|
||||
sourceVersion,
|
||||
newVersion,
|
||||
...
|
||||
}:
|
||||
@ -55,18 +52,16 @@ rec {
|
||||
in
|
||||
constructSource (argsKeep // {
|
||||
reComputeHash = true;
|
||||
version = sourceVersion;
|
||||
} // {
|
||||
"${fetcher.versionField}" = newVersion;
|
||||
});
|
||||
|
||||
# fetch a source defined via a dream lock source spec
|
||||
fetchSource = { source, sourceVersion ? null, extract ? false, }:
|
||||
fetchSource = { source, extract ? false }:
|
||||
let
|
||||
fetcher = fetchers."${source.type}";
|
||||
fetcherArgs = b.removeAttrs source [ "dir" "hash" "type" ];
|
||||
versionAttrset = lib.optionalAttrs (sourceVersion != null) { version = sourceVersion; };
|
||||
fetcherOutputs = fetcher.outputs (fetcherArgs // versionAttrset);
|
||||
fetcherOutputs = fetcher.outputs fetcherArgs;
|
||||
maybeArchive = fetcherOutputs.fetched (source.hash or null);
|
||||
in
|
||||
if source ? dir then
|
||||
|
@ -7,14 +7,10 @@
|
||||
...
|
||||
}:
|
||||
{
|
||||
|
||||
inputs = [
|
||||
"pname"
|
||||
"version"
|
||||
];
|
||||
|
||||
inputs = [ "pname" "version" ];
|
||||
|
||||
versionField = "version";
|
||||
|
||||
|
||||
# defaultUpdater = "";
|
||||
|
||||
outputs = { pname, version, }@inp:
|
||||
|
@ -7,10 +7,7 @@
|
||||
}:
|
||||
{
|
||||
|
||||
inputs = [
|
||||
"pname"
|
||||
"version"
|
||||
];
|
||||
inputs = [ "pname" "version" ];
|
||||
|
||||
versionField = "version";
|
||||
|
||||
|
@ -82,13 +82,11 @@
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"pname": { "type": "string" },
|
||||
"version": { "type": "string" },
|
||||
"hash": { "type": "string" },
|
||||
"type": { "type": "string" },
|
||||
"dir": { "type": "string" }
|
||||
},
|
||||
"required": ["type", "pname"],
|
||||
"required": ["type"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
@ -112,13 +110,11 @@
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"pname": { "type": "string" },
|
||||
"version": { "type": "string" },
|
||||
"hash": { "type": "string" },
|
||||
"type": { "type": "string" },
|
||||
"dir": { "type": "string" }
|
||||
},
|
||||
"required": ["type", "pname"],
|
||||
"required": ["type"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
@ -128,12 +124,10 @@
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"pname": { "type": "string" },
|
||||
"version": { "type": "string" },
|
||||
"hash": { "type": "string" },
|
||||
"type": { "type": "string" }
|
||||
},
|
||||
"required": ["type", "pname"],
|
||||
"required": ["type"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
|
@ -200,8 +200,6 @@
|
||||
|
||||
crates-io = dependencyObject:
|
||||
{
|
||||
pname = dependencyObject.name;
|
||||
version = dependencyObject.version;
|
||||
hash = dependencyObject.checksum;
|
||||
};
|
||||
};
|
||||
|
@ -10,6 +10,17 @@ let
|
||||
|
||||
b = builtins;
|
||||
|
||||
overrideWarning = fields: args:
|
||||
lib.filterAttrs (name: _:
|
||||
if lib.any (field: name == field) fields
|
||||
then lib.warn ''
|
||||
you are trying to pass a "${name}" key from your source
|
||||
constructor, this will be overrided with a value passed
|
||||
by dream2nix.
|
||||
'' false
|
||||
else true
|
||||
) args;
|
||||
|
||||
simpleTranslate = translatorName:
|
||||
{
|
||||
# values
|
||||
@ -52,22 +63,26 @@ let
|
||||
serializedPackagesList;
|
||||
|
||||
sources = b.foldl'
|
||||
(result: pkgData: lib.recursiveUpdate result {
|
||||
"${getName pkgData}" =
|
||||
let pkgVersion = getVersion pkgData; in {
|
||||
"${pkgVersion}" =
|
||||
let
|
||||
type = getSourceType pkgData;
|
||||
constructedArgs =
|
||||
(sourceConstructors."${type}" pkgData)
|
||||
// {
|
||||
(result: pkgData:
|
||||
let
|
||||
pkgName = getName pkgData;
|
||||
pkgVersion = getVersion pkgData;
|
||||
in lib.recursiveUpdate result {
|
||||
"${pkgName}" = {
|
||||
"${pkgVersion}" =
|
||||
let
|
||||
type = getSourceType pkgData;
|
||||
constructedArgs = sourceConstructors."${type}" pkgData;
|
||||
constructedArgsKeep =
|
||||
overrideWarning [ "pname" "version" ] constructedArgs;
|
||||
in
|
||||
fetchers.constructSource (constructedArgsKeep // {
|
||||
inherit type;
|
||||
pname = pkgName;
|
||||
version = pkgVersion;
|
||||
};
|
||||
in
|
||||
fetchers.constructSource constructedArgs;
|
||||
};
|
||||
})
|
||||
});
|
||||
};
|
||||
})
|
||||
{}
|
||||
serializedPackagesList;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user