Browse Source

nixos: persistent file-system storage

master
Emery Hemingway 3 months ago
parent
commit
9940b0fe85

+ 29
- 6
nixos-modules/genode-core.nix View File

@@ -253,6 +253,26 @@ in {
253 253
               usb = rumpExt2;
254 254
             }.${config.genode.boot.storeBackend};
255 255
 
256
+            persistencePolicies = lib.mapAttrsToList (name: _: ''
257
+              , Init.Config.Policy::{
258
+                  , service = "File_system"
259
+                  , label = Genode.Init.LabelSelector.prefix
260
+                      "nixos -> ${name}"
261
+                  , attributes = toMap { root = "/services", writeable = "yes" }
262
+                  }
263
+            '') (filterAttrs (_: child: child.fsPersistence)
264
+              config.genode.init.children);
265
+
266
+            storePolicies = map (name: ''
267
+              , Init.Config.Policy::{
268
+                , service = "File_system"
269
+                , label =
270
+                    Init.LabelSelector.Type.Partial
271
+                      { prefix = Some "nixos -> ${name}", suffix = Some "nix-store" }
272
+                , attributes = toMap { root = "/nix/store", writeable = "no" }
273
+                }
274
+            '') (builtins.attrNames config.genode.init.children);
275
+
256 276
           in builtins.toFile "store_fs.dhall" ''
257 277
             let Genode = env:DHALL_GENODE
258 278
 
@@ -260,6 +280,14 @@ in {
260 280
 
261 281
             let VFS = Genode.VFS
262 282
 
283
+            let persistencePolicies = [ ${
284
+              toString persistencePolicies
285
+            } ] : List Init.Config.Policy.Type
286
+
287
+            let storePolicies = [ ${
288
+              toString storePolicies
289
+            } ] : List Init.Config.Policy.Type
290
+
263 291
             in  Init.Child.flat
264 292
                   Init.Child.Attributes::{
265 293
                   , binary = "vfs"
@@ -268,16 +296,11 @@ in {
268 296
                     , content = [ ${storeVfsConfig} ]
269 297
                     , policies =
270 298
                       [ Init.Config.Policy::{
271
-                        , service = "File_system"
272
-                        , label = Init.LabelSelector.suffix "nix-store"
273
-                        , attributes = toMap { root = "/nix/store" }
274
-                        }
275
-                      , Init.Config.Policy::{
276 299
                         , service = "File_system"
277 300
                         , label = Init.LabelSelector.prefix "store_rom"
278 301
                         , attributes = toMap { root = "/" }
279 302
                         }
280
-                      ]
303
+                      ] # persistencePolicies # storePolicies
281 304
                     }
282 305
                   }
283 306
           '';

+ 10
- 0
nixos-modules/genode-init.nix View File

@@ -68,6 +68,16 @@ in {
68 68
               '';
69 69
             };
70 70
 
71
+            fsPersistence = lib.mkOption {
72
+              type = types.bool;
73
+              default = false;
74
+              description = ''
75
+                Whether this child will have access to mutable and persistent storage.
76
+                This space is shared among all components for which this option is available
77
+                and UNIX permission bits are not honored.
78
+              '';
79
+            };
80
+
71 81
             configFile = mkOption {
72 82
               type = types.path;
73 83
               description = ''

+ 11
- 0
nixos-modules/systemd-runner.dhall View File

@@ -20,6 +20,7 @@ in  λ ( params
20 20
         , binary : Text
21 21
         , coreutils : Text
22 22
         , extraVfs : List XML.Type
23
+        , fsPersistence : Bool
23 24
         , interface : Optional Text
24 25
         , ramQuotaMiB : Natural
25 26
         }
@@ -90,10 +91,20 @@ in  λ ( params
90 91
                                               [ VFS.fs
91 92
                                                   VFS.FS::{
92 93
                                                   , label = "nix-store"
94
+                                                  , writeable = "no"
93 95
                                                   }
94 96
                                               ]
95 97
                                           ]
96 98
                                       ]
99
+                                    # ( if    params.fsPersistence
100
+                                        then  [ VFS.fs
101
+                                                  VFS.FS::{
102
+                                                  , label = "peristence"
103
+                                                  , writeable = "yes"
104
+                                                  }
105
+                                              ]
106
+                                        else  [ VFS.leaf "ram" ]
107
+                                      )
97 108
                                     # params.extraVfs
98 109
                                   )
99 110
                               ]

+ 16
- 2
nixos-modules/systemd.nix View File

@@ -5,7 +5,8 @@ with lib; {
5 5
     type = types.attrsOf (types.submodule ({ name, config, ... }: {
6 6
       options.genode = {
7 7
 
8
-        enable = lib.mkEnableOption "systemd unit to a Genode subsystem translation";
8
+        enable =
9
+          lib.mkEnableOption "systemd unit to a Genode subsystem translation";
9 10
 
10 11
         interface = lib.mkOption {
11 12
           type = with types; nullOr str;
@@ -32,6 +33,16 @@ with lib; {
32 33
           description = "RAM quota in MiB";
33 34
         };
34 35
 
36
+        fsPersistence = lib.mkOption {
37
+          type = types.bool;
38
+          default = false;
39
+          description = ''
40
+            Whether this service will have access to mutable and persistent storage.
41
+            This space is shared among all services for which this option is available
42
+            and UNIX permission bits are not honored.
43
+          '';
44
+        };
45
+
35 46
       };
36 47
     }));
37 48
   };
@@ -56,6 +67,7 @@ with lib; {
56 67
               vfs
57 68
               vfs_pipe
58 69
             ];
70
+          inherit (service.genode) fsPersistence;
59 71
           configFile = let
60 72
             args = lib.strings.splitString " "
61 73
               (toString service.serviceConfig.ExecStart);
@@ -66,6 +78,7 @@ with lib; {
66 78
               "None Text"
67 79
             else
68 80
               ''Some "${service.genode.interface}"'';
81
+            toBool = cond: if cond then "True" else "False";
69 82
           in pkgs.writeText "${name'}.dhall" ''
70 83
             ${./systemd-runner.dhall} {
71 84
             , args = ${args'}
@@ -73,10 +86,11 @@ with lib; {
73 86
             , coreutils = "${pkgs.coreutils}"
74 87
             , extraVfs = ${
75 88
               if service.genode.extraVfs == null then
76
-                "[] : List (env:DHALL_PRELUDE).XML.Type"
89
+                "[] : List (env:DHALL_GENODE).Prelude.XML.Type"
77 90
               else
78 91
                 service.genode.extraVfs
79 92
             }
93
+            , fsPersistence = ${toBool service.genode.fsPersistence}
80 94
             , interface = ${interface}
81 95
             , ramQuotaMiB = ${toString service.genode.ramQuota}
82 96
             }

Loading…
Cancel
Save