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,13 +6,13 @@ 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
@ -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; }) {};
sources_nixpkgs =
if builtins.hasAttr "nixpkgs" sources if builtins.hasAttr "nixpkgs" sources
then sources.nixpkgs then sourcesNixpkgs
else abort else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
import <nixpkgs> {}
else
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;
in # Create the final "sources" from the config
mkSources = config:
mapAttrs ( mapAttrs (
name: spec: name: spec:
if builtins.hasAttr "outPath" spec if builtins.hasAttr "outPath" spec
then abort then abort
"The values in sources.json should not have an 'outPath' attribute" "The values in sources.json should not have an 'outPath' attribute"
else else
spec // { outPath = fetch name spec; } spec // { outPath = fetch config.pkgs name spec; }
) sources ) 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
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }