2022-04-20 16:41:20 +02:00
|
|
|
# Copyright 2022 The TVL Contributors
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2019-08-14 00:03:16 +02:00
|
|
|
|
2019-09-08 22:53:22 +02:00
|
|
|
# Load a Nix package set from one of the supported source types
|
|
|
|
# (nixpkgs, git, path).
|
|
|
|
{ srcType, srcArgs, importArgs ? { } }:
|
2019-08-14 00:03:16 +02:00
|
|
|
|
|
|
|
with builtins;
|
|
|
|
let
|
|
|
|
# If a nixpkgs channel is requested, it is retrieved from Github (as
|
|
|
|
# a tarball) and imported.
|
|
|
|
fetchImportChannel = channel:
|
|
|
|
let
|
|
|
|
url =
|
2021-04-13 16:20:06 +02:00
|
|
|
"https://github.com/NixOS/nixpkgs/archive/${channel}.tar.gz";
|
2022-04-20 16:41:20 +02:00
|
|
|
in
|
|
|
|
import (fetchTarball url) importArgs;
|
2019-08-14 00:03:16 +02:00
|
|
|
|
|
|
|
# If a git repository is requested, it is retrieved via
|
|
|
|
# builtins.fetchGit which defaults to the git configuration of the
|
|
|
|
# outside environment. This means that user-configured SSH
|
|
|
|
# credentials etc. are going to work as expected.
|
2019-09-08 22:53:22 +02:00
|
|
|
fetchImportGit = spec: import (fetchGit spec) importArgs;
|
2019-08-14 00:03:16 +02:00
|
|
|
|
|
|
|
# No special handling is used for paths, so users are expected to pass one
|
|
|
|
# that will work natively with Nix.
|
2019-09-08 22:53:22 +02:00
|
|
|
importPath = path: import (toPath path) importArgs;
|
2022-04-20 16:41:20 +02:00
|
|
|
in
|
|
|
|
if srcType == "nixpkgs" then
|
2019-09-08 22:53:22 +02:00
|
|
|
fetchImportChannel srcArgs
|
|
|
|
else if srcType == "git" then
|
|
|
|
fetchImportGit (fromJSON srcArgs)
|
|
|
|
else if srcType == "path" then
|
|
|
|
importPath srcArgs
|
2019-08-14 00:03:16 +02:00
|
|
|
else
|
2019-09-08 22:53:22 +02:00
|
|
|
throw ("Invalid package set source specification: ${srcType} (${srcArgs})")
|