2020-11-01 20:21:27 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
with lib; {
|
|
|
|
|
|
|
|
options.systemd.services = lib.mkOption {
|
|
|
|
type = types.attrsOf (types.submodule ({ name, config, ... }: {
|
2020-11-03 19:21:10 +01:00
|
|
|
options.genode = {
|
|
|
|
|
2020-12-31 09:36:19 +01:00
|
|
|
enable =
|
|
|
|
lib.mkEnableOption "systemd unit to a Genode subsystem translation";
|
2020-11-03 19:21:10 +01:00
|
|
|
|
|
|
|
interface = lib.mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
example = "eth0";
|
|
|
|
description = ''
|
|
|
|
Grant access to an IP stack for this interface.
|
|
|
|
Only UDP and TCP are supported. No raw device access.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-12-03 12:51:16 +01:00
|
|
|
extraVfs = lib.mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Extra configuration to be appended to the VFS of the service.
|
|
|
|
Dhall type is Prelude/XML/Type.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ramQuota = lib.mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 16;
|
|
|
|
description = "RAM quota in MiB";
|
|
|
|
};
|
|
|
|
|
2020-12-31 09:36:19 +01:00
|
|
|
fsPersistence = lib.mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether this service will have access to mutable and persistent storage.
|
|
|
|
This space is shared among all services for which this option is available
|
|
|
|
and UNIX permission bits are not honored.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
};
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2020-11-03 19:21:10 +01:00
|
|
|
config = {
|
|
|
|
|
|
|
|
services.klogd.enable = false;
|
|
|
|
# The default is determined by checking the Linux version
|
|
|
|
# which cannot be evaluated here.
|
|
|
|
|
|
|
|
genode.init.children = mapAttrs' (name: service:
|
|
|
|
let name' = "services." + name;
|
|
|
|
in {
|
|
|
|
name = name';
|
|
|
|
value = {
|
|
|
|
inputs = with pkgs;
|
|
|
|
with genodePackages; [
|
|
|
|
bash
|
|
|
|
cached_fs_rom
|
|
|
|
libc
|
|
|
|
posix
|
|
|
|
vfs
|
|
|
|
vfs_pipe
|
|
|
|
];
|
2020-12-31 09:36:19 +01:00
|
|
|
inherit (service.genode) fsPersistence;
|
2020-11-03 19:21:10 +01:00
|
|
|
configFile = let
|
2020-11-29 14:49:52 +01:00
|
|
|
args = lib.strings.splitString " "
|
|
|
|
(toString service.serviceConfig.ExecStart);
|
|
|
|
binary = builtins.head args;
|
|
|
|
args' = ''[ "${concatStringsSep ''", "'' (builtins.tail args)}" ]'';
|
2020-11-24 20:24:07 +01:00
|
|
|
# TODO: service.environment;
|
2020-11-03 19:21:10 +01:00
|
|
|
interface = if service.genode.interface == null then
|
|
|
|
"None Text"
|
|
|
|
else
|
|
|
|
''Some "${service.genode.interface}"'';
|
2020-12-31 09:36:19 +01:00
|
|
|
toBool = cond: if cond then "True" else "False";
|
2020-11-03 19:21:10 +01:00
|
|
|
in pkgs.writeText "${name'}.dhall" ''
|
|
|
|
${./systemd-runner.dhall} {
|
2020-11-29 14:49:52 +01:00
|
|
|
, args = ${args'}
|
|
|
|
, binary = "${binary}"
|
2020-11-03 19:21:10 +01:00
|
|
|
, coreutils = "${pkgs.coreutils}"
|
2020-12-03 12:51:16 +01:00
|
|
|
, extraVfs = ${
|
|
|
|
if service.genode.extraVfs == null then
|
2020-12-31 09:36:19 +01:00
|
|
|
"[] : List (env:DHALL_GENODE).Prelude.XML.Type"
|
2020-12-03 12:51:16 +01:00
|
|
|
else
|
|
|
|
service.genode.extraVfs
|
|
|
|
}
|
2020-12-31 09:36:19 +01:00
|
|
|
, fsPersistence = ${toBool service.genode.fsPersistence}
|
2020-11-03 19:21:10 +01:00
|
|
|
, interface = ${interface}
|
2020-12-03 12:51:16 +01:00
|
|
|
, ramQuotaMiB = ${toString service.genode.ramQuota}
|
2020-11-03 19:21:10 +01:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}) (filterAttrs (name: service: service.genode.enable)
|
|
|
|
config.systemd.services);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
}
|