|
| 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 | + sources_gitignore = |
| 25 | + if builtins.hasAttr "gitignore" sources |
| 26 | + then sources.gitignore |
| 27 | + else abort |
| 28 | + '' |
| 29 | + Please add "gitignore" to your sources.json: |
| 30 | + niv add hercules-ci/gitignore |
| 31 | + ''; |
| 32 | + |
| 33 | + inherit (import (builtins_fetchTarball { inherit (sources_gitignore) url sha256; }) { |
| 34 | + inherit (pkgs) lib; |
| 35 | + }) gitignoreSource; |
| 36 | + |
| 37 | + # fetchTarball version that is compatible between all the versions of Nix |
| 38 | + builtins_fetchTarball = |
| 39 | + { url, sha256 ? null }@attrs: |
| 40 | + let |
| 41 | + inherit (builtins) lessThan nixVersion fetchTarball; |
| 42 | + in |
| 43 | + if sha256 == null || lessThan nixVersion "1.12" then |
| 44 | + fetchTarball { inherit url; } |
| 45 | + else |
| 46 | + fetchTarball attrs; |
| 47 | + |
| 48 | + # fetchurl version that is compatible between all the versions of Nix |
| 49 | + builtins_fetchurl = |
| 50 | + { url, sha256 ? null }@attrs: |
| 51 | + let |
| 52 | + inherit (builtins) lessThan nixVersion fetchurl; |
| 53 | + in |
| 54 | + if sha256 == null || lessThan nixVersion "1.12" then |
| 55 | + fetchurl { inherit url; } |
| 56 | + else |
| 57 | + fetchurl attrs; |
| 58 | + |
| 59 | + # A wrapper around pkgs.fetchzip that has inspectable arguments, |
| 60 | + # annoyingly this means we have to specify them |
| 61 | + fetchzip = { url, sha256 ? null }@attrs: if sha256 == null |
| 62 | + then builtins.fetchTarball { inherit url; } |
| 63 | + else pkgs.fetchzip attrs; |
| 64 | + |
| 65 | + # A wrapper around pkgs.fetchurl that has inspectable arguments, |
| 66 | + # annoyingly this means we have to specify them |
| 67 | + fetchurl = { url, sha256 }@attrs: pkgs.fetchurl attrs; |
| 68 | + |
| 69 | + hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success; |
| 70 | + hasThisAsNixpkgsPath = |
| 71 | + (builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.; |
| 72 | + |
| 73 | + sources = builtins.fromJSON (builtins.readFile ./sources.json); |
| 74 | + |
| 75 | + mapAttrs = builtins.mapAttrs or |
| 76 | + (f: set: with builtins; |
| 77 | + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))); |
| 78 | + |
| 79 | + # borrowed from nixpkgs |
| 80 | + functionArgs = f: f.__functionArgs or (builtins.functionArgs f); |
| 81 | + callFunctionWith = autoArgs: f: args: |
| 82 | + let auto = builtins.intersectAttrs (functionArgs f) autoArgs; |
| 83 | + in f (auto // args); |
| 84 | + |
| 85 | + getFetcher = spec: |
| 86 | + let fetcherName = |
| 87 | + if builtins.hasAttr "type" spec |
| 88 | + then builtins.getAttr "type" spec |
| 89 | + else "builtin-tarball"; |
| 90 | + in builtins.getAttr fetcherName { |
| 91 | + "tarball" = fetchzip; |
| 92 | + "builtin-tarball" = builtins_fetchTarball; |
| 93 | + "file" = fetchurl; |
| 94 | + "builtin-url" = builtins_fetchurl; |
| 95 | + }; |
| 96 | +}; |
| 97 | +# NOTE: spec must _not_ have an "outPath" attribute |
| 98 | +mapAttrs (name: spec: |
| 99 | + if builtins.hasAttr "outPath" spec |
| 100 | + then abort |
| 101 | + "The values in sources.json should not have an 'outPath' attribute" |
| 102 | + else |
| 103 | + let |
| 104 | + host = if (name == "nixpkgs") then "custom_nixpkgs" else name; |
| 105 | + tryFromPath = builtins.tryEval (builtins.findFile builtins.nixPath host); |
| 106 | + defaultSpec = (if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec |
| 107 | + then spec // |
| 108 | + { outPath = callFunctionWith spec (getFetcher spec) { }; } |
| 109 | + else spec) // (if tryFromPath.success |
| 110 | + then let path = tryFromPath.value; |
| 111 | + in { |
| 112 | + outPath = builtins.trace "using search host <${host}>" ( |
| 113 | + if pkgs.lib.hasPrefix "/nix/store" (builtins.toString path) |
| 114 | + then path else gitignoreSource path); |
| 115 | + } |
| 116 | + else {}); |
| 117 | + in if builtins.hasAttr "rev" spec && builtins.hasAttr "url" spec then |
| 118 | + defaultSpec // |
| 119 | + { revOverride = rev: if (rev == null) then defaultSpec else |
| 120 | + let |
| 121 | + spec' = removeAttrs (spec // { |
| 122 | + rev = rev; |
| 123 | + url = builtins.replaceStrings [defaultSpec.rev] [rev] defaultSpec.url; |
| 124 | + }) [ "sha256" ]; |
| 125 | + in |
| 126 | + spec' // |
| 127 | + { outPath = callFunctionWith spec' (getFetcher spec') { }; }; |
| 128 | + } |
| 129 | + else defaultSpec |
| 130 | + ) sources |
0 commit comments