home

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

sources.nix (4219B)


      1 # This file has been generated by Niv.
      2 let
      3   #
      4   # The fetchers. fetch_<type> fetches specs of type <type>.
      5   #
      6 
      7   fetch_file = pkgs: spec:
      8     if spec.builtin or true then
      9       builtins_fetchurl { inherit (spec) url sha256; }
     10     else
     11       pkgs.fetchurl { inherit (spec) url sha256; };
     12 
     13   fetch_tarball = pkgs: spec:
     14     if spec.builtin or true then
     15       builtins_fetchTarball { inherit (spec) url sha256; }
     16     else
     17       pkgs.fetchzip { inherit (spec) url sha256; };
     18 
     19   fetch_git = spec:
     20     builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
     21 
     22   fetch_builtin-tarball = spec:
     23     builtins.trace
     24       ''
     25         WARNING:
     26           The niv type "builtin-tarball" will soon be deprecated. You should
     27           instead use `builtin = true`.
     28 
     29           $ niv modify <package> -a type=tarball -a builtin=true
     30       ''
     31       builtins_fetchTarball { inherit (spec) url sha256; };
     32 
     33   fetch_builtin-url = spec:
     34     builtins.trace
     35       ''
     36         WARNING:
     37           The niv type "builtin-url" will soon be deprecated. You should
     38           instead use `builtin = true`.
     39 
     40           $ niv modify <package> -a type=file -a builtin=true
     41       ''
     42       (builtins_fetchurl { inherit (spec) url sha256; });
     43 
     44   #
     45   # Various helpers
     46   #
     47 
     48   # The set of packages used when specs are fetched using non-builtins.
     49   mkPkgs = sources:
     50     let
     51       sourcesNixpkgs =
     52         import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { };
     53       hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
     54       hasThisAsNixpkgsPath = <nixpkgs> == ./.;
     55     in
     56     if builtins.hasAttr "nixpkgs" sources
     57     then sourcesNixpkgs
     58     else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
     59       import <nixpkgs> { }
     60     else
     61       abort
     62         ''
     63           Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
     64           add a package called "nixpkgs" to your sources.json.
     65         '';
     66 
     67   # The actual fetching function.
     68   fetch = pkgs: name: spec:
     69 
     70     if ! builtins.hasAttr "type" spec then
     71       abort "ERROR: niv spec ${name} does not have a 'type' attribute"
     72     else if spec.type == "file" then fetch_file pkgs spec
     73     else if spec.type == "tarball" then fetch_tarball pkgs spec
     74     else if spec.type == "git" then fetch_git spec
     75     else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec
     76     else if spec.type == "builtin-url" then fetch_builtin-url spec
     77     else
     78       abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
     79 
     80   # Ports of functions for older nix versions
     81 
     82   # a Nix version of mapAttrs if the built-in doesn't exist
     83   mapAttrs = builtins.mapAttrs or (
     84     f: set: with builtins;
     85     listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
     86   );
     87 
     88   # fetchTarball version that is compatible between all the versions of Nix
     89   builtins_fetchTarball = { url, sha256 }@attrs:
     90     let
     91       inherit (builtins) lessThan nixVersion fetchTarball;
     92     in
     93     if lessThan nixVersion "1.12" then
     94       fetchTarball { inherit url; }
     95     else
     96       fetchTarball attrs;
     97 
     98   # fetchurl version that is compatible between all the versions of Nix
     99   builtins_fetchurl = { url, sha256 }@attrs:
    100     let
    101       inherit (builtins) lessThan nixVersion fetchurl;
    102     in
    103     if lessThan nixVersion "1.12" then
    104       fetchurl { inherit url; }
    105     else
    106       fetchurl attrs;
    107 
    108   # Create the final "sources" from the config
    109   mkSources = config:
    110     mapAttrs
    111       (
    112         name: spec:
    113           if builtins.hasAttr "outPath" spec
    114           then abort
    115             "The values in sources.json should not have an 'outPath' attribute"
    116           else
    117             spec // { outPath = fetch config.pkgs name spec; }
    118       )
    119       config.sources;
    120 
    121   # The "config" used by the fetchers
    122   mkConfig =
    123     { sourcesFile ? ./sources.json
    124     , sources ? builtins.fromJSON (builtins.readFile sourcesFile)
    125     , pkgs ? mkPkgs sources
    126     }: rec {
    127       # The sources, i.e. the attribute set of spec name to spec
    128       inherit sources;
    129 
    130       # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
    131       inherit pkgs;
    132     };
    133 in
    134 mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }