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:
Yusuf Bera Ertan 2021-11-30 08:20:27 +03:00 committed by GitHub
parent c5126b2053
commit 0903f5ea43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 48 additions and 51 deletions

View File

@ -8,10 +8,7 @@
}:
{
inputs = [
"pname"
"version"
];
inputs = [ "pname" "version" ];
versionField = "version";

View File

@ -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;

View File

@ -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

View File

@ -7,14 +7,10 @@
...
}:
{
inputs = [
"pname"
"version"
];
inputs = [ "pname" "version" ];
versionField = "version";
# defaultUpdater = "";
outputs = { pname, version, }@inp:

View File

@ -7,10 +7,7 @@
}:
{
inputs = [
"pname"
"version"
];
inputs = [ "pname" "version" ];
versionField = "version";

View File

@ -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
}
},

View File

@ -200,8 +200,6 @@
crates-io = dependencyObject:
{
pname = dependencyObject.name;
version = dependencyObject.version;
hash = dependencyObject.checksum;
};
};

View File

@ -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;