2
0
Fork 0

nixos: persistent file-system storage

This commit is contained in:
Emery Hemingway 2020-12-31 09:36:19 +01:00
parent 983c63aa0b
commit 9940b0fe85
4 changed files with 66 additions and 8 deletions

View File

@ -253,6 +253,26 @@ in {
usb = rumpExt2; usb = rumpExt2;
}.${config.genode.boot.storeBackend}; }.${config.genode.boot.storeBackend};
persistencePolicies = lib.mapAttrsToList (name: _: ''
, Init.Config.Policy::{
, service = "File_system"
, label = Genode.Init.LabelSelector.prefix
"nixos -> ${name}"
, attributes = toMap { root = "/services", writeable = "yes" }
}
'') (filterAttrs (_: child: child.fsPersistence)
config.genode.init.children);
storePolicies = map (name: ''
, Init.Config.Policy::{
, service = "File_system"
, label =
Init.LabelSelector.Type.Partial
{ prefix = Some "nixos -> ${name}", suffix = Some "nix-store" }
, attributes = toMap { root = "/nix/store", writeable = "no" }
}
'') (builtins.attrNames config.genode.init.children);
in builtins.toFile "store_fs.dhall" '' in builtins.toFile "store_fs.dhall" ''
let Genode = env:DHALL_GENODE let Genode = env:DHALL_GENODE
@ -260,6 +280,14 @@ in {
let VFS = Genode.VFS let VFS = Genode.VFS
let persistencePolicies = [ ${
toString persistencePolicies
} ] : List Init.Config.Policy.Type
let storePolicies = [ ${
toString storePolicies
} ] : List Init.Config.Policy.Type
in Init.Child.flat in Init.Child.flat
Init.Child.Attributes::{ Init.Child.Attributes::{
, binary = "vfs" , binary = "vfs"
@ -268,16 +296,11 @@ in {
, content = [ ${storeVfsConfig} ] , content = [ ${storeVfsConfig} ]
, policies = , policies =
[ Init.Config.Policy::{ [ Init.Config.Policy::{
, service = "File_system"
, label = Init.LabelSelector.suffix "nix-store"
, attributes = toMap { root = "/nix/store" }
}
, Init.Config.Policy::{
, service = "File_system" , service = "File_system"
, label = Init.LabelSelector.prefix "store_rom" , label = Init.LabelSelector.prefix "store_rom"
, attributes = toMap { root = "/" } , attributes = toMap { root = "/" }
} }
] ] # persistencePolicies # storePolicies
} }
} }
''; '';

View File

@ -68,6 +68,16 @@ in {
''; '';
}; };
fsPersistence = lib.mkOption {
type = types.bool;
default = false;
description = ''
Whether this child will have access to mutable and persistent storage.
This space is shared among all components for which this option is available
and UNIX permission bits are not honored.
'';
};
configFile = mkOption { configFile = mkOption {
type = types.path; type = types.path;
description = '' description = ''

View File

@ -20,6 +20,7 @@ in λ ( params
, binary : Text , binary : Text
, coreutils : Text , coreutils : Text
, extraVfs : List XML.Type , extraVfs : List XML.Type
, fsPersistence : Bool
, interface : Optional Text , interface : Optional Text
, ramQuotaMiB : Natural , ramQuotaMiB : Natural
} }
@ -90,10 +91,20 @@ in λ ( params
[ VFS.fs [ VFS.fs
VFS.FS::{ VFS.FS::{
, label = "nix-store" , label = "nix-store"
, writeable = "no"
} }
] ]
] ]
] ]
# ( if params.fsPersistence
then [ VFS.fs
VFS.FS::{
, label = "peristence"
, writeable = "yes"
}
]
else [ VFS.leaf "ram" ]
)
# params.extraVfs # params.extraVfs
) )
] ]

View File

@ -5,7 +5,8 @@ with lib; {
type = types.attrsOf (types.submodule ({ name, config, ... }: { type = types.attrsOf (types.submodule ({ name, config, ... }: {
options.genode = { options.genode = {
enable = lib.mkEnableOption "systemd unit to a Genode subsystem translation"; enable =
lib.mkEnableOption "systemd unit to a Genode subsystem translation";
interface = lib.mkOption { interface = lib.mkOption {
type = with types; nullOr str; type = with types; nullOr str;
@ -32,6 +33,16 @@ with lib; {
description = "RAM quota in MiB"; 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.
'';
};
}; };
})); }));
}; };
@ -56,6 +67,7 @@ with lib; {
vfs vfs
vfs_pipe vfs_pipe
]; ];
inherit (service.genode) fsPersistence;
configFile = let configFile = let
args = lib.strings.splitString " " args = lib.strings.splitString " "
(toString service.serviceConfig.ExecStart); (toString service.serviceConfig.ExecStart);
@ -66,6 +78,7 @@ with lib; {
"None Text" "None Text"
else else
''Some "${service.genode.interface}"''; ''Some "${service.genode.interface}"'';
toBool = cond: if cond then "True" else "False";
in pkgs.writeText "${name'}.dhall" '' in pkgs.writeText "${name'}.dhall" ''
${./systemd-runner.dhall} { ${./systemd-runner.dhall} {
, args = ${args'} , args = ${args'}
@ -73,10 +86,11 @@ with lib; {
, coreutils = "${pkgs.coreutils}" , coreutils = "${pkgs.coreutils}"
, extraVfs = ${ , extraVfs = ${
if service.genode.extraVfs == null then if service.genode.extraVfs == null then
"[] : List (env:DHALL_PRELUDE).XML.Type" "[] : List (env:DHALL_GENODE).Prelude.XML.Type"
else else
service.genode.extraVfs service.genode.extraVfs
} }
, fsPersistence = ${toBool service.genode.fsPersistence}
, interface = ${interface} , interface = ${interface}
, ramQuotaMiB = ${toString service.genode.ramQuota} , ramQuotaMiB = ${toString service.genode.ramQuota}
} }