|
| 1 | +# This file has been generated by Niv. |
| 2 | + |
| 3 | +# A record, from name to path, of the third-party packages |
| 4 | +with rec |
| 5 | +{ |
| 6 | + pkgs = |
| 7 | + if hasNixpkgsPath |
| 8 | + then |
| 9 | + if hasThisAsNixpkgsPath |
| 10 | + then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {} |
| 11 | + else import <nixpkgs> {} |
| 12 | + else |
| 13 | + import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}; |
| 14 | + |
| 15 | + sources_nixpkgs = |
| 16 | + if builtins.hasAttr "nixpkgs" sources |
| 17 | + then sources.nixpkgs |
| 18 | + else abort |
| 19 | + '' |
| 20 | + Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or |
| 21 | + add a package called "nixpkgs" to your sources.json. |
| 22 | + ''; |
| 23 | + |
| 24 | + # fetchTarball version that is compatible between all the versions of Nix |
| 25 | + builtins_fetchTarball = |
| 26 | + { url, sha256 }@attrs: |
| 27 | + let |
| 28 | + inherit (builtins) lessThan nixVersion fetchTarball; |
| 29 | + in |
| 30 | + if lessThan nixVersion "1.12" then |
| 31 | + fetchTarball { inherit url; } |
| 32 | + else |
| 33 | + fetchTarball attrs; |
| 34 | + |
| 35 | + # fetchurl version that is compatible between all the versions of Nix |
| 36 | + builtins_fetchurl = |
| 37 | + { url, sha256 }@attrs: |
| 38 | + let |
| 39 | + inherit (builtins) lessThan nixVersion fetchurl; |
| 40 | + in |
| 41 | + if lessThan nixVersion "1.12" then |
| 42 | + fetchurl { inherit url; } |
| 43 | + else |
| 44 | + fetchurl attrs; |
| 45 | + |
| 46 | + # A wrapper around pkgs.fetchzip that has inspectable arguments, |
| 47 | + # annoyingly this means we have to specify them |
| 48 | + fetchzip = { url, sha256 }@attrs: pkgs.fetchzip attrs; |
| 49 | + |
| 50 | + # A wrapper around pkgs.fetchurl that has inspectable arguments, |
| 51 | + # annoyingly this means we have to specify them |
| 52 | + fetchurl = { url, sha256 }@attrs: pkgs.fetchurl attrs; |
| 53 | + |
| 54 | + hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success; |
| 55 | + hasThisAsNixpkgsPath = |
| 56 | + (builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.; |
| 57 | + |
| 58 | + sources = builtins.fromJSON (builtins.readFile ./sources.json); |
| 59 | + |
| 60 | + mapAttrs = builtins.mapAttrs or |
| 61 | + (f: set: with builtins; |
| 62 | + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))); |
| 63 | + |
| 64 | + # borrowed from nixpkgs |
| 65 | + functionArgs = f: f.__functionArgs or (builtins.functionArgs f); |
| 66 | + callFunctionWith = autoArgs: f: args: |
| 67 | + let auto = builtins.intersectAttrs (functionArgs f) autoArgs; |
| 68 | + in f (auto // args); |
| 69 | + |
| 70 | + getFetcher = spec: |
| 71 | + let fetcherName = |
| 72 | + if builtins.hasAttr "type" spec |
| 73 | + then builtins.getAttr "type" spec |
| 74 | + else "builtin-tarball"; |
| 75 | + in builtins.getAttr fetcherName { |
| 76 | + "tarball" = fetchzip; |
| 77 | + "builtin-tarball" = builtins_fetchTarball; |
| 78 | + "file" = fetchurl; |
| 79 | + "builtin-url" = builtins_fetchurl; |
| 80 | + }; |
| 81 | +}; |
| 82 | +# NOTE: spec must _not_ have an "outPath" attribute |
| 83 | +mapAttrs (_: spec: |
| 84 | + if builtins.hasAttr "outPath" spec |
| 85 | + then abort |
| 86 | + "The values in sources.json should not have an 'outPath' attribute" |
| 87 | + else |
| 88 | + if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec |
| 89 | + then |
| 90 | + spec // |
| 91 | + { outPath = callFunctionWith spec (getFetcher spec) { }; } |
| 92 | + else spec |
| 93 | + ) sources |
0 commit comments