Genode Packages collection https://git.sr.ht/~ehmry/genodepkgs/
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.

default.nix 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. { buildPackages, targetPackages }:
  2. let
  3. version = "20.05";
  4. # Update ./port-versions.nix bumping the version and updateing the sources.
  5. platform = targetPackages.targetPlatform;
  6. arch = with platform;
  7. if isx86_64 then
  8. "x86_64"
  9. else if isAarch64 then
  10. "arm_v8a"
  11. else
  12. throw "unknown Genode arch for platform ${platform.system}";
  13. inherit (buildPackages) callPackage fetchurl lib;
  14. genodeSources =
  15. # The Genode source repository
  16. let
  17. toolPrefix = if platform.isx86 then
  18. "genode-x86-"
  19. else if platform.isAarch64 then
  20. "genode-aarch64-"
  21. else
  22. throw "unknown tool prefix for Genode arch ${arch}";
  23. in with buildPackages;
  24. stdenvNoCC.mkDerivation {
  25. pname = "genode-sources";
  26. inherit version;
  27. src = fetchurl {
  28. url = "https://github.com/genodelabs/genode/archive/${version}.tar.gz";
  29. hash = "sha256-5Fd8ywGbDtQF+9yDZ5xAQ7l1Vzh1jQAQeqVj+EtO1us=";
  30. };
  31. nativeBuildInputs = [ expect gnumake tcl ];
  32. patches = [ ./LIB.patch ./binary-labels.patch ];
  33. configurePhase = ''
  34. patchShebangs ./tool
  35. substituteInPlace repos/base/etc/tools.conf \
  36. --replace "/usr/local/genode/tool/19.05/bin/" ""
  37. substituteInPlace tool/check_abi \
  38. --replace "exec nm" "exec ${toolPrefix}nm"
  39. '';
  40. buildPhase = ''
  41. echo { >> ports.nix
  42. find repos/*/ports -name '*.hash' | while read hashFile
  43. do
  44. echo " $(basename --suffix=.hash $hashFile) = \"$(cut -c -6 $hashFile)\";" >> ports.nix
  45. done
  46. echo } >> ports.nix
  47. '';
  48. installPhase = "cp -a . $out";
  49. };
  50. preparePort =
  51. # Prepare a "port" of source code declared in the Genode sources
  52. name:
  53. { hash ? "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
  54. , patches ? [ ], ... }@args:
  55. let
  56. havePatches = patches != [ ];
  57. version = (import ./port-versions.nix).${name};
  58. in with buildPackages;
  59. stdenvNoCC.mkDerivation (args // {
  60. name = name + "-port-" + version;
  61. inherit version patches;
  62. preferLocalBuild = true;
  63. outputHashMode = "recursive";
  64. outputHash = hash;
  65. GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
  66. VERBOSE = "";
  67. # need to build in verbose mode because errors are hidden
  68. impureEnvVars = lib.fetchers.proxyImpureEnvVars
  69. ++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" ];
  70. src = if havePatches then genodeSources else null;
  71. dontUnpack = !havePatches;
  72. dontConfigure = true;
  73. nativeBuildInputs =
  74. [ bison flex gitMinimal glibc glibcLocales wget which ]
  75. ++ (args.nativeBuildInputs or [ ]);
  76. buildPhase =
  77. # ignore the port hash, its only for the inputs
  78. ''
  79. runHook preBuild
  80. export CONTRIB_DIR=$NIX_BUILD_TOP/contrib
  81. export GENODE_DIR=${if havePatches then "$(pwd)" else genodeSources}
  82. mkdir $CONTRIB_DIR
  83. $GENODE_DIR/tool/ports/prepare_port ${name} CHECK_HASH=no
  84. runHook postBuild
  85. '';
  86. installPhase =
  87. # strip non-deterministic and extra artifacts
  88. ''
  89. runHook preInstall
  90. chmod -R +w $CONTRIB_DIR/*
  91. find $CONTRIB_DIR/* -name .git -exec rm -rf {} \; || true
  92. find $CONTRIB_DIR/* -name .svn -exec rm -rf {} \; || true
  93. find $CONTRIB_DIR/* -name '*.t?z' -exec rm -rf {} \; || true
  94. find $CONTRIB_DIR/* -name '*.tar.*' -exec rm -rf {} \; || true
  95. find $CONTRIB_DIR/* -name '*.zip' -exec rm -rf {} \; || true
  96. mkdir $out
  97. cp -a $CONTRIB_DIR/* $out/
  98. runHook postInstall
  99. '';
  100. dontFixup = true;
  101. });
  102. ports =
  103. lib.mapAttrs preparePort (import ./ports.nix { inherit buildPackages; });
  104. toolchain = callPackage ./toolchain.nix { };
  105. stdenv' =
  106. targetPackages.stdenvAdapters.overrideCC targetPackages.stdenv toolchain;
  107. buildUpstream =
  108. # Build from the Genode sources
  109. { name, targets, portInputs ? [ ], nativeBuildInputs ? [ ], patches ? [ ]
  110. , enableParallelBuilding ? true, meta ? { }, ... }@extraAttrs:
  111. let havePatches = patches != [ ];
  112. in stdenv'.mkDerivation (extraAttrs // {
  113. pname = name;
  114. inherit (genodeSources) version;
  115. inherit targets patches enableParallelBuilding;
  116. src = if havePatches then genodeSources else null;
  117. dontUnpack = !havePatches;
  118. nativeBuildInputs = with buildPackages;
  119. [ binutils bison flex stdenv.cc tcl which ] ++ nativeBuildInputs;
  120. configurePhase = let
  121. linkPorts = toString
  122. (builtins.map (drv: " ln -sv ${drv}/* $CONTRIB_DIR/;") portInputs);
  123. in ''
  124. runHook preConfigure
  125. export CONTRIB_DIR=$NIX_BUILD_TOP/contrib
  126. export BUILD_DIR=$(pwd)/build
  127. export GENODE_DIR=${if havePatches then "$(pwd)" else genodeSources}
  128. $GENODE_DIR/tool/create_builddir ${arch}
  129. substituteInPlace $BUILD_DIR/etc/build.conf \
  130. --replace "#REPOSITORIES" "REPOSITORIES"
  131. mkdir $CONTRIB_DIR; ${linkPorts}
  132. runHook postConfigure
  133. '';
  134. STRIP_TARGET_CMD = "cp $< $@";
  135. makeFlags = [ "-C build" "VERBOSE=" ] ++ targets;
  136. installPhase = ''
  137. runHook preInstall
  138. find build/bin -name '*.xsd' -delete
  139. find build/bin -follow -type f -exec install -Dt $out '{}' \;
  140. runHook postInstall
  141. '';
  142. meta = { platforms = lib.platforms.genode; } // meta;
  143. });
  144. buildDepot =
  145. # Build a Depot target from the Genode sources
  146. { name, apiOnly ? false, portInputs ? [ ], nativeBuildInputs ? [ ]
  147. , meta ? { }, ... }@extraAttrs:
  148. stdenv'.mkDerivation (extraAttrs // {
  149. pname = name;
  150. inherit (genodeSources) version;
  151. enableParallelBuilding = true;
  152. nativeBuildInputs = with buildPackages;
  153. [ binutils bison flex stdenv.cc tcl which ] ++ nativeBuildInputs;
  154. src = genodeSources;
  155. # The genode source tree must be copied to the build directory
  156. # because the depot tool must modify the source tree as it runs.
  157. configurePhase = let
  158. copyPorts = # wasteful copy
  159. toString
  160. (builtins.map (drv: " cp -r ${drv}/* $CONTRIB_DIR/;") portInputs);
  161. in ''
  162. runHook preConfigure
  163. export GENODE_DIR=$(pwd)
  164. export CONTRIB_DIR=$GENODE_DIR/contrib
  165. export DEPOT_DIR=$GENODE_DIR/depot
  166. mkdir -p $CONTRIB_DIR; ${copyPorts}
  167. chmod +rwX -R .
  168. runHook postConfigure
  169. '';
  170. STRIP_TARGET_CMD = "cp $< $@";
  171. # defer strip until fixup phase
  172. makefile = "tool/depot/create";
  173. makeFlags = [
  174. "genodelabs/bin/${arch}/${name}"
  175. # by default the build system will refuse to be useful
  176. "FORCE=1"
  177. "KEEP_BUILD_DIR=1"
  178. "UPDATE_VERSIONS=1"
  179. "VERBOSE="
  180. ];
  181. installPhase = ''
  182. runHook preInstall
  183. rm -r depot/genodelabs/bin/${arch}/${name}/*\.build
  184. find depot/genodelabs/bin/${arch}/${name} -type f -exec install -Dt "''${!outputBin}" {} \;
  185. moveToOutput "lib*.so" "''${!outputLib}/lib"
  186. runHook postInstall
  187. '';
  188. meta = { platforms = lib.platforms.genode; } // meta;
  189. });
  190. buildOverrides = callPackage ./targets.nix { inherit ports; };
  191. specs = with platform;
  192. [ ]
  193. ++ lib.optional is32bit "32bit"
  194. ++ lib.optional is64bit "64bit"
  195. ++ lib.optional isAarch32 "arm"
  196. ++ lib.optional isAarch64 "arm_64"
  197. ++ lib.optional isRiscV "riscv"
  198. ++ lib.optional isx86 "x86"
  199. ++ lib.optional isx86_32 "x86_32"
  200. ++ lib.optional isx86_64 "x86_64";
  201. genodeBase =
  202. # A package containing the Genode C++ headers, a stub ld.lib.so and libvfs.lib.so
  203. buildUpstream {
  204. name = "base";
  205. targets = [ "LIB=vfs" ];
  206. postInstall =
  207. # The actual ld.lib.so is kernel specific
  208. # so ship the stubbed library for linking
  209. ''
  210. cp $BUILD_DIR/var/libcache/ld/ld.abi.so $out/ld.lib.so
  211. mkdir -p $out/include
  212. cp -r --no-preserve=mode \
  213. $GENODE_DIR/repos/base/include/* \
  214. $GENODE_DIR/repos/os/include/* \
  215. $GENODE_DIR/repos/demo/include/* \
  216. $GENODE_DIR/repos/gems/include/* \
  217. $out/include/
  218. for spec in ${toString specs}; do
  219. dir=$out/include/spec/$spec
  220. if [ -d $dir ]; then
  221. cp -r $dir/* $out/include/
  222. fi
  223. done
  224. rm -rf $out/include/spec
  225. cp -r $GENODE_DIR/repos/base/src/ld $out/ld
  226. '';
  227. };
  228. in genodeSources // {
  229. inherit buildUpstream buildDepot ports specs toolchain genodeBase;
  230. make = target:
  231. let
  232. name = builtins.replaceStrings [ "/" ] [ "-" ] target;
  233. attrs = buildOverrides.${name} or { };
  234. in buildUpstream ({
  235. inherit name;
  236. targets = [ target ];
  237. } // attrs);
  238. depot = name:
  239. let attrs = buildOverrides.${name} or { };
  240. in buildDepot ({ inherit name; } // attrs);
  241. }