mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-08-16 18:00:30 +03:00
feature: sourceOverrides
This commit is contained in:
parent
76ae17fc27
commit
d23fb76ef6
@ -22,6 +22,7 @@
|
||||
|
||||
dream2nixFor = forAllSystems (system: import ./src rec {
|
||||
pkgs = nixpkgsFor."${system}";
|
||||
inherit lib;
|
||||
externalSources = pkgs.runCommand "dream2nix-imported" {} ''
|
||||
mkdir -p $out/npmlock2nix
|
||||
cp ${npmlock2nix}/{internal.nix,LICENSE} $out/npmlock2nix/
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
callPackage,
|
||||
...
|
||||
}:
|
||||
{
|
||||
python = rec {
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
{
|
||||
@ -20,7 +21,7 @@ python.pkgs.buildPythonPackage {
|
||||
nativeBuildInputs = [ pkgs.autoPatchelfHook python.pkgs.wheelUnpackHook ];
|
||||
unpackPhase = ''
|
||||
mkdir dist
|
||||
for file in ${lib.attrValues fetchedSources}; do
|
||||
for file in ${builtins.toString (lib.attrValues fetchedSources)}; do
|
||||
# pick right most element of path
|
||||
fname=''${file##*/}
|
||||
fname=$(stripHash $fname)
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> {},
|
||||
lib ? pkgs.lib,
|
||||
externalSources ?
|
||||
if builtins.getEnv "d2nExternalSources" != "" then
|
||||
builtins.getEnv "d2nExternalSources"
|
||||
@ -63,17 +64,37 @@ rec {
|
||||
{
|
||||
genericLock,
|
||||
builder ? findBuilder (parseLock genericLock),
|
||||
fetcher ? findFetcher (parseLock genericLock)
|
||||
fetcher ? findFetcher (parseLock genericLock),
|
||||
sourceOverrides ? oldSources: {},
|
||||
}:
|
||||
let
|
||||
# is generic lock is a file, read and parse it
|
||||
# if generic lock is a file, read and parse it
|
||||
genericLock' = (parseLock genericLock);
|
||||
fetched = fetcher {
|
||||
sources = genericLock'.sources;
|
||||
sourcesCombinedHash = genericLock'.generic.sourcesCombinedHash;
|
||||
};
|
||||
sourcesToReplace = sourceOverrides fetched.fetchedSources;
|
||||
sourcesOverridden = lib.mapAttrs (pname: source:
|
||||
sourcesToReplace."${pname}" or source
|
||||
) fetched.fetchedSources;
|
||||
sourcesEnsuredOverridden = lib.mapAttrs (pname: source:
|
||||
if source == "unknown" then throw ''
|
||||
Source '${pname}' is unknown. Please override using:
|
||||
dream2nix.buildPackage {
|
||||
...
|
||||
sourceOverrides = oldSources: {
|
||||
"${pname}" = ...;
|
||||
};
|
||||
...
|
||||
};
|
||||
''
|
||||
else source
|
||||
) sourcesOverridden;
|
||||
in
|
||||
fetched;
|
||||
fetched // {
|
||||
fetchedSources = sourcesEnsuredOverridden;
|
||||
};
|
||||
|
||||
|
||||
# automatically build package defined by generic lock
|
||||
@ -81,10 +102,11 @@ rec {
|
||||
{
|
||||
genericLock,
|
||||
builder ? findBuilder (parseLock genericLock),
|
||||
fetcher ? findFetcher (parseLock genericLock)
|
||||
fetcher ? findFetcher (parseLock genericLock),
|
||||
sourceOverrides ? oldSources: {},
|
||||
}@args:
|
||||
let
|
||||
# is generic lock is a file, read and parse it
|
||||
# if generic lock is a file, read and parse it
|
||||
genericLock' = (parseLock genericLock);
|
||||
in
|
||||
builder {
|
||||
|
@ -23,9 +23,9 @@ let
|
||||
defaultFetched = (defaultFetcher { inherit sources; }).fetchedSources;
|
||||
|
||||
# extract the arguments from the individual fetcher calls
|
||||
fetcherArgsAll =
|
||||
FODArgsAll =
|
||||
let
|
||||
fetcherArgsAll' =
|
||||
FODArgsAll' =
|
||||
lib.mapAttrs
|
||||
(pname: fetched:
|
||||
|
||||
@ -35,24 +35,20 @@ let
|
||||
passthru.originalArgs = args;
|
||||
})).originalArgs
|
||||
|
||||
# handle non-FOD sources
|
||||
else if lib.isDerivation fetched || lib.isStorePath fetched then
|
||||
null
|
||||
# handle unknown sources
|
||||
else if fetched == "unknown" then
|
||||
"unknown"
|
||||
|
||||
# error out on unknown source types
|
||||
else
|
||||
throw ''
|
||||
Error while generating FOD fetcher for combined sources.
|
||||
Cannot classify source of '${pname}'.
|
||||
Known source types:
|
||||
- FOD
|
||||
- derivation
|
||||
- store path
|
||||
''
|
||||
)
|
||||
defaultFetched;
|
||||
in
|
||||
lib.filterAttrs (pname: fetcherArgs: fetcherArgs != null) fetcherArgsAll';
|
||||
lib.filterAttrs (pname: fetcherArgs: fetcherArgs != "unknown") FODArgsAll';
|
||||
|
||||
# convert arbitrary types to string, like nix does with derivation arguments
|
||||
toString = x:
|
||||
@ -99,7 +95,7 @@ let
|
||||
popd
|
||||
rm -r workdir
|
||||
export out=$OUT_ORIG
|
||||
'') fetcherArgsAll )}
|
||||
'') FODArgsAll )}
|
||||
|
||||
echo "FOD_PATH=$(${nix}/bin/nix hash-path $out)"
|
||||
'';
|
||||
@ -109,7 +105,7 @@ let
|
||||
nativeBuildInputs' = lib.foldl (a: b: a ++ b) [] (
|
||||
lib.mapAttrsToList
|
||||
(pname: fetcherArgs: (fetcherArgs.nativeBuildInputs or []))
|
||||
fetcherArgsAll
|
||||
FODArgsAll
|
||||
);
|
||||
in
|
||||
stdenv.mkDerivation rec {
|
||||
@ -130,9 +126,9 @@ in
|
||||
fetchedSources =
|
||||
# attrset: pname -> path of downloaded source
|
||||
lib.genAttrs (lib.attrNames sources) (pname:
|
||||
if fetcherArgsAll ? "${pname}" then
|
||||
"${FODAllSources}/${fetcherArgsAll."${pname}".name}"
|
||||
if FODArgsAll ? "${pname}" then
|
||||
"${FODAllSources}/${FODArgsAll."${pname}".name}"
|
||||
else
|
||||
sources."${pname}"
|
||||
defaultFetched."${pname}"
|
||||
);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@
|
||||
sha256 = source.hash or null;
|
||||
}
|
||||
else if source.type == "unknown" then
|
||||
null
|
||||
"unknown"
|
||||
else throw "unsupported source type '${source.type}'"
|
||||
) sources;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user