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.

genode-core.nix 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. { config, pkgs, lib, modulesPath, ... }:
  2. with lib;
  3. let localPackages = pkgs.buildPackages;
  4. in {
  5. options.genode = {
  6. core = {
  7. prefix = mkOption {
  8. type = types.str;
  9. example = "hw-pc-";
  10. };
  11. supportedSystems = mkOption {
  12. type = types.listOf types.str;
  13. example = [ "i686-genode" "x86_64-genode" ];
  14. };
  15. basePackages = mkOption { type = types.listOf types.package; };
  16. };
  17. boot = {
  18. kernel = mkOption {
  19. type = types.path;
  20. default = "${pkgs.genodePackages.bender}/bender";
  21. };
  22. initrd = mkOption {
  23. type = types.str;
  24. default = "${pkgs.genodePackages.bender}/bender";
  25. description = "Path to an image or a command-line arguments";
  26. };
  27. configFile = mkOption {
  28. type = types.path;
  29. description = ''
  30. Dhall boot configuration. See
  31. https://git.sr.ht/~ehmry/dhall-genode/tree/master/Boot/package.dhall
  32. '';
  33. };
  34. image = mkOption {
  35. type = types.path;
  36. description =
  37. "Boot image containing the base component binaries and configuration.";
  38. };
  39. romModules = mkOption {
  40. type = types.attrsOf types.path;
  41. description = "Attr set of initial ROM modules";
  42. };
  43. };
  44. };
  45. config = let
  46. initInputs = unique config.genode.init.inputs;
  47. addManifest = drv:
  48. drv // {
  49. manifest =
  50. localPackages.runCommand "${drv.name}.dhall" { inherit drv; } ''
  51. set -eu
  52. echo -n '[' >> $out
  53. find $drv/ -type f -printf ',{mapKey= "%f",mapValue="%p"}' >> $out
  54. ${if builtins.elem "lib" drv.outputs then
  55. ''
  56. find ${drv.lib}/ -type f -printf ',{mapKey= "%f",mapValue="%p"}' >> $out''
  57. else
  58. ""}
  59. echo -n ']' >> $out
  60. '';
  61. };
  62. mergeManifests = inputs:
  63. localPackages.writeTextFile {
  64. name = "manifest.dhall";
  65. text = with builtins;
  66. let
  67. f = head: input:
  68. if hasAttr "manifest" input then
  69. ''
  70. ${head}, { mapKey = "${
  71. lib.getName input
  72. }", mapValue = ${input.manifest} }''
  73. else
  74. abort "${input.pname} does not have a manifest";
  75. in (foldl' f "[" inputs) + "]";
  76. };
  77. in {
  78. assertions = [{
  79. assertion = builtins.any (s: s == config.nixpkgs.system)
  80. config.genode.core.supportedSystems;
  81. message = "invalid Genode core for this system";
  82. }];
  83. genode.boot.configFile = let
  84. tarball =
  85. "${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar";
  86. manifest = mergeManifests (map addManifest
  87. (config.genode.core.basePackages ++ [ config.system.build.tarball ]
  88. ++ (with pkgs.genodePackages; [ init cached_fs_rom vfs ])));
  89. in localPackages.runCommand "boot.dhall" { } ''
  90. cat > $out << EOF
  91. ${./store-wrapper.dhall}
  92. (${config.genode.init.configFile})
  93. "${config.system.build.tarball.fileName}.tar"
  94. $(stat --format '%s' ${tarball})
  95. ${config.system.build.storeManifest} ${manifest}
  96. EOF
  97. '';
  98. system.build.storeManifest = mergeManifests (map addManifest initInputs);
  99. # Create the tarball of the store to live in core ROM
  100. system.build.tarball =
  101. pkgs.callPackage "${modulesPath}/../lib/make-system-tarball.nix" {
  102. contents = [ ];
  103. storeContents = [
  104. {
  105. # assume that the init config will depend
  106. # on every store path needed to boot
  107. object = config.genode.init.configFile;
  108. symlink = "/config.dhall";
  109. }
  110. {
  111. object = pkgs.buildPackages.symlinkJoin {
  112. name = config.system.name + ".rom";
  113. paths = config.genode.init.inputs;
  114. };
  115. symlink = "/rom";
  116. }
  117. ];
  118. compressCommand = "cat";
  119. compressionExtension = "";
  120. };
  121. system.build.initXml = pkgs.buildPackages.runCommand "init.xml" {
  122. nativeBuildInputs = with pkgs.buildPackages; [ dhall xorg.lndir ];
  123. DHALL_GENODE = "${pkgs.genodePackages.dhallGenode}/binary.dhall";
  124. BOOT_CONFIG = config.genode.boot.configFile;
  125. } ''
  126. export XDG_CACHE_HOME=$NIX_BUILD_TOP
  127. lndir -silent \
  128. ${pkgs.genodePackages.dhallGenode}/.cache \
  129. $XDG_CACHE_HOME
  130. dhall text <<< "(env:DHALL_GENODE).Init.render (env:BOOT_CONFIG).config" > $out
  131. '';
  132. };
  133. }