From 74ea4d0c1278f2ebc253ff48297159de0c770a2e Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 13 Jan 2021 12:33:52 +0100 Subject: [PATCH] nixos: add file-systems options --- nixos-modules/default.nix | 1 + nixos-modules/file-systems.nix | 29 +++++++++++++++++++++++++++++ nixos-modules/genode-core.nix | 25 ++++++++++++++----------- nixos-modules/hardware/ahci.nix | 6 +++--- tests/ahci.nix | 6 +++++- tests/lib/build-vms.nix | 1 + 6 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 nixos-modules/file-systems.nix diff --git a/nixos-modules/default.nix b/nixos-modules/default.nix index 54274ba..f6062a5 100644 --- a/nixos-modules/default.nix +++ b/nixos-modules/default.nix @@ -4,6 +4,7 @@ x86_64 = { imports = [ + ./file-systems.nix ./genode-core.nix ./genode-init.nix ./gui diff --git a/nixos-modules/file-systems.nix b/nixos-modules/file-systems.nix new file mode 100644 index 0000000..9706c83 --- /dev/null +++ b/nixos-modules/file-systems.nix @@ -0,0 +1,29 @@ +{ config, lib, pkgs, ... }: +with lib; { + + options.fileSystems = lib.mkOption { + type = types.attrsOf (types.submodule ({ name, config, ... }: { + options.block = { + + device = lib.mkOption { type = types.int; }; + + driver = lib.mkOption { type = types.enum [ "ahci" ]; }; + + partition = lib.mkOption { type = types.ints.positive; }; + + }; + })); + }; + + config = { + + assertions = [{ + assertion = config.fileSystems."/".fsType == "ext2"; + message = "The only supported fsType is EXT2"; + }]; + + hardware.genode.ahci.enable = + any (fs: fs.block.driver == "ahci") (attrValues config.fileSystems); + }; + +} diff --git a/nixos-modules/genode-core.nix b/nixos-modules/genode-core.nix index faf154f..ea08fa9 100644 --- a/nixos-modules/genode-core.nix +++ b/nixos-modules/genode-core.nix @@ -220,7 +220,9 @@ in { , service = "Block" , label = Init.LabelSelector.prefix "store_fs" , attributes = toMap - { partition = "1" + { partition = "${ + toString config.fileSystems."/".block.partition + }" , writeable = "yes" , TODO = "select by partition UUID" } @@ -233,17 +235,18 @@ in { { }) // { store_fs.configFile = let - storeVfsConfig = let - rumpExt2 = '' - VFS.vfs [ VFS.leafAttrs "rump" (toMap { fs = "ext2fs", ram="12M" }) ] - ''; - in { - ahci = rumpExt2; - tarball = '' + storeVfsConfig = + if config.genode.boot.storeBackend == "tarball" then '' VFS.vfs [ VFS.leafAttrs "tar" (toMap { name = "${config.system.build.tarball.fileName}.tar" }) ] - ''; - usb = rumpExt2; - }.${config.genode.boot.storeBackend}; + '' else + let + rumpExt2 = '' + VFS.vfs [ VFS.leafAttrs "rump" (toMap { fs = "ext2fs", ram="12M" }) ] + ''; + in { + ahci = rumpExt2; + usb = rumpExt2; + }.${config.fileSystems."/".block.driver}; storeResources = let rumpExt2 = diff --git a/nixos-modules/hardware/ahci.nix b/nixos-modules/hardware/ahci.nix index 1db6177..d34aee4 100644 --- a/nixos-modules/hardware/ahci.nix +++ b/nixos-modules/hardware/ahci.nix @@ -10,8 +10,6 @@ with lib; config = let cfg = config.hardware.genode.ahci; in { - hardware.genode.ahci.enable = config.genode.boot.storeBackend == "ahci"; - hardware.genode.platform.policies = lib.optional cfg.enable (builtins.toFile ("ahci.platform-policy.dhall") '' let Genode = env:DHALL_GENODE @@ -52,7 +50,9 @@ with lib; [ Init.Config.Policy::{ , service = "Block" , label = Init.LabelSelector.prefix "part_block" - , attributes = toMap { device = "0", writeable = "yes" } + , attributes = toMap { device = "${ + toString config.fileSystems."/".block.device + }", writeable = "yes" } } ] } diff --git a/tests/ahci.nix b/tests/ahci.nix index eb3e83f..2103025 100644 --- a/tests/ahci.nix +++ b/tests/ahci.nix @@ -1,7 +1,11 @@ { name = "ahci"; machine = { pkgs, ... }: { - genode.boot.storeBackend = "ahci"; + fileSystems."/".block = { + driver = "ahci"; + device = 0; + partition = 1; + }; genode.init.children.hello = { inputs = [ pkgs.hello pkgs.genodePackages.vfs.lib ]; configFile = pkgs.writeText "ahci-hello.child.dhall" '' diff --git a/tests/lib/build-vms.nix b/tests/lib/build-vms.nix index 51f5db2..5899ee9 100644 --- a/tests/lib/build-vms.nix +++ b/tests/lib/build-vms.nix @@ -27,6 +27,7 @@ rec { inherit system; modules = configurations ++ extraConfigurations; baseModules = (import "${modulesPath}/module-list.nix") ++ [ + ../../nixos-modules/file-systems.nix ../../nixos-modules/genode-core.nix ../../nixos-modules/genode-init.nix ../../nixos-modules/gui