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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. { system, localSystem, crossSystem, genodepkgs, nixpkgs, apps }:
  2. let
  3. thisSystem = builtins.getAttr system;
  4. inherit (nixpkgs) buildPackages;
  5. testPkgs = thisSystem genodepkgs.packages;
  6. dhallCachePrelude = ''
  7. export XDG_CACHE_HOME=$NIX_BUILD_TOP
  8. export DHALL_GENODE="${testPkgs.dhallGenode}/binary.dhall";
  9. ${buildPackages.xorg.lndir}/bin/lndir -silent \
  10. ${testPkgs.dhallGenode}/.cache \
  11. $XDG_CACHE_HOME
  12. '';
  13. in rec {
  14. runDhallCommand = name: env: script:
  15. nixpkgs.runCommand name (env // {
  16. nativeBuildInputs = [ buildPackages.dhall ]
  17. ++ env.nativeBuildInputs or [ ];
  18. }) ''
  19. ${dhallCachePrelude}
  20. ${script}
  21. '';
  22. linuxScript = name: env: bootDhall:
  23. runDhallCommand name env ''
  24. dhall to-directory-tree --output $out \
  25. <<< "${./linux-script.dhall} (${bootDhall}) \"$out\""
  26. '';
  27. compileBoot = name: env: bootDhall:
  28. runDhallCommand "${name}-boot" env ''
  29. dhall to-directory-tree --output $out \
  30. <<< "${./compile-boot.dhall} (${bootDhall}) \"$out\""
  31. dhall <<< "(${bootDhall}).config" \
  32. | dhall encode \
  33. > $out/config.dhall.bin
  34. '';
  35. hwImage = coreLinkAddr: bootstrapLinkAddr: basePkg: name:
  36. { gzip ? false, ... }@env:
  37. boot:
  38. nixpkgs.stdenv.mkDerivation {
  39. name = name + "-hw-image";
  40. build = compileBoot name env boot;
  41. nativeBuildInputs = [ buildPackages.dhall ];
  42. buildCommand = let
  43. bootstrapDhall =
  44. # snippet used to nest core.elf into image.elf
  45. builtins.toFile "boostrap.dall" ''
  46. let Genode = env:DHALL_GENODE
  47. in { config = Genode.Init.default
  48. , rom =
  49. Genode.BootModules.toRomPaths
  50. [ { mapKey = "core.elf", mapValue = "./core.elf" } ]
  51. }
  52. '';
  53. in ''
  54. ${dhallCachePrelude}
  55. build_core() {
  56. local lib="$1"
  57. local modules="$2"
  58. local link_address="$3"
  59. local out="$4"
  60. # compile the boot modules into one object file
  61. $CC -c -x assembler -o "boot_modules.o" "$modules"
  62. # link final image
  63. LD="${buildPackages.binutils}/bin/${buildPackages.binutils.targetPrefix}ld"
  64. $LD \
  65. --strip-all \
  66. -T${testPkgs.genodeSources}/repos/base/src/ld/genode.ld \
  67. -z max-page-size=0x1000 \
  68. -Ttext=$link_address -gc-sections \
  69. "$lib" "boot_modules.o" \
  70. -o $out
  71. }
  72. build_core \
  73. "${basePkg.coreObj}" \
  74. "$build/modules_asm" \
  75. ${coreLinkAddr} \
  76. core.elf
  77. dhall to-directory-tree --output bootstrap \
  78. <<< "${./compile-boot.dhall} ${bootstrapDhall} \"bootstrap\""
  79. mkdir -p $out
  80. build_core \
  81. "${basePkg.bootstrapObj}" \
  82. bootstrap/modules_asm \
  83. ${bootstrapLinkAddr} \
  84. $out/image.elf
  85. '' + nixpkgs.lib.optionalString gzip "gzip $out/image.elf";
  86. };
  87. novaImage = name:
  88. { gzip ? false, ... }@env:
  89. boot:
  90. nixpkgs.stdenv.mkDerivation {
  91. name = name + "-nova-image";
  92. build = compileBoot name env boot;
  93. buildCommand = ''
  94. mkdir -p $out
  95. # compile the boot modules into one object file
  96. $CC -c -x assembler -o "boot_modules.o" "$build/modules_asm"
  97. # link final image
  98. LD="${buildPackages.binutils}/bin/${buildPackages.binutils.targetPrefix}ld"
  99. $LD --strip-all -nostdlib \
  100. -T${testPkgs.genodeSources}/repos/base/src/ld/genode.ld \
  101. -T${testPkgs.genodeSources}/repos/base-nova/src/core/core-bss.ld \
  102. -z max-page-size=0x1000 \
  103. -Ttext=0x100000 -gc-sections \
  104. "${testPkgs.base-nova.coreObj}" boot_modules.o \
  105. -o $out/image.elf
  106. '' + nixpkgs.lib.optionalString gzip "gzip $out/image.elf";
  107. };
  108. mergeManifests = inputs:
  109. nixpkgs.writeTextFile {
  110. name = "manifest.dhall";
  111. text = with builtins;
  112. let
  113. f = head: input:
  114. if hasAttr "manifest" input then
  115. ''
  116. ${head}, { mapKey = "${
  117. nixpkgs.lib.getName input
  118. }", mapValue = ${input.manifest} }''
  119. else
  120. abort "${input.pname} does not have a manifest";
  121. in (foldl' f "[" inputs) + "]";
  122. };
  123. }