93 lines
2.6 KiB
Nix
93 lines
2.6 KiB
Nix
# SPDX-License-Identifier: CC0-1.0
|
|
|
|
{ self }:
|
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
{
|
|
options.genodeGuests = with lib;
|
|
let
|
|
genodeOpts = { ... }: {
|
|
options = {
|
|
|
|
name = mkOption {
|
|
example = "webserver";
|
|
type = types.str;
|
|
description = "Name of the Genode subsystem.";
|
|
};
|
|
|
|
config = mkOption {
|
|
type = types.str;
|
|
default = "<config/>";
|
|
description = ''
|
|
Configuration of the Genode subsystem.
|
|
Must be rendered in the Genode XML format.
|
|
'';
|
|
};
|
|
|
|
rom = mkOption {
|
|
default = pkgs: { };
|
|
description = ''
|
|
Function taking a package set and returning an attrset of name to store
|
|
path mappings. Note that this set is the Nixpkgs collection, the native
|
|
Genode packages are found within this set at "genodePackages".
|
|
'';
|
|
example = literalExample ''
|
|
pkgs: {
|
|
nic_drv = "${pkgs.genodePackages.linux_nic_drv}/bin/linux_nic_drv";
|
|
}
|
|
'';
|
|
};
|
|
|
|
};
|
|
};
|
|
|
|
in mkOption {
|
|
type = with lib.types; loaOf (submodule genodeOpts);
|
|
default = { };
|
|
example = {
|
|
foobar = {
|
|
config = "<empty/>";
|
|
rom = pkgs: { };
|
|
};
|
|
};
|
|
description = "Configurations of Genode subsystems.";
|
|
};
|
|
|
|
config = let
|
|
crossSystem = config.nixpkgs.localSystem.system + "-"
|
|
+ pkgs.targetPlatform.platform.kernelArch + "-genode";
|
|
crossPkgs = builtins.trace crossSystem self.legacyPackages.${crossSystem};
|
|
in {
|
|
|
|
systemd.services = let
|
|
inherit (crossPkgs.genodePackages) base-linux;
|
|
toService = name: cfg: {
|
|
description = "Genode subsystem";
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
preStart = let
|
|
rom' = with crossPkgs.genodePackages;
|
|
{
|
|
core = "${base-linux}/bin/core-linux";
|
|
init = "${init}/bin/init";
|
|
"ld.lib.so" = "${base-linux}/bin/ld.lib.so";
|
|
timer = "${base-linux}/bin/linux_timer_drv";
|
|
config = builtins.toFile "${name}.config.xml" cfg.config;
|
|
} // (cfg.rom crossPkgs);
|
|
in builtins.concatStringsSep "\n"
|
|
(lib.mapAttrsToList (name: value: "ln -s ${value} ${name}") rom');
|
|
|
|
serviceConfig = {
|
|
DynamicUser = true;
|
|
RuntimeDirectory = "genode/" + name;
|
|
WorkingDirectory = "/run/genode/" + name;
|
|
ExecStart = "${base-linux}/bin/core-linux";
|
|
};
|
|
};
|
|
in lib.mapAttrs toService config.genodeGuests;
|
|
|
|
};
|
|
|
|
}
|