updating niv version

This commit is contained in:
László Vaskó
2020-04-25 19:30:00 +02:00
parent 64df68fa30
commit c7217357bb

View File

@ -6,20 +6,20 @@ let
# The fetchers. fetch_<type> fetches specs of type <type>. # The fetchers. fetch_<type> fetches specs of type <type>.
# #
fetch_file = spec: fetch_file = pkgs: spec:
if spec.builtin or true then if spec.builtin or true then
builtins_fetchurl { inherit (spec) url sha256; } builtins_fetchurl { inherit (spec) url sha256; }
else else
pkgs.fetchurl { inherit (spec) url sha256; }; pkgs.fetchurl { inherit (spec) url sha256; };
fetch_tarball = spec: fetch_tarball = pkgs: spec:
if spec.builtin or true then if spec.builtin or true then
builtins_fetchTarball { inherit (spec) url sha256; } builtins_fetchTarball { inherit (spec) url sha256; }
else else
pkgs.fetchzip { inherit (spec) url sha256; }; pkgs.fetchzip { inherit (spec) url sha256; };
fetch_git = spec: fetch_git = spec:
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
fetch_builtin-tarball = spec: fetch_builtin-tarball = spec:
builtins.trace builtins.trace
@ -43,46 +43,36 @@ let
'' ''
(builtins_fetchurl { inherit (spec) url sha256; }); (builtins_fetchurl { inherit (spec) url sha256; });
#
# The sources to fetch.
#
sources = builtins.fromJSON (builtins.readFile ./sources.json);
# #
# Various helpers # Various helpers
# #
# The set of packages used when specs are fetched using non-builtins. # The set of packages used when specs are fetched using non-builtins.
pkgs = mkPkgs = sources:
if hasNixpkgsPath let
then sourcesNixpkgs =
if hasThisAsNixpkgsPath import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {} hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
else import <nixpkgs> {} hasThisAsNixpkgsPath = <nixpkgs> == ./.;
else in
import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}; if builtins.hasAttr "nixpkgs" sources
then sourcesNixpkgs
sources_nixpkgs = else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
if builtins.hasAttr "nixpkgs" sources import <nixpkgs> {}
then sources.nixpkgs else
else abort abort
'' ''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json. add a package called "nixpkgs" to your sources.json.
''; '';
hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success;
hasThisAsNixpkgsPath =
(builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.;
# The actual fetching function. # The actual fetching function.
fetch = name: spec: fetch = pkgs: name: spec:
if ! builtins.hasAttr "type" spec then if ! builtins.hasAttr "type" spec then
abort "ERROR: niv spec ${name} does not have a 'type' attribute" abort "ERROR: niv spec ${name} does not have a 'type' attribute"
else if spec.type == "file" then fetch_file spec else if spec.type == "file" then fetch_file pkgs spec
else if spec.type == "tarball" then fetch_tarball spec else if spec.type == "tarball" then fetch_tarball pkgs spec
else if spec.type == "git" then fetch_git spec else if spec.type == "git" then fetch_git spec
else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec
else if spec.type == "builtin-url" then fetch_builtin-url spec else if spec.type == "builtin-url" then fetch_builtin-url spec
@ -117,12 +107,28 @@ let
else else
fetchurl attrs; fetchurl attrs;
# Create the final "sources" from the config
mkSources = config:
mapAttrs (
name: spec:
if builtins.hasAttr "outPath" spec
then abort
"The values in sources.json should not have an 'outPath' attribute"
else
spec // { outPath = fetch config.pkgs name spec; }
) config.sources;
# The "config" used by the fetchers
mkConfig =
{ sourcesFile ? ./sources.json
, sources ? builtins.fromJSON (builtins.readFile sourcesFile)
, pkgs ? mkPkgs sources
}: rec {
# The sources, i.e. the attribute set of spec name to spec
inherit sources;
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
inherit pkgs;
};
in in
mapAttrs ( mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
name: spec:
if builtins.hasAttr "outPath" spec
then abort
"The values in sources.json should not have an 'outPath' attribute"
else
spec // { outPath = fetch name spec; }
) sources