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.

267 lines
9.0 KiB

11 months ago
2 years ago
  1. { pkgs ? import <nixpkgs> { overlays = [ (import ./artiq-fast/mozilla-overlay.nix) ]; }
  2. , use-generated ? <use-generated>
  3. }:
  4. let
  5. sinaraSystemsRev = builtins.readFile <artiq-board-generated/sinara-rev.txt>;
  6. sinaraSystemsHash = builtins.readFile <artiq-board-generated/sinara-hash.txt>;
  7. sinaraSystemsSrc =
  8. if use-generated
  9. then pkgs.fetchgit {
  10. url = "https://git.m-labs.hk/M-Labs/sinara-systems.git";
  11. rev = sinaraSystemsRev;
  12. sha256 = sinaraSystemsHash;
  13. }
  14. else <sinaraSystemsSrc>;
  15. artiq-fast =
  16. if use-generated
  17. then <artiq-board-generated/fast>
  18. else <artiq-fast>;
  19. artiqVersion = import (artiq-fast + "/pkgs/artiq-version.nix") {
  20. inherit (pkgs) stdenv git fetchgit;
  21. };
  22. targets = import ./artiq-full/artiq-targets.nix {
  23. inherit pkgs artiqVersion sinaraSystemsSrc;
  24. };
  25. kasliVariants = map ({ variant, ... }: variant) (
  26. builtins.filter ({ target, ... }: target == "kasli") (
  27. builtins.attrValues targets
  28. )
  29. );
  30. standaloneVariants = map ({ variant, ... }: variant) (
  31. builtins.filter ({ target, standalone ? false, ... }: target == "kasli" && standalone) (
  32. builtins.attrValues targets
  33. )
  34. );
  35. serializedTargets = pkgs.lib.generators.toPretty {} (
  36. map (conf:
  37. if conf ? buildCommand
  38. then conf // {
  39. buildCommand = builtins.replaceStrings ["$"] ["\\\\\\$"] conf.buildCommand;
  40. }
  41. else conf
  42. ) (builtins.attrValues targets)
  43. );
  44. generatedNix = pkgs.runCommand "generated-nix" { buildInputs = [ pkgs.nix pkgs.git ]; }
  45. ''
  46. mkdir $out
  47. ${if use-generated
  48. then ''
  49. cp -a ${<artiq-board-generated>} $out/board-generated
  50. ln -s board-generated/fast $out/fast
  51. ''
  52. else "cp -a ${<artiq-fast>} $out/fast"}
  53. cp ${./artiq-full}/artiq-board-vivado.nix $out
  54. cp ${./artiq-full}/generate-identifier.py $out
  55. cp ${./artiq-full}/conda-artiq-board.nix $out
  56. cp ${./artiq-full}/extras.nix $out
  57. cp ${./artiq-full}/*.patch $out
  58. ${if use-generated
  59. then ''
  60. REV=${sinaraSystemsRev}
  61. HASH=${sinaraSystemsHash}
  62. ''
  63. else ''
  64. REV=`git --git-dir ${sinaraSystemsSrc}/.git rev-parse HEAD`
  65. SINARA_SRC_CLEAN=`mktemp -d`
  66. cp -a ${sinaraSystemsSrc}/. $SINARA_SRC_CLEAN
  67. chmod -R 755 $SINARA_SRC_CLEAN/.git
  68. chmod 755 $SINARA_SRC_CLEAN
  69. rm -rf $SINARA_SRC_CLEAN/.git
  70. HASH=`nix-hash --type sha256 --base32 $SINARA_SRC_CLEAN`
  71. ''}
  72. cat > $out/default.nix << EOF
  73. { pkgs ? import <nixpkgs> { overlays = [ (import ./fast/mozilla-overlay.nix) ]; }}:
  74. let
  75. artiq-fast = import ${if use-generated then "./board-generated" else "."}/fast { inherit pkgs; };
  76. ddbDeps = [
  77. artiq-fast.artiq
  78. (pkgs.python3.withPackages (ps: [ ps.jsonschema ]))
  79. ];
  80. kasliVariants = [${builtins.concatStringsSep " " (
  81. builtins.map (variant: "\"${variant}\"") kasliVariants
  82. )}];
  83. standaloneVariants = [${builtins.concatStringsSep " " (
  84. builtins.map (variant: "\"${variant}\"") standaloneVariants
  85. )}];
  86. vivado = import ${if use-generated then "./board-generated" else "."}/fast/vivado.nix {
  87. inherit pkgs;
  88. };
  89. artiq-board =
  90. ${if use-generated
  91. then ''
  92. import ./artiq-board-vivado.nix {
  93. inherit pkgs vivado;
  94. version = artiq-fast.artiq.version;
  95. board-generated = import ./board-generated {
  96. inherit pkgs;
  97. };
  98. }
  99. ''
  100. else ''
  101. import ./fast/artiq-board.nix {
  102. inherit pkgs vivado;
  103. rustPlatform = import ./fast/rust-platform.nix { inherit pkgs; };
  104. }
  105. ''};
  106. conda-artiq-board = import ./conda-artiq-board.nix { inherit pkgs; };
  107. src = pkgs.fetchgit {
  108. url = "https://git.m-labs.hk/M-Labs/sinara-systems.git";
  109. rev = "$REV";
  110. sha256 = "$HASH";
  111. };
  112. artiq-targets = pkgs.lib.lists.foldr (conf: start:
  113. let
  114. inherit (conf) target variant;
  115. json = src + "/\''${variant}.json";
  116. boardBinaries = artiq-board (conf // {
  117. src = json;
  118. });
  119. in
  120. start // {
  121. "artiq-board-\''${target}-\''${variant}" = boardBinaries;
  122. "conda-artiq-board-\''${target}-\''${variant}" = conda-artiq-board {
  123. boardBinaries = boardBinaries;
  124. inherit target variant;
  125. };
  126. } // (pkgs.lib.optionalAttrs (
  127. target == "kasli" &&
  128. builtins.elem variant standaloneVariants
  129. ) {
  130. "device-db-\''${target}-\''${variant}" = pkgs.stdenv.mkDerivation {
  131. name = "device-db-\''${target}-\''${variant}";
  132. buildInputs = ddbDeps;
  133. phases = [ "buildPhase" ];
  134. buildPhase = "
  135. mkdir \$out
  136. artiq_ddb_template \''${json} -o \$out/device_db.py
  137. mkdir \$out/nix-support
  138. echo file device_db_template \$out/device_db.py >> \$out/nix-support/hydra-build-products
  139. ";
  140. };
  141. })
  142. ) {} ${serializedTargets};
  143. drtio-systems = {
  144. ${pkgs.lib.optionalString use-generated ''
  145. ap = {
  146. master = "apmaster";
  147. satellites = {
  148. "1" = "apsatellite1";
  149. "2" = "apsatellite2";
  150. };
  151. };
  152. berkeley3 = {
  153. master = "berkeley3master";
  154. satellites = {
  155. "1" = "berkeley3satellite";
  156. };
  157. };
  158. npl5 = {
  159. master = "npl5master";
  160. satellites = {
  161. "1" = "npl5satellite";
  162. };
  163. };
  164. ptb3 = {
  165. master = "ptb3master";
  166. satellites = {
  167. "1" = "ptb3satellite";
  168. };
  169. };
  170. purdue = {
  171. master = "purduemaster";
  172. satellites = {
  173. "1" = "purduesatellite";
  174. };
  175. };
  176. sias = {
  177. master = "siasmaster";
  178. satellites = {
  179. "1" = "siassatellite";
  180. };
  181. };
  182. stfc = {
  183. master = "stfcmaster";
  184. satellites = {
  185. "1" = "stfcsatellite";
  186. };
  187. };
  188. ubirmingham3 = {
  189. master = "ubirmingham3master";
  190. satellites = {
  191. "1" = "ubirmingham3satellite";
  192. };
  193. };
  194. ustc5 = {
  195. master = "ustc5master";
  196. satellites = {
  197. "1" = "ustc5satellite";
  198. };
  199. };
  200. wipm7 = {
  201. master = "wipm7master";
  202. satellites = {
  203. "1" = "wipm7satellite";
  204. };
  205. };
  206. ''}
  207. };
  208. drtio-ddbs = pkgs.lib.attrsets.mapAttrs'
  209. (system: crates: pkgs.lib.attrsets.nameValuePair ("device-db-" + system)
  210. (pkgs.stdenv.mkDerivation {
  211. name = "device-db-\''${system}";
  212. buildInputs = ddbDeps;
  213. phases = [ "buildPhase" ];
  214. buildPhase = "
  215. mkdir \$out
  216. artiq_ddb_template \
  217. \''${pkgs.lib.strings.concatStringsSep " " (pkgs.lib.attrsets.mapAttrsToList (dest: desc: "-s " + dest + " " + (src + "/\''${desc}.json")) crates.satellites) } \
  218. \''${src}/\''${crates.master}.json -o \$out/device_db.py
  219. mkdir \$out/nix-support
  220. echo file device_db_template \$out/device_db.py >> \$out/nix-support/hydra-build-products
  221. ";
  222. })) drtio-systems;
  223. extras = import ./extras.nix { inherit pkgs; inherit (artiq-fast) sipyco asyncserial artiq; };
  224. in
  225. artiq-fast // artiq-targets // drtio-ddbs // extras // rec {
  226. conda-artiq-board-kasli-tester = conda-artiq-board {
  227. target = "kasli";
  228. variant = "tester";
  229. boardBinaries = artiq-fast.artiq-board-kasli-tester;
  230. };
  231. conda-artiq-board-kc705-nist_clock = conda-artiq-board {
  232. target = "kc705";
  233. variant = "nist_clock";
  234. boardBinaries = artiq-fast.artiq-board-kc705-nist_clock;
  235. };
  236. }
  237. EOF
  238. '';
  239. pythonDeps = import ./artiq-full/python-deps.nix { inherit pkgs; };
  240. sipycoManualPackages = import ./artiq-full/sipyco-manual.nix {
  241. inherit (pkgs) stdenv lib python3Packages texlive texinfo;
  242. inherit (import artiq-fast { inherit pkgs; }) sipyco;
  243. };
  244. artiqManualPackages = import ./artiq-full/artiq-manual.nix {
  245. inherit (pkgs) stdenv lib fetchgit git python3Packages texlive texinfo;
  246. inherit (pythonDeps) sphinxcontrib-wavedrom;
  247. inherit artiq-fast;
  248. };
  249. artiq-full = import generatedNix { inherit pkgs; };
  250. exampleUserEnv = import ./artiq-full/example-user-env.nix { inherit pkgs artiq-full; };
  251. jobs = artiq-full // sipycoManualPackages // artiqManualPackages // exampleUserEnv;
  252. in
  253. builtins.mapAttrs (key: value: pkgs.lib.hydraJob value) jobs // {
  254. artiq-full = pkgs.releaseTools.channel {
  255. name = "artiq-full";
  256. src = generatedNix;
  257. constituents = [];
  258. };
  259. conda-channel = import ./artiq-full/conda-channel.nix { inherit pkgs artiq-fast; } { inherit jobs; };
  260. }