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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. { flake, pkgs }:
  2. let
  3. inherit (pkgs) lib buildPackages targetPackages;
  4. platform = pkgs.targetPlatform;
  5. arch = with platform;
  6. if isx86_64 then
  7. "x86_64"
  8. else if isAarch64 then
  9. "arm_v8a"
  10. else
  11. throw "unknown Genode arch for platform ${platform.system}";
  12. upstreamSources = pkgs.fetchFromGitHub {
  13. owner = "genodelabs";
  14. repo = "genode";
  15. rev = "3fac8b106d83721914797c202793ec1d8ea02d2f";
  16. hash = "sha256-XgN1fBUsmX8oKk4ZBvROwEWlpILRlJz+UuK4kMDSI1Y=";
  17. };
  18. genodeSources =
  19. # The Genode source repository
  20. let
  21. toolPrefix = if platform.isx86 then
  22. "genode-x86-"
  23. else if platform.isAarch64 then
  24. "genode-aarch64-"
  25. else
  26. throw "unknown tool prefix for Genode arch ${arch}";
  27. in with buildPackages;
  28. stdenvNoCC.mkDerivation {
  29. pname = "genode-sources";
  30. version = builtins.substring 0 7 upstreamSources.rev;
  31. src = upstreamSources;
  32. nativeBuildInputs = [ expect gnumake tcl ];
  33. patches = [ ./patches/binary-labels.patch ./patches/label-fail.patch ];
  34. configurePhase = ''
  35. patchShebangs ./tool
  36. substituteInPlace repos/base/etc/tools.conf \
  37. --replace "/usr/local/genode/tool/19.05/bin/" ""
  38. substituteInPlace tool/check_abi \
  39. --replace "exec nm" "exec ${toolPrefix}nm"
  40. '';
  41. buildPhase = ''
  42. echo { >> ports.nix
  43. find repos/*/ports -name '*.hash' | while read hashFile
  44. do
  45. echo " $(basename --suffix=.hash $hashFile) = \"$(cut -c -6 $hashFile)\";" >> ports.nix
  46. done
  47. echo } >> ports.nix
  48. '';
  49. installPhase = "cp -a . $out";
  50. };
  51. portVersions = import "${genodeSources}/ports.nix";
  52. preparePort =
  53. # Prepare a "port" of source code declared in the Genode sources
  54. name:
  55. { hash ? "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
  56. , patches ? [ ], extraRepos ? [ ], ... }@args:
  57. let
  58. dontUnpack = patches == [ ] && extraRepos == [ ];
  59. version = portVersions.${name} or args.version;
  60. in with buildPackages.buildPackages;
  61. stdenvNoCC.mkDerivation (args // {
  62. name = name + "-port-" + version;
  63. inherit version patches dontUnpack extraRepos;
  64. preferLocalBuild = true;
  65. outputHashMode = "recursive";
  66. outputHash = hash;
  67. GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
  68. VERBOSE = "";
  69. # need to build in verbose mode because errors are hidden
  70. impureEnvVars = lib.fetchers.proxyImpureEnvVars
  71. ++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" ];
  72. src = if dontUnpack then null else genodeSources;
  73. dontConfigure = true;
  74. nativeBuildInputs =
  75. [ bison flex gitMinimal glibc glibcLocales wget which ]
  76. ++ (args.nativeBuildInputs or [ ]);
  77. buildPhase =
  78. # ignore the port hash, its only for the inputs
  79. ''
  80. runHook preBuild
  81. export CONTRIB_DIR=$NIX_BUILD_TOP/contrib
  82. export GENODE_DIR=${if dontUnpack then genodeSources else "$(pwd)"}
  83. for repo in $extraRepos; do
  84. ln -s $repo $GENODE_DIR/repos/
  85. done
  86. mkdir $CONTRIB_DIR
  87. $GENODE_DIR/tool/ports/prepare_port ${name} CHECK_HASH=no
  88. runHook postBuild
  89. '';
  90. installPhase =
  91. # strip non-deterministic and extra artifacts
  92. ''
  93. runHook preInstall
  94. chmod -R +w $CONTRIB_DIR/*
  95. find $CONTRIB_DIR/* -name .git -exec rm -rf {} \; || true
  96. find $CONTRIB_DIR/* -name .svn -exec rm -rf {} \; || true
  97. find $CONTRIB_DIR/* -name '*.t?z' -exec rm -rf {} \; || true
  98. find $CONTRIB_DIR/* -name '*.tar.*' -exec rm -rf {} \; || true
  99. find $CONTRIB_DIR/* -name '*.zip' -exec rm -rf {} \; || true
  100. mkdir $out
  101. cp -a $CONTRIB_DIR/* $out/
  102. runHook postInstall
  103. '';
  104. dontFixup = true;
  105. });
  106. ports = lib.mapAttrs preparePort (import ./ports.nix {
  107. pkgs = flake.inputs.nixpkgs.legacyPackages.x86_64-linux // {
  108. inherit (pkgs) genodePackages;
  109. };
  110. });
  111. # The "ports" mechanism is hardly deterministic, so prepare with
  112. # a pinned nixpkgs revision for a pinned platform.
  113. toolchain = buildPackages.buildPackages.callPackage ./toolchain.nix { };
  114. stdenv' = pkgs.stdenvAdapters.overrideCC pkgs.stdenv toolchain;
  115. buildUpstream =
  116. # Build from the Genode sources
  117. { name, targets, portInputs ? [ ], nativeBuildInputs ? [ ], patches ? [ ]
  118. , enableParallelBuilding ? true, meta ? { }, ... }@extraAttrs:
  119. let havePatches = patches != [ ];
  120. in stdenv'.mkDerivation (extraAttrs // {
  121. pname = name;
  122. inherit (genodeSources) version;
  123. inherit targets patches enableParallelBuilding;
  124. src = if havePatches then genodeSources else null;
  125. dontUnpack = !havePatches;
  126. nativeBuildInputs = with buildPackages;
  127. [ binutils bison flex stdenv.cc tcl which ] ++ nativeBuildInputs;
  128. configurePhase = let
  129. linkPorts = toString
  130. (builtins.map (drv: " ln -sv ${drv}/* $CONTRIB_DIR/;") portInputs);
  131. in ''
  132. runHook preConfigure
  133. export CONTRIB_DIR=$NIX_BUILD_TOP/contrib
  134. export BUILD_DIR=$(pwd)/build
  135. export GENODE_DIR=${if havePatches then "$(pwd)" else genodeSources}
  136. $GENODE_DIR/tool/create_builddir ${arch}
  137. substituteInPlace $BUILD_DIR/etc/build.conf \
  138. --replace "#REPOSITORIES" "REPOSITORIES"
  139. mkdir $CONTRIB_DIR; ${linkPorts}
  140. runHook postConfigure
  141. '';
  142. STRIP_TARGET_CMD = "cp $< $@";
  143. makeFlags = [ "-C build" "VERBOSE=" ] ++ targets;
  144. installPhase = ''
  145. runHook preInstall
  146. find build/bin -name '*.xsd' -delete
  147. find build/bin -follow -type f -name '*.lib.so' \
  148. -exec install -Dt "''${!outputLib}/lib" {} \; -delete
  149. find build/bin -follow -type f -executable \
  150. -exec install -Dt "''${!outputBin}/bin" {} \;
  151. runHook postInstall
  152. '';
  153. meta = { platforms = lib.platforms.genode; } // meta;
  154. });
  155. buildDepot =
  156. # Build a Depot target from the Genode sources
  157. { name, apiOnly ? false, portInputs ? [ ], nativeBuildInputs ? [ ]
  158. , buildInputs ? [ ], meta ? { }, ... }@extraAttrs:
  159. stdenv'.mkDerivation (extraAttrs // {
  160. pname = name;
  161. inherit (genodeSources) version;
  162. enableParallelBuilding = true;
  163. nativeBuildInputs = with buildPackages.buildPackages;
  164. [ binutils bison flex stdenv.cc tcl which ] ++ nativeBuildInputs;
  165. src = genodeSources;
  166. # The genode source tree must be copied to the build directory
  167. # because the depot tool must modify the source tree as it runs.
  168. configurePhase = let
  169. copyPorts = # wasteful copy
  170. toString
  171. (builtins.map (drv: " cp -r ${drv}/* $CONTRIB_DIR/;") portInputs);
  172. in ''
  173. runHook preConfigure
  174. export GENODE_DIR=$(pwd)
  175. export CONTRIB_DIR=$GENODE_DIR/contrib
  176. export DEPOT_DIR=$GENODE_DIR/depot
  177. mkdir -p $CONTRIB_DIR; ${copyPorts}
  178. chmod +rwX -R .
  179. runHook postConfigure
  180. '';
  181. STRIP_TARGET_CMD = "cp $< $@";
  182. # defer strip until fixup phase
  183. makefile = "tool/depot/create";
  184. makeFlags = [
  185. "genodelabs/bin/${arch}/${name}"
  186. # by default the build system will refuse to be useful
  187. "FORCE=1"
  188. "KEEP_BUILD_DIR=1"
  189. "UPDATE_VERSIONS=1"
  190. "VERBOSE="
  191. ];
  192. installPhase = ''
  193. runHook preInstall
  194. rm -r depot/genodelabs/bin/${arch}/${name}/*\.build
  195. local outputLibDir="''${!outputLib}/lib"
  196. find depot/genodelabs/bin/${arch}/${name} -name '*.lib.so' \
  197. -exec install -Dt "$outputLibDir" {} \; -delete
  198. if [ -d "$outputLibDir" ]; then
  199. pushd "$outputLibDir"
  200. for src in *.lib.so; do
  201. dst=$src
  202. dst="''${dst#lib}"
  203. dst="''${dst%.lib.so}"
  204. ln -s "$src" lib"$dst".so
  205. done
  206. popd
  207. fi
  208. find depot/genodelabs/bin/${arch}/${name} -executable \
  209. -exec install -Dt "''${!outputBin}/bin" {} \;
  210. runHook postInstall
  211. '';
  212. meta = { platforms = lib.platforms.genode; } // meta;
  213. });
  214. makePackages = let
  215. overrides = import ./make-targets.nix {
  216. inherit (pkgs) buildPackages genodePackages;
  217. inherit ports;
  218. };
  219. in lib.attrsets.mapAttrs
  220. (name: value: (buildUpstream ({ inherit name; } // value))) overrides;
  221. depotPackages = lib.attrsets.mapAttrs
  222. (name: value: (buildDepot ({ inherit name; } // value)))
  223. (import ./depot-targets.nix {
  224. inherit (pkgs) genodePackages;
  225. inherit ports;
  226. buildPackages = buildPackages.buildPackages;
  227. });
  228. specs = with platform;
  229. [ ]
  230. ++ lib.optional is32bit "32bit"
  231. ++ lib.optional is64bit "64bit"
  232. ++ lib.optional isAarch32 "arm"
  233. ++ lib.optional isAarch64 "arm_64"
  234. ++ lib.optional isRiscV "riscv"
  235. ++ lib.optional isx86 "x86"
  236. ++ lib.optional isx86_32 "x86_32"
  237. ++ lib.optional isx86_64 "x86_64";
  238. genodeBase =
  239. # A package containing the Genode C++ headers, a stub ld.lib.so and vfs.lib.so
  240. buildUpstream {
  241. name = "base";
  242. targets = [ "LIB=vfs" ];
  243. postInstall =
  244. # The actual ld.lib.so is kernel specific
  245. # so ship the stubbed library for linking
  246. ''
  247. cp $BUILD_DIR/var/libcache/ld/ld.abi.so $out/ld.lib.so
  248. mkdir -p $out/include
  249. cp -r --no-preserve=mode \
  250. $GENODE_DIR/repos/base/include/* \
  251. $GENODE_DIR/repos/os/include/* \
  252. $GENODE_DIR/repos/demo/include/* \
  253. $GENODE_DIR/repos/gems/include/* \
  254. $out/include/
  255. for spec in ${toString specs}; do
  256. dir=$out/include/spec/$spec
  257. if [ -d $dir ]; then
  258. cp -r $dir/* $out/include/
  259. fi
  260. done
  261. rm -rf $out/include/spec
  262. cp -r $GENODE_DIR/repos/base/src/ld $out/ld
  263. '';
  264. };
  265. basePatches = [
  266. ./patches/cxx-align.patch
  267. ./patches/core-diag.patch
  268. ./patches/ld-ro.patch
  269. ];
  270. in makePackages // depotPackages // {
  271. genodeSources = genodeSources // {
  272. inherit arch buildUpstream buildDepot genodeBase ports specs toolchain;
  273. };
  274. base-hw-pc = buildUpstream {
  275. name = "base-hw-pc";
  276. outputs = [ "out" "coreObj" "bootstrapObj" ];
  277. KERNEL = "hw";
  278. BOARD = "pc";
  279. targets = [ "bootstrap" "core" "timer" "lib/ld" ];
  280. patches = basePatches;
  281. postInstall = ''
  282. mv $out/lib/ld-hw.lib.so $out/lib/ld.lib.so
  283. mv $out/bin/hw_timer_drv $out/bin/timer_drv
  284. install build/bin/core-hw-pc.o $coreObj
  285. install build/bin/bootstrap-hw-pc.o $bootstrapObj
  286. '';
  287. meta.platforms = [ "x86_64-genode" ];
  288. };
  289. base-hw-virt_qemu = buildUpstream {
  290. name = "base-hw-virt_qemu";
  291. outputs = [ "out" "coreObj" "bootstrapObj" ];
  292. KERNEL = "hw";
  293. BOARD = "virt_qemu";
  294. targets = [ "bootstrap" "core" "timer" "lib/ld" ];
  295. patches = basePatches;
  296. postInstall = ''
  297. mv $out/lib/ld-hw.lib.so $out/lib/ld.lib.so
  298. mv $out/bin/hw_timer_drv $out/bin/timer_drv
  299. install build/bin/core-hw-virt_qemu.o $coreObj
  300. install build/bin/bootstrap-hw-virt_qemu.o $bootstrapObj
  301. '';
  302. meta.platforms = [ "aarch64-genode" ];
  303. };
  304. base-linux = buildUpstream {
  305. name = "base-linux";
  306. KERNEL = "linux";
  307. BOARD = "linux";
  308. targets = [ "core" "timer" "lib/ld" ];
  309. patches = basePatches;
  310. postInstall = ''
  311. mv $out/lib/ld-linux.lib.so $out/lib/ld.lib.so
  312. mv $out/bin/linux_timer_drv $out/bin/timer_drv
  313. '';
  314. HOST_INC_DIR = buildPackages.glibc.dev + "/include";
  315. };
  316. base-nova = buildUpstream {
  317. name = "base-nova";
  318. outputs = [ "out" "coreObj" ];
  319. KERNEL = "nova";
  320. targets = [ "core" "timer" "lib/ld" ];
  321. patches = basePatches;
  322. postInstall = ''
  323. mv $out/lib/ld-nova.lib.so $out/lib/ld.lib.so
  324. mv $out/bin/nova_timer_drv $out/bin/timer_drv
  325. install build/bin/core-nova.o $coreObj
  326. '';
  327. };
  328. }