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.

buildBootDescription.nix 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Generate a total boot description by matching the binaries referred to by an init
  2. # configuration with a list of input packages.
  3. { lib, writeText, dhall-json }:
  4. { initConfig, imageInputs, extraBinaries ? [ ], extraRoms ? { } }:
  5. with builtins;
  6. let
  7. extractDrv = lib.runDhallCommand "binaries.json" {
  8. nativeBuildInputs = [ dhall-json ];
  9. } ''
  10. dhall-to-json << EOF > $out
  11. let Genode = env:DHALL_GENODE
  12. let init = ${initConfig}
  13. in Genode.Init.Child.binaries (Genode.Init.toChild init Genode.Init.Attributes::{=})
  14. EOF
  15. '';
  16. binariesJSON = readFile (toString extractDrv);
  17. binaries = lib.unique (fromJSON binariesJSON ++ extraBinaries);
  18. matches = let
  19. f = binary: {
  20. name = binary;
  21. value = let
  22. f = drv:
  23. if lib.hasPrefix "lib" binary && lib.hasSuffix ".so" binary
  24. && pathExists "${drv.lib or drv}/lib" then
  25. toPath "${drv.lib or drv}/lib/${binary}"
  26. else
  27. toPath (if pathExists "${drv}/bin" then
  28. "${drv}/bin/${binary}"
  29. else
  30. "${drv}/${binary}");
  31. in filter pathExists (map f imageInputs);
  32. };
  33. in map f binaries;
  34. binaryPaths = let
  35. f = { name, value }:
  36. let l = length value;
  37. in if l == 1 then {
  38. inherit name;
  39. value = elemAt value 0;
  40. } else if l == 0 then
  41. throw "${name} not found in imageInputs"
  42. else
  43. throw "${name} found in multiple imageInputs, ${toString value}";
  44. in map f matches;
  45. extraList =
  46. lib.mapAttrsToList (name: value: { inherit name value; }) extraRoms;
  47. in writeText "boot.dhall" ''
  48. let Genode = env:DHALL_GENODE
  49. in { config = ${initConfig}
  50. , rom = Genode.BootModules.toRomPaths ([
  51. ${
  52. toString (map ({ name, value }: ''
  53. , { mapKey = "${name}", mapValue = "${value}" }
  54. '') (binaryPaths ++ extraList))
  55. }
  56. ])
  57. }
  58. ''