2020-10-28 06:15:08 +00:00
|
|
|
{
|
2020-11-17 11:29:44 +00:00
|
|
|
condaChannelsExtra ? {},
|
2020-10-28 06:15:08 +00:00
|
|
|
pkgs ? import (import ./nixpkgs-src.nix) {},
|
2020-11-17 11:29:44 +00:00
|
|
|
providers ? builtins.fromJSON (builtins.readFile (builtins.getEnv "providers")),
|
2020-10-28 06:15:08 +00:00
|
|
|
system ? "x86_64-linux",
|
2020-11-17 11:29:44 +00:00
|
|
|
|
|
|
|
# conda-channels index
|
2020-10-28 06:15:08 +00:00
|
|
|
repoName ? "conda-channels",
|
|
|
|
repoOwner ? "DavHau",
|
2020-11-20 17:08:20 +00:00
|
|
|
condaDataRev ? (builtins.fromJSON (builtins.readFile ./CONDA_CHANNELS.json)).rev,
|
|
|
|
condaDataSha256 ? (builtins.fromJSON (builtins.readFile ./CONDA_CHANNELS.json)).indexSha256
|
2020-10-28 06:15:08 +00:00
|
|
|
}:
|
|
|
|
with builtins;
|
|
|
|
with pkgs.lib;
|
|
|
|
let
|
2020-11-17 11:29:44 +00:00
|
|
|
|
2020-10-28 06:15:08 +00:00
|
|
|
systemMap = {
|
|
|
|
x86_64-linux = "linux-64";
|
|
|
|
x86_64-darwin = "osx-64";
|
2022-02-02 00:01:07 +00:00
|
|
|
aarch64-darwin = "osx-arm64";
|
2020-10-28 06:15:08 +00:00
|
|
|
aarch64-linux = "linux-aarch64";
|
|
|
|
};
|
2020-11-17 11:29:44 +00:00
|
|
|
|
|
|
|
allProviders = flatten (attrValues providers);
|
|
|
|
|
|
|
|
usedChannels =
|
|
|
|
filter (p: p != null)
|
|
|
|
(map (p: if hasPrefix "conda/" p then removePrefix "conda/" p else null) allProviders);
|
|
|
|
|
|
|
|
channelRegistry = fromJSON (readFile (fetchurl {
|
2020-10-28 06:15:08 +00:00
|
|
|
name = "conda-channels-index";
|
2020-11-20 17:08:20 +00:00
|
|
|
url = "https://raw.githubusercontent.com/${repoOwner}/${repoName}/${condaDataRev}/sha256.json";
|
|
|
|
sha256 = condaDataSha256;
|
2020-10-28 06:15:08 +00:00
|
|
|
}));
|
2020-11-17 11:29:44 +00:00
|
|
|
|
2021-06-08 12:16:14 +00:00
|
|
|
registryChannels = foldl' (a: b: recursiveUpdate a b) {} (mapAttrsToList (path: sha256:
|
2020-11-17 11:29:44 +00:00
|
|
|
let
|
2021-06-08 12:16:14 +00:00
|
|
|
split = splitString "/" path;
|
2020-11-17 11:29:44 +00:00
|
|
|
chan = elemAt split 1;
|
2021-06-08 12:16:14 +00:00
|
|
|
file = last split;
|
|
|
|
sys = head (splitString "." file);
|
|
|
|
part = elemAt (splitString "." file) 1;
|
|
|
|
in {
|
|
|
|
"${chan}" = {
|
|
|
|
"${sys}" = {
|
|
|
|
"${part}" = sha256;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
) channelRegistry);
|
2020-11-17 11:29:44 +00:00
|
|
|
|
2021-06-08 12:16:14 +00:00
|
|
|
channelFiles = chan: flatten (forEach [ systemMap."${system}" "noarch" ] (sys:
|
|
|
|
if registryChannels ? "${chan}"."${sys}" then
|
|
|
|
mapAttrsToList (part: sha256: builtins.fetchurl {
|
|
|
|
url = "https://raw.githubusercontent.com/${repoOwner}/${repoName}/${condaDataRev}/channels/${chan}/${sys}.${part}.json";
|
|
|
|
sha256 = channelRegistry."channels/${chan}/${sys}.${part}.json";
|
|
|
|
}) registryChannels."${chan}"."${sys}"
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
));
|
|
|
|
|
|
|
|
_selectedRegistryChannels =
|
|
|
|
|
|
|
|
genAttrs usedChannels (chan: channelFiles chan);
|
2020-11-17 11:29:44 +00:00
|
|
|
|
|
|
|
_condaChannelsExtra = filterAttrs (chan: json: elem chan usedChannels) condaChannelsExtra;
|
|
|
|
|
2021-06-08 12:16:14 +00:00
|
|
|
allCondaChannels = (_selectedRegistryChannels // _condaChannelsExtra);
|
2020-11-17 11:29:44 +00:00
|
|
|
|
|
|
|
condaChannelsJson = pkgs.writeText "conda-channels.json" (toJSON allCondaChannels);
|
2020-11-18 18:09:56 +00:00
|
|
|
|
|
|
|
missingChannels = filter (c:
|
|
|
|
! elem c ((attrNames registryChannels) ++ (attrNames condaChannelsExtra))
|
|
|
|
) usedChannels;
|
|
|
|
|
2020-10-28 06:15:08 +00:00
|
|
|
in
|
2020-11-18 18:09:56 +00:00
|
|
|
if missingChannels != [] then
|
|
|
|
throw "Conda channels [${toString missingChannels}] are unknown. Use 'condaChannelsExtra' to make them available"
|
2021-06-09 17:07:19 +00:00
|
|
|
else let
|
|
|
|
channelNames = (attrNames allCondaChannels); in
|
|
|
|
if channelNames != [] then
|
|
|
|
trace "using conda channels: ${toString (concatStringsSep ", " (attrNames allCondaChannels))}"
|
|
|
|
{ inherit condaChannelsJson; }
|
|
|
|
else
|
|
|
|
{ inherit condaChannelsJson; }
|