mirror of
https://github.com/nmattia/niv.git
synced 2024-11-23 06:22:50 +03:00
Support more types, including builtins
This commit is contained in:
parent
30f55f14e1
commit
0c48736b06
@ -21,9 +21,8 @@ with rec
|
|||||||
add a package called "nixpkgs" to your sources.json.
|
add a package called "nixpkgs" to your sources.json.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
# fetchTarball version that is compatible between all the versions of Nix
|
||||||
builtins_fetchTarball =
|
builtins_fetchTarball =
|
||||||
# fetchTarball version that is compatible between all the versions of
|
|
||||||
# Nix
|
|
||||||
{ url, sha256 }@attrs:
|
{ url, sha256 }@attrs:
|
||||||
let
|
let
|
||||||
inherit (builtins) lessThan nixVersion fetchTarball;
|
inherit (builtins) lessThan nixVersion fetchTarball;
|
||||||
@ -33,6 +32,21 @@ with rec
|
|||||||
else
|
else
|
||||||
fetchTarball attrs;
|
fetchTarball attrs;
|
||||||
|
|
||||||
|
# fetchurl version that is compatible between all the versions of Nix
|
||||||
|
builtins_fetchurl =
|
||||||
|
{ url, sha256 }@attrs:
|
||||||
|
let
|
||||||
|
inherit (builtins) lessThan nixVersion fetchurl;
|
||||||
|
in
|
||||||
|
if lessThan nixVersion "1.12" then
|
||||||
|
fetchurl { inherit url; }
|
||||||
|
else
|
||||||
|
fetchurl attrs;
|
||||||
|
|
||||||
|
# A wrapper around pkgs.fetchzip that has inspectable arguments,
|
||||||
|
# annoyingly this means we have to specify them
|
||||||
|
fetchzip = { url, sha256 }@attrs: pkgs.fetchzip attrs;
|
||||||
|
|
||||||
hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success;
|
hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success;
|
||||||
hasThisAsNixpkgsPath =
|
hasThisAsNixpkgsPath =
|
||||||
(builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.;
|
(builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.;
|
||||||
@ -43,14 +57,22 @@ with rec
|
|||||||
(f: set: with builtins;
|
(f: set: with builtins;
|
||||||
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));
|
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));
|
||||||
|
|
||||||
|
# borrowed from nixpkgs
|
||||||
|
functionArgs = f: f.__functionArgs or (builtins.functionArgs f);
|
||||||
|
callFunctionWith = autoArgs: f: args:
|
||||||
|
let auto = builtins.intersectAttrs (functionArgs f) autoArgs;
|
||||||
|
in f (auto // args);
|
||||||
|
|
||||||
getFetcher = spec:
|
getFetcher = spec:
|
||||||
let fetcherName =
|
let fetcherName =
|
||||||
if builtins.hasAttr "type" spec
|
if builtins.hasAttr "type" spec
|
||||||
then builtins.getAttr "type" spec
|
then builtins.getAttr "type" spec
|
||||||
else "tarball";
|
else "tarball";
|
||||||
in builtins.getAttr fetcherName {
|
in builtins.getAttr fetcherName {
|
||||||
"tarball" = pkgs.fetchzip;
|
"tarball" = fetchzip;
|
||||||
|
"builtin-tarball" = builtins_fetchTarball;
|
||||||
"file" = pkgs.fetchurl;
|
"file" = pkgs.fetchurl;
|
||||||
|
"builtin-url" = builtins_fetchurl;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
# NOTE: spec must _not_ have an "outPath" attribute
|
# NOTE: spec must _not_ have an "outPath" attribute
|
||||||
@ -62,6 +84,6 @@ mapAttrs (_: spec:
|
|||||||
if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec
|
if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec
|
||||||
then
|
then
|
||||||
spec //
|
spec //
|
||||||
{ outPath = getFetcher spec { inherit (spec) url sha256; } ; }
|
{ outPath = callFunctionWith spec (getFetcher spec) { }; }
|
||||||
else spec
|
else spec
|
||||||
) sources
|
) sources
|
||||||
|
Loading…
Reference in New Issue
Block a user