nixos: rewrite gui module

This commit is contained in:
Ehmry - 2021-04-15 09:25:28 +02:00
parent 48966025df
commit 7ee13bad02
4 changed files with 202 additions and 114 deletions

View File

@ -14,31 +14,34 @@ let Resources = Init.Resources
let ServiceRoute = Init.ServiceRoute
let routeLogRom =
let routeRom =
λ(label : Text) → ServiceRoute.parentLabel "ROM" (Some "log") (Some label)
in λ(params : { fontFile : Text }) →
in λ ( params
: { gui_fb : Text
, fontFile : Text
, log_core : Text
, terminal : Text
, terminal_log : Text
, vfs_ttf : Text
}
) →
λ(binary : Text) →
Init.toChild
Init::{
, verbose = True
, routes =
[ Init.ServiceRoute.parent "Gui", Init.ServiceRoute.parent "Timer" ]
, children = toMap
{ gui_fb =
, routes = [ Init.ServiceRoute.parent "Timer" ]
, children =
[ { mapKey = "gui_fb"
, mapValue =
Child.flat
Child.Attributes::{
, binary = "${pkgs.genodePackages.gui_fb}/bin/gui_fb"
, binary = params.gui_fb
, exitPropagate = True
, resources = Resources::{ ram = Sigil.units.MiB 8 }
, routes = [ Init.ServiceRoute.parent "Gui" ]
, config = Init.Config::{
, attributes = toMap
{ origin = "top_right"
, xpos = "0"
, ypos = "0"
, initial_width = "1024"
, initial_height = "768"
}
{ origin = "top_left", xpos = "0", ypos = "0" }
, policies =
[ Init.Config.Policy::{
, service = "Framebuffer"
@ -51,10 +54,12 @@ in λ(params : { fontFile : Text }) →
]
}
}
, terminal =
}
, { mapKey = "terminal"
, mapValue =
Child.flat
Child.Attributes::{
, binary = "${pkgs.genodePackages.terminal}/bin/terminal"
, binary = params.terminal
, exitPropagate = True
, resources = Resources::{
, caps = 256
@ -63,14 +68,19 @@ in λ(params : { fontFile : Text }) →
, routes =
[ ServiceRoute.child "Framebuffer" "gui_fb"
, ServiceRoute.child "Input" "gui_fb"
, ServiceRoute.parent "File_system"
, ServiceRoute.parentLabel
"ROM"
(Some "vfs_ttf.lib.so")
(Some params.vfs_ttf)
]
, config = Init.Config::{
, content =
[ XML.element
{ name = "palette"
, attributes = toMap
{ uri = "https://pippin.gimp.org/ametameric/" }
{ uri = "https://pippin.gimp.org/ametameric/"
, notes = "Black on white is unsupported."
}
, content =
let color =
λ(index : Natural) →
@ -129,36 +139,44 @@ in λ(params : { fontFile : Text }) →
]
}
}
, terminal_log =
}
, { mapKey = "terminal_log"
, mapValue =
Child.flat
Child.Attributes::{
, binary =
"${pkgs.genodePackages.terminal_log}/bin/terminal_log"
, binary = params.terminal_log
, config = Init.Config::{
, policies =
[ Init.Config.Policy::{
, service = "LOG"
, label = Init.LabelSelector.prefix "core"
, label = Init.LabelSelector.prefix "core_log"
}
, Init.Config.Policy::{
, service = "LOG"
, label = Init.LabelSelector.prefix "kernel"
, label = Init.LabelSelector.prefix "kernel_log"
}
]
}
}
, core =
}
, { mapKey = "core_log"
, mapValue =
Child.flat
Child.Attributes::{
, binary = "${pkgs.genodePackages.log_core}/bin/log_core"
, routes = [ routeLogRom "core_log" ]
}
, kernel =
Child.flat
Child.Attributes::{
, binary = "${pkgs.genodePackages.log_core}/bin/log_core"
, routes = [ routeLogRom "kernel_log" ]
, binary = params.log_core
, priorityOffset = 1
, routes = [ routeRom "core_log" ]
}
}
, { mapKey = "kernel_log"
, mapValue =
Child.flat
Child.Attributes::{
, binary = params.log_core
, priorityOffset = 1
, routes = [ routeRom "kernel_log" ]
}
}
]
}
Init.Attributes.default

View File

@ -1,57 +1,120 @@
{ config, pkgs, lib, ... }:
with lib;
let
toDhall = lib.generators.toDhall { };
cfg = config.genode.gui;
domains' = lib.attrsets.mapAttrsToList (mapKey: attrs: {
inherit mapKey;
mapValue = lib.attrsets.mapAttrsToList
(mapKey: mapValue: { inherit mapKey mapValue; }) attrs;
}) cfg.domains;
let cfg = config.genode.gui;
in {
options.genode.gui = {
enable = mkEnableOption "Genode Gui service";
consoleLog = { enable = mkEnableOption "console log"; };
enable = lib.mkEnableOption "Genode Gui service";
consoleLog = {
enable = lib.mkEnableOption "console log";
layer = lib.mkOption {
type = lib.types.ints.positive;
default = 1;
};
};
policies = lib.mkOption {
type = with lib.types; listOf path;
default = [ ];
description = ''
List of policies to append to the Genode GUI server.
Type is Init.Config.Policy.Type.
'';
};
domains = lib.mkOption {
type = with lib.types; attrsOf (attrsOf str);
description = ''
List of domains to configure at the Gui server.
Partially documented at the Nitpicker README,
consult the implementation when in doubt.
<link xlink:href="https://github.com/genodelabs/genode/blob/master/repos/os/src/server/nitpicker/README"/>
'';
example = {
pointer = {
layer = "1";
content = "client";
label = "no";
origin = "pointer";
};
default = {
layer = "2";
color = "#052944";
hover = "always";
focus = "click";
};
};
};
};
config = {
genode.gui.enable = cfg.consoleLog.enable;
genode.gui.enable = lib.mkDefault cfg.consoleLog.enable;
genode.gui.policies = lib.optional cfg.consoleLog.enable
(builtins.toFile ("consoleLog-gui-policy.dhall") ''
let Init = (env:DHALL_SIGIL).Init
in Init.Config.Policy::{
, service = "Gui"
, label = Init.LabelSelector.prefix "consoleLog"
, attributes = toMap { domain = "consoleLog" }
}
'');
genode.gui.domains.consoleLog = lib.mkIf cfg.consoleLog.enable {
layer = toString cfg.consoleLog.layer;
label = "no";
content = "client";
};
hardware.genode.framebuffer.enable = cfg.enable;
genode.core.children.nitpicker = mkIf cfg.enable {
binary = pkgs.genodePackages.nitpicker;
genode.core.children.nitpicker = lib.mkIf cfg.enable (let
nitpicker' = lib.getEris' "bin" pkgs.genodePackages.nitpicker "nitpicker";
in {
binary = nitpicker'.cap;
extraErisInputs = [ nitpicker' ];
configFile = pkgs.writeText "nitpicker.dhall" ''
let Init = (env:DHALL_SIGIL).Init
in ${./nitpicker.dhall}
{ policies =
[ Init.Config.Policy::{
, service = "Gui"
, label = Init.LabelSelector.prefix "consoleLog"
, attributes = toMap { domain = "default" }
}
]
}
${./nitpicker.dhall} {domains = ${toDhall domains'}, policies = [ ${
lib.strings.concatStringsSep ", " cfg.policies
} ] }
'';
});
genode.core.romModules = lib.mkIf cfg.consoleLog.enable {
"FiraCode-VF.ttf" = pkgs.buildPackages.fira-code
+ "/share/fonts/truetype/FiraCode-VF.ttf";
};
genode.core.romModules = mkIf cfg.consoleLog.enable {
"TerminusTTF.ttf" = pkgs.buildPackages.terminus_font_ttf
+ "/share/fonts/truetype/TerminusTTF.ttf";
};
genode.core.children.consoleLog = mkIf cfg.consoleLog.enable {
binary = pkgs.genodePackages.init;
extraInputs = with pkgs.genodePackages; [
gui_fb
log_core
libc
terminal
terminal_log
vfs_ttf
];
genode.core.children.consoleLog = lib.mkIf cfg.consoleLog.enable (let
erisInputs = (lib.attrsets.mapAttrs (_: lib.getEris "bin") {
inherit (pkgs.genodePackages) gui_fb log_core terminal terminal_log;
}) // (lib.attrsets.mapAttrs (_: lib.getEris "lib") {
inherit (pkgs.genodePackages) vfs_ttf;
});
in {
package = pkgs.genodePackages.init;
coreROMs = [ "core_log" "kernel_log" ];
extraErisInputs = builtins.attrValues erisInputs;
configFile = pkgs.writeText "consoleLog.dhall" ''
${./consoleLog.dhall} { fontFile = "TerminusTTF.ttf" }
${./consoleLog.dhall} ${
toDhall (lib.attrsets.mapAttrs (_: builtins.getAttr "cap") erisInputs
// {
fontFile = "FiraCode-VF.ttf";
})
}
'';
};
});
};
}

View File

@ -1,10 +1,20 @@
let Sigil = env:DHALL_SIGIL
let XML = Sigil.Prelude.XML
let Prelude = Sigil.Prelude
let Map = Prelude.Map
let Attributes = Map.Type Text Text
let Domain = Map.Entry Text Attributes
let XML = Prelude.XML
let Init = Sigil.Init
in λ(params : { policies : List Init.Config.Policy.Type }) →
in λ ( params
: { domains : List Domain, policies : List Init.Config.Policy.Type }
) →
λ(binary : Text) →
Init.Child.flat
Init.Child.Attributes::{
@ -14,21 +24,24 @@ in λ(params : { policies : List Init.Config.Policy.Type }) →
, attributes = toMap
{ note = "Nitpicker config is extremely fragile!" }
, content =
[ XML.leaf { name = "capture", attributes = XML.emptyAttributes }
, XML.leaf
{ name = "domain"
, attributes = toMap
{ name = "default"
, layer = "1"
, content = "client"
, label = "no"
[ XML.leaf
{ name = "capture", attributes = XML.emptyAttributes }
, XML.leaf
{ name = "background"
, attributes = toMap { color = "#000000" }
}
}
, XML.leaf
{ name = "background"
, attributes = toMap { color = "#000000" }
}
]
]
# Prelude.List.map
Domain
XML.Type
( λ(domain : Domain) →
XML.leaf
{ name = "domain"
, attributes =
toMap { name = domain.mapKey } # domain.mapValue
}
)
params.domains
, policies =
params.policies
# [ Init.Config.Policy::{
@ -36,8 +49,5 @@ in λ(params : { policies : List Init.Config.Policy.Type }) →
, label = Init.LabelSelector.prefix "fb_drv"
}
]
, defaultPolicy = Some Init.Config.DefaultPolicy::{
, attributes = toMap { domain = "default" }
}
}
}

View File

@ -1,8 +1,8 @@
{ config, pkgs, lib, ... }:
with lib;
{
let cfg = config.hardware.genode.framebuffer;
in {
options.hardware.genode.framebuffer = {
enable = lib.mkEnableOption "framebuffer driver";
driver = mkOption {
@ -13,8 +13,7 @@ with lib;
config = {
hardware.genode.platform.policies =
lib.optional config.hardware.genode.framebuffer.enable
hardware.genode.platform.policies = lib.optional cfg.enable
(builtins.toFile ("framebuffer.platform-policy.dhall") ''
let Sigil = env:DHALL_SIGIL
@ -28,33 +27,31 @@ with lib;
}
'');
genode.core.children.fb_drv =
mkIf config.hardware.genode.framebuffer.enable {
package = with pkgs.genodePackages;
{
boot = boot_fb_drv;
vesa = vesa_drv;
}.${config.hardware.genode.framebuffer.driver};
configFile = builtins.toFile "fb_drv.dhall" ''
let Sigil = env:DHALL_SIGIL
genode.core.children.fb_drv = mkIf cfg.enable {
package = with pkgs.genodePackages;
{
boot = boot_fb_drv;
vesa = vesa_drv;
}.${cfg.driver};
configFile = builtins.toFile "fb_drv.dhall" ''
let Sigil = env:DHALL_SIGIL
let Init = Sigil.Init
let Init = Sigil.Init
in λ(binary : Text)
Init.Child.flat
Init.Child.Attributes::{
, binary
, resources = Init.Resources::{ caps = 256, ram = Sigil.units.MiB 32 }
, routes =
[ Init.ServiceRoute.parent "IO_MEM"
, Init.ServiceRoute.parent "IO_PORT"
]
}
'';
};
in λ(binary : Text)
Init.Child.flat
Init.Child.Attributes::{
, binary
, resources = Init.Resources::{ caps = 256, ram = Sigil.units.MiB 32 }
, routes =
[ Init.ServiceRoute.parent "IO_MEM"
, Init.ServiceRoute.parent "IO_PORT"
]
}
'';
};
virtualisation.graphics =
lib.mkDefault config.hardware.genode.framebuffer.enable;
virtualisation.graphics = lib.mkDefault cfg.enable;
};