This contains my bachelors thesis and associated tex files, code snippets and maybe more. Topic: Data Movement in Heterogeneous Memories with Intel Data Streaming Accelerator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
7.2 KiB

  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. submodules = if spec ? submodules then spec.submodules else false;
  30. submoduleArg =
  31. let
  32. nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0;
  33. emptyArgWithWarning =
  34. if submodules == true
  35. then
  36. builtins.trace
  37. (
  38. "The niv input \"${name}\" uses submodules "
  39. + "but your nix's (${builtins.nixVersion}) builtins.fetchGit "
  40. + "does not support them"
  41. )
  42. { }
  43. else { };
  44. in
  45. if nixSupportsSubmodules
  46. then { inherit submodules; }
  47. else emptyArgWithWarning;
  48. in
  49. builtins.fetchGit
  50. ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg);
  51. fetch_local = spec: spec.path;
  52. fetch_builtin-tarball = name: throw
  53. ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
  54. $ niv modify ${name} -a type=tarball -a builtin=true'';
  55. fetch_builtin-url = name: throw
  56. ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
  57. $ niv modify ${name} -a type=file -a builtin=true'';
  58. #
  59. # Various helpers
  60. #
  61. # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
  62. sanitizeName = name:
  63. (
  64. concatMapStrings (s: if builtins.isList s then "-" else s)
  65. (
  66. builtins.split "[^[:alnum:]+._?=-]+"
  67. ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
  68. )
  69. );
  70. # The set of packages used when specs are fetched using non-builtins.
  71. mkPkgs = sources: system:
  72. let
  73. sourcesNixpkgs =
  74. import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
  75. hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
  76. hasThisAsNixpkgsPath = <nixpkgs> == ./.;
  77. in
  78. if builtins.hasAttr "nixpkgs" sources
  79. then sourcesNixpkgs
  80. else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
  81. import <nixpkgs> { }
  82. else
  83. abort
  84. ''
  85. Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
  86. add a package called "nixpkgs" to your sources.json.
  87. '';
  88. # The actual fetching function.
  89. fetch = pkgs: name: spec:
  90. if ! builtins.hasAttr "type" spec then
  91. abort "ERROR: niv spec ${name} does not have a 'type' attribute"
  92. else if spec.type == "file" then fetch_file pkgs name spec
  93. else if spec.type == "tarball" then fetch_tarball pkgs name spec
  94. else if spec.type == "git" then fetch_git name spec
  95. else if spec.type == "local" then fetch_local spec
  96. else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
  97. else if spec.type == "builtin-url" then fetch_builtin-url name
  98. else
  99. abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
  100. # If the environment variable NIV_OVERRIDE_${name} is set, then use
  101. # the path directly as opposed to the fetched source.
  102. replace = name: drv:
  103. let
  104. saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
  105. ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
  106. in
  107. if ersatz == "" then drv else
  108. # this turns the string into an actual Nix path (for both absolute and
  109. # relative paths)
  110. if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
  111. # Ports of functions for older nix versions
  112. # a Nix version of mapAttrs if the built-in doesn't exist
  113. mapAttrs = builtins.mapAttrs or (
  114. f: set: with builtins;
  115. listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
  116. );
  117. # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
  118. range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
  119. # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
  120. stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
  121. # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
  122. stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
  123. concatMapStrings = f: list: concatStrings (map f list);
  124. concatStrings = builtins.concatStringsSep "";
  125. # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
  126. optionalAttrs = cond: as: if cond then as else { };
  127. # fetchTarball version that is compatible between all the versions of Nix
  128. builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
  129. let
  130. inherit (builtins) lessThan nixVersion fetchTarball;
  131. in
  132. if lessThan nixVersion "1.12" then
  133. fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
  134. else
  135. fetchTarball attrs;
  136. # fetchurl version that is compatible between all the versions of Nix
  137. builtins_fetchurl = { url, name ? null, sha256 }@attrs:
  138. let
  139. inherit (builtins) lessThan nixVersion fetchurl;
  140. in
  141. if lessThan nixVersion "1.12" then
  142. fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
  143. else
  144. fetchurl attrs;
  145. # Create the final "sources" from the config
  146. mkSources = config:
  147. mapAttrs
  148. (
  149. name: spec:
  150. if builtins.hasAttr "outPath" spec
  151. then
  152. abort
  153. "The values in sources.json should not have an 'outPath' attribute"
  154. else
  155. spec // { outPath = replace name (fetch config.pkgs name spec); }
  156. )
  157. config.sources;
  158. # The "config" used by the fetchers
  159. mkConfig =
  160. { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
  161. , sources ? if isNull sourcesFile then { } else builtins.fromJSON (builtins.readFile sourcesFile)
  162. , system ? builtins.currentSystem
  163. , pkgs ? mkPkgs sources system
  164. }: rec {
  165. # The sources, i.e. the attribute set of spec name to spec
  166. inherit sources;
  167. # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
  168. inherit pkgs;
  169. };
  170. in
  171. mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }