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

View File

@ -1,57 +1,120 @@
{ config, pkgs, lib, ... }: { 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 { in {
options.genode.gui = { options.genode.gui = {
enable = mkEnableOption "Genode Gui service"; enable = lib.mkEnableOption "Genode Gui service";
consoleLog = { enable = mkEnableOption "console log"; }; 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 = { 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; hardware.genode.framebuffer.enable = cfg.enable;
genode.core.children.nitpicker = mkIf cfg.enable { genode.core.children.nitpicker = lib.mkIf cfg.enable (let
binary = pkgs.genodePackages.nitpicker; nitpicker' = lib.getEris' "bin" pkgs.genodePackages.nitpicker "nitpicker";
in {
binary = nitpicker'.cap;
extraErisInputs = [ nitpicker' ];
configFile = pkgs.writeText "nitpicker.dhall" '' configFile = pkgs.writeText "nitpicker.dhall" ''
let Init = (env:DHALL_SIGIL).Init ${./nitpicker.dhall} {domains = ${toDhall domains'}, policies = [ ${
lib.strings.concatStringsSep ", " cfg.policies
in ${./nitpicker.dhall} } ] }
{ policies =
[ Init.Config.Policy::{
, service = "Gui"
, label = Init.LabelSelector.prefix "consoleLog"
, attributes = toMap { domain = "default" }
}
]
}
''; '';
});
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 { genode.core.children.consoleLog = lib.mkIf cfg.consoleLog.enable (let
"TerminusTTF.ttf" = pkgs.buildPackages.terminus_font_ttf erisInputs = (lib.attrsets.mapAttrs (_: lib.getEris "bin") {
+ "/share/fonts/truetype/TerminusTTF.ttf"; inherit (pkgs.genodePackages) gui_fb log_core terminal terminal_log;
}; }) // (lib.attrsets.mapAttrs (_: lib.getEris "lib") {
inherit (pkgs.genodePackages) vfs_ttf;
genode.core.children.consoleLog = mkIf cfg.consoleLog.enable { });
binary = pkgs.genodePackages.init; in {
extraInputs = with pkgs.genodePackages; [ package = pkgs.genodePackages.init;
gui_fb
log_core
libc
terminal
terminal_log
vfs_ttf
];
coreROMs = [ "core_log" "kernel_log" ]; coreROMs = [ "core_log" "kernel_log" ];
extraErisInputs = builtins.attrValues erisInputs;
configFile = pkgs.writeText "consoleLog.dhall" '' 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 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 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) → λ(binary : Text) →
Init.Child.flat Init.Child.flat
Init.Child.Attributes::{ Init.Child.Attributes::{
@ -14,21 +24,24 @@ in λ(params : { policies : List Init.Config.Policy.Type }) →
, attributes = toMap , attributes = toMap
{ note = "Nitpicker config is extremely fragile!" } { note = "Nitpicker config is extremely fragile!" }
, content = , content =
[ XML.leaf { name = "capture", attributes = XML.emptyAttributes } [ XML.leaf
, XML.leaf { name = "capture", attributes = XML.emptyAttributes }
{ name = "domain" , XML.leaf
, attributes = toMap { name = "background"
{ name = "default" , attributes = toMap { color = "#000000" }
, layer = "1"
, content = "client"
, label = "no"
} }
} ]
, XML.leaf # Prelude.List.map
{ name = "background" Domain
, attributes = toMap { color = "#000000" } XML.Type
} ( λ(domain : Domain) →
] XML.leaf
{ name = "domain"
, attributes =
toMap { name = domain.mapKey } # domain.mapValue
}
)
params.domains
, policies = , policies =
params.policies params.policies
# [ Init.Config.Policy::{ # [ Init.Config.Policy::{
@ -36,8 +49,5 @@ in λ(params : { policies : List Init.Config.Policy.Type }) →
, label = Init.LabelSelector.prefix "fb_drv" , label = Init.LabelSelector.prefix "fb_drv"
} }
] ]
, defaultPolicy = Some Init.Config.DefaultPolicy::{
, attributes = toMap { domain = "default" }
}
} }
} }

View File

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