Digitale bierlijst

sources.nix 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. # This file has been generated by Niv.
  2. let
  3. #
  4. # The fetchers. fetch_<type> fetches specs of type <type>.
  5. #
  6. fetch_file = pkgs: name: spec:
  7. let
  8. name' = sanitizeName name + "-src";
  9. in
  10. if spec.builtin or true then
  11. builtins_fetchurl { inherit (spec) url sha256; name = name'; }
  12. else
  13. pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
  14. fetch_tarball = pkgs: name: spec:
  15. let
  16. name' = sanitizeName name + "-src";
  17. in
  18. if spec.builtin or true then
  19. builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
  20. else
  21. pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
  22. fetch_git = name: spec:
  23. let
  24. ref =
  25. if spec ? ref then spec.ref else
  26. if spec ? branch then "refs/heads/${spec.branch}" else
  27. if spec ? tag then "refs/tags/${spec.tag}" else
  28. abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
  29. in
  30. builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
  31. fetch_local = spec: spec.path;
  32. fetch_builtin-tarball = name: throw
  33. ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
  34. $ niv modify ${name} -a type=tarball -a builtin=true'';
  35. fetch_builtin-url = name: throw
  36. ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
  37. $ niv modify ${name} -a type=file -a builtin=true'';
  38. #
  39. # Various helpers
  40. #
  41. # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
  42. sanitizeName = name:
  43. (
  44. concatMapStrings (s: if builtins.isList s then "-" else s)
  45. (
  46. builtins.split "[^[:alnum:]+._?=-]+"
  47. ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
  48. )
  49. );
  50. # The set of packages used when specs are fetched using non-builtins.
  51. mkPkgs = sources: system:
  52. let
  53. sourcesNixpkgs =
  54. import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
  55. hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
  56. hasThisAsNixpkgsPath = <nixpkgs> == ./.;
  57. in
  58. if builtins.hasAttr "nixpkgs" sources
  59. then sourcesNixpkgs
  60. else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
  61. import <nixpkgs> {}
  62. else
  63. abort
  64. ''
  65. Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
  66. add a package called "nixpkgs" to your sources.json.
  67. '';
  68. # The actual fetching function.
  69. fetch = pkgs: name: spec:
  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 name spec
  73. else if spec.type == "tarball" then fetch_tarball pkgs name spec
  74. else if spec.type == "git" then fetch_git name spec
  75. else if spec.type == "local" then fetch_local spec
  76. else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
  77. else if spec.type == "builtin-url" then fetch_builtin-url name
  78. else
  79. abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
  80. # If the environment variable NIV_OVERRIDE_${name} is set, then use
  81. # the path directly as opposed to the fetched source.
  82. replace = name: drv:
  83. let
  84. saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
  85. ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
  86. in
  87. if ersatz == "" then drv else ersatz;
  88. # Ports of functions for older nix versions
  89. # a Nix version of mapAttrs if the built-in doesn't exist
  90. mapAttrs = builtins.mapAttrs or (
  91. f: set: with builtins;
  92. listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
  93. );
  94. # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
  95. range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
  96. # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
  97. stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
  98. # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
  99. stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
  100. concatMapStrings = f: list: concatStrings (map f list);
  101. concatStrings = builtins.concatStringsSep "";
  102. # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
  103. optionalAttrs = cond: as: if cond then as else {};
  104. # fetchTarball version that is compatible between all the versions of Nix
  105. builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
  106. let
  107. inherit (builtins) lessThan nixVersion fetchTarball;
  108. in
  109. if lessThan nixVersion "1.12" then
  110. fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
  111. else
  112. fetchTarball attrs;
  113. # fetchurl version that is compatible between all the versions of Nix
  114. builtins_fetchurl = { url, name ? null, sha256 }@attrs:
  115. let
  116. inherit (builtins) lessThan nixVersion fetchurl;
  117. in
  118. if lessThan nixVersion "1.12" then
  119. fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
  120. else
  121. fetchurl attrs;
  122. # Create the final "sources" from the config
  123. mkSources = config:
  124. mapAttrs (
  125. name: spec:
  126. if builtins.hasAttr "outPath" spec
  127. then abort
  128. "The values in sources.json should not have an 'outPath' attribute"
  129. else
  130. spec // { outPath = replace name (fetch config.pkgs name spec); }
  131. ) config.sources;
  132. # The "config" used by the fetchers
  133. mkConfig =
  134. { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
  135. , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
  136. , system ? builtins.currentSystem
  137. , pkgs ? mkPkgs sources system
  138. }: rec {
  139. # The sources, i.e. the attribute set of spec name to spec
  140. inherit sources;
  141. # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
  142. inherit pkgs;
  143. };
  144. in
  145. mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }