1
1
mirror of https://github.com/nmattia/niv.git synced 2024-11-08 08:26:02 +03:00
niv/nix/sources.nix

90 lines
2.7 KiB
Nix
Raw Normal View History

# This file has been generated by Niv.
2019-01-31 21:05:00 +03:00
# A record, from name to path, of the third-party packages
with rec
2019-01-31 21:05:00 +03:00
{
pkgs =
if hasNixpkgsPath
then
if hasThisAsNixpkgsPath
2019-04-11 00:10:46 +03:00
then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}
else import <nixpkgs> {}
else
2019-04-11 00:10:46 +03:00
import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {};
sources_nixpkgs =
if builtins.hasAttr "nixpkgs" sources
then sources.nixpkgs
else abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';
2019-05-23 22:36:18 +03:00
# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball =
{ url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball { inherit url; }
else
fetchTarball attrs;
2019-05-23 22:36:18 +03:00
# 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;
hasThisAsNixpkgsPath =
(builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.;
sources = builtins.fromJSON (builtins.readFile ./sources.json);
2019-01-31 21:05:00 +03:00
2019-02-01 17:51:40 +03:00
mapAttrs = builtins.mapAttrs or
(f: set: with builtins;
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));
2019-01-31 21:05:00 +03:00
2019-05-23 22:36:18 +03:00
# 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:
let fetcherName =
if builtins.hasAttr "type" spec
then builtins.getAttr "type" spec
2019-05-23 22:36:39 +03:00
else "builtin-tarball";
in builtins.getAttr fetcherName {
2019-05-23 22:36:18 +03:00
"tarball" = fetchzip;
"builtin-tarball" = builtins_fetchTarball;
"file" = pkgs.fetchurl;
2019-05-23 22:36:18 +03:00
"builtin-url" = builtins_fetchurl;
};
};
2019-01-31 21:05:00 +03:00
# NOTE: spec must _not_ have an "outPath" attribute
2019-02-01 17:51:40 +03:00
mapAttrs (_: spec:
2019-01-31 21:05:00 +03:00
if builtins.hasAttr "outPath" spec
then abort
"The values in sources.json should not have an 'outPath' attribute"
2019-01-31 21:05:00 +03:00
else
if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec
then
spec //
2019-05-23 22:36:18 +03:00
{ outPath = callFunctionWith spec (getFetcher spec) { }; }
2019-01-31 21:05:00 +03:00
else spec
) sources