nixos: remove systemd module
parent
f5f54a2ec2
commit
e8f433559a
@ -1,189 +0,0 @@
|
||||
let Sigil = env:DHALL_SIGIL
|
||||
|
||||
let Prelude = Sigil.Prelude
|
||||
|
||||
let XML = Prelude.XML
|
||||
|
||||
let Libc = Sigil.Libc
|
||||
|
||||
let VFS = Sigil.VFS
|
||||
|
||||
let Init = Sigil.Init
|
||||
|
||||
let Child = Init.Child
|
||||
|
||||
let parentRoutes =
|
||||
Prelude.List.map Text Init.ServiceRoute.Type Init.ServiceRoute.parent
|
||||
|
||||
in λ ( params
|
||||
: { args : List Text
|
||||
, binary : Text
|
||||
, coreutils : Text
|
||||
, extraVfs : List XML.Type
|
||||
, fsPersistence : Bool
|
||||
, interface : Optional Text
|
||||
, ramQuotaMiB : Natural
|
||||
}
|
||||
) →
|
||||
let socketsVfs =
|
||||
merge
|
||||
{ Some =
|
||||
λ(interface : Text) →
|
||||
[ VFS.dir
|
||||
"sockets"
|
||||
[ VFS.fs VFS.FS::{ label = "${interface}.sockets" } ]
|
||||
]
|
||||
, None = [] : List XML.Type
|
||||
}
|
||||
params.interface
|
||||
|
||||
let init =
|
||||
Init::{
|
||||
, routes =
|
||||
parentRoutes [ "File_system", "Rtc", "Terminal", "Timer" ]
|
||||
, children =
|
||||
toMap
|
||||
{ vfs =
|
||||
Child.flat
|
||||
Child.Attributes::{
|
||||
, binary = "vfs"
|
||||
, exitPropagate = True
|
||||
, resources = Sigil.Init.Resources::{
|
||||
, caps = 256
|
||||
, ram = Sigil.units.MiB 8
|
||||
}
|
||||
, config = Init.Config::{
|
||||
, content =
|
||||
[ VFS.vfs
|
||||
( [ VFS.dir
|
||||
"dev"
|
||||
( [ VFS.dir
|
||||
"pipes"
|
||||
[ VFS.leaf "pipe" ]
|
||||
, VFS.leaf "log"
|
||||
, VFS.leaf "null"
|
||||
, VFS.leafAttrs
|
||||
"terminal"
|
||||
( toMap
|
||||
{ name = "entropy"
|
||||
, label = "entropy"
|
||||
}
|
||||
)
|
||||
, VFS.leaf "rtc"
|
||||
, VFS.leaf "zero"
|
||||
]
|
||||
# socketsVfs
|
||||
)
|
||||
, VFS.dir
|
||||
"usr"
|
||||
[ VFS.dir
|
||||
"bin"
|
||||
[ VFS.symlink
|
||||
"env"
|
||||
"${params.coreutils}/bin/env"
|
||||
]
|
||||
]
|
||||
, VFS.dir "tmp" [ VFS.leaf "ram" ]
|
||||
, VFS.dir
|
||||
"nix"
|
||||
[ VFS.dir
|
||||
"store"
|
||||
[ VFS.fs
|
||||
VFS.FS::{
|
||||
, label = "nix-store"
|
||||
, writeable = "no"
|
||||
}
|
||||
]
|
||||
]
|
||||
]
|
||||
# ( if params.fsPersistence
|
||||
then [ VFS.fs
|
||||
VFS.FS::{
|
||||
, label = "peristence"
|
||||
, writeable = "yes"
|
||||
}
|
||||
]
|
||||
else [ VFS.leaf "ram" ]
|
||||
)
|
||||
# params.extraVfs
|
||||
)
|
||||
]
|
||||
, policies =
|
||||
[ Init.Config.Policy::{
|
||||
, service = "File_system"
|
||||
, label = Init.LabelSelector.prefix "ExecStart"
|
||||
, attributes = toMap
|
||||
{ root = "/", writeable = "yes" }
|
||||
}
|
||||
, Init.Config.Policy::{
|
||||
, service = "File_system"
|
||||
, label = Init.LabelSelector.prefix "vfs_rom"
|
||||
, attributes = toMap
|
||||
{ root = "/", writeable = "no" }
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
, vfs_rom =
|
||||
Child.flat
|
||||
Child.Attributes::{
|
||||
, binary = "cached_fs_rom"
|
||||
, resources = Sigil.Init.Resources::{
|
||||
, ram = Sigil.units.MiB 32
|
||||
}
|
||||
, config = Init.Config::{
|
||||
, policies =
|
||||
[ Init.Config.Policy::{
|
||||
, service = "ROM"
|
||||
, label = Init.LabelSelector.prefix "ExecStart"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
# [ { mapKey = "ExecStart"
|
||||
, mapValue =
|
||||
Child.flat
|
||||
Child.Attributes::{
|
||||
, binary = params.binary
|
||||
, exitPropagate = True
|
||||
, resources = Sigil.Init.Resources::{
|
||||
, caps = 256
|
||||
, ram = Sigil.units.MiB params.ramQuotaMiB
|
||||
}
|
||||
, config =
|
||||
( Libc.toConfig
|
||||
Libc::{
|
||||
, stdin = Some "/dev/null"
|
||||
, stdout = Some "/dev/log"
|
||||
, stderr = Some "/dev/log"
|
||||
, pipe = Some "/dev/pipes"
|
||||
, rng = Some "/dev/entropy"
|
||||
, rtc = Some "/dev/rtc"
|
||||
, socket = Some "/dev/sockets"
|
||||
, vfs = [ VFS.leaf "fs" ]
|
||||
, args = [ params.binary ] # params.args
|
||||
}
|
||||
)
|
||||
with attributes = toMap { ld_verbose = "yes" }
|
||||
, routes =
|
||||
Prelude.List.map
|
||||
Text
|
||||
Init.ServiceRoute.Type
|
||||
( λ(label : Text) →
|
||||
Init.ServiceRoute.parentLabel
|
||||
"ROM"
|
||||
(Some label)
|
||||
(Some label)
|
||||
)
|
||||
[ "libc.lib.so"
|
||||
, "libm.lib.so"
|
||||
, "posix.lib.so"
|
||||
, "vfs.lib.so"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
in Init.toChild init Init.Attributes::{=}
|
@ -1,104 +0,0 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
with lib; {
|
||||
|
||||
options.systemd.services = lib.mkOption {
|
||||
type = types.attrsOf (types.submodule ({ name, config, ... }: {
|
||||
options.genode = {
|
||||
|
||||
enable =
|
||||
lib.mkEnableOption "systemd unit to a Genode subsystem translation";
|
||||
|
||||
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.
|
||||
'';
|
||||
};
|
||||
|
||||
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";
|
||||
};
|
||||
|
||||
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.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
}));
|
||||
};
|
||||
|
||||
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 = rec {
|
||||
extraInputs = with pkgs;
|
||||
with genodePackages; [
|
||||
bash
|
||||
cached_fs_rom
|
||||
libc
|
||||
posix
|
||||
vfs
|
||||
vfs_pipe
|
||||
];
|
||||
inherit (service.genode) fsPersistence;
|
||||
binary = builtins.head args;
|
||||
configFile = let
|
||||
args = lib.strings.splitString " "
|
||||
(toString service.serviceConfig.ExecStart);
|
||||
args' = ''[ "${concatStringsSep ''", "'' (builtins.tail args)}" ]'';
|
||||
# TODO: service.environment;
|
||||
interface = if service.genode.interface == null then
|
||||
"None Text"
|
||||
else
|
||||
''Some "${service.genode.interface}"'';
|
||||
toBool = cond: if cond then "True" else "False";
|
||||
in pkgs.writeText "${name'}.dhall" ''
|
||||
${./systemd-runner.dhall} {
|
||||
, args = ${args'}
|
||||
, binary = "${binary}"
|
||||
, coreutils = "${pkgs.coreutils}"
|
||||
, extraVfs = ${
|
||||
if service.genode.extraVfs == null then
|
||||
"[] : List (env:DHALL_SIGIL).Prelude.XML.Type"
|
||||
else
|
||||
service.genode.extraVfs
|
||||
}
|
||||
, fsPersistence = ${toBool service.genode.fsPersistence}
|
||||
, interface = ${interface}
|
||||
, ramQuotaMiB = ${toString service.genode.ramQuota}
|
||||
}
|
||||
'';
|
||||
};
|
||||
}) (filterAttrs (name: service: service.genode.enable)
|
||||
config.systemd.services);
|
||||
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue