From da12a733349087baae8b12dddeff5c012c95ee94 Mon Sep 17 00:00:00 2001 From: kalipso Date: Sun, 13 Apr 2025 15:24:06 +0200 Subject: [PATCH] [run-vim] allow setting data share --- machines/modules/host_builder.nix | 11 ++++++++++- scripts/run-vm.sh | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/machines/modules/host_builder.nix b/machines/modules/host_builder.nix index 0fe75743..14fac786 100644 --- a/machines/modules/host_builder.nix +++ b/machines/modules/host_builder.nix @@ -133,6 +133,13 @@ rec { mountPoint = "/var"; tag = "var"; } + ] ++ pkgs.lib.optionals (options.dataPath != "") [ + { + source = "${options.dataPath}"; + securityModel = "mapped"; + mountPoint = "/data"; + tag = "data"; + } ]); interfaces = pkgs.lib.mkIf (!options.withNetworking) (pkgs.lib.mkForce [{ @@ -209,6 +216,7 @@ rec { (vmMicroVMOverwrites name { withNetworking = true; varPath = ""; + dataPath = ""; writableStore = false; }) (if sopsDummy then (vmSopsOverwrites name) else {}) ]); @@ -218,11 +226,12 @@ rec { builtins.listToAttrs (map mapperFunc self.nixosConfigurations.${host}.config.services.malobeo.microvm.deployHosts)); }; - buildVM = host: networking: sopsDummy: disableDisko: varPath: writableStore: fwdPort: (self.nixosConfigurations.${host}.extendModules { + buildVM = host: networking: sopsDummy: disableDisko: varPath: dataPath: writableStore: fwdPort: (self.nixosConfigurations.${host}.extendModules { modules = [ (vmMicroVMOverwrites host { withNetworking = networking; varPath = "${varPath}"; + dataPath = "${dataPath}"; writableStore = writableStore; fwdPort = fwdPort; }) (if sopsDummy then (vmSopsOverwrites host) else {}) diff --git a/scripts/run-vm.sh b/scripts/run-vm.sh index 3968cdd8..8daa98c9 100644 --- a/scripts/run-vm.sh +++ b/scripts/run-vm.sh @@ -6,6 +6,7 @@ usage() { echo "--no-disko disable disko and initrd secrets. needed for real hosts like fanny" echo "--writable-store enables writable store. necessary for host with nested imperative microvms like fanny" echo "--var path to directory that should be shared as /var. may require root otherwise some systemd units fail within vm. if dir is empty vm will populate" + echo "--data path to directory that should be shared as /data" echo "--fwd-port forwards the given port to port 80 on vm" exit 1 } @@ -23,6 +24,7 @@ DUMMY_SECRETS=false NO_DISKO=false RW_STORE=false VAR_PATH="" +DATA_PATH="" FWD_PORT=0 # check argws @@ -42,6 +44,15 @@ while [[ "$#" -gt 0 ]]; do usage fi ;; + --data) + if [[ -n "$2" && ! "$2" =~ ^- ]]; then + DATA_PATH="$2" + shift + else + echo "Error: --data requires a non-empty string argument." + usage + fi + ;; --fwd-port) if [[ -n "$2" && ! "$2" =~ ^- ]]; then FWD_PORT="$2" @@ -64,4 +75,8 @@ if [ -n "$VAR_PATH" ]; then echo "sharing var directory: $VAR_PATH" fi -nix run --show-trace --impure --expr "((builtins.getFlake \"$(pwd)\").vmBuilder.x86_64-linux \"$HOSTNAME\" $NETWORK $DUMMY_SECRETS $NO_DISKO \"$VAR_PATH\" $RW_STORE $FWD_PORT).config.microvm.declaredRunner" +if [ -n "$DATA_PATH" ]; then + echo "sharing data directory: $DATA_PATH" +fi + +nix run --show-trace --impure --expr "((builtins.getFlake \"$(pwd)\").vmBuilder.x86_64-linux \"$HOSTNAME\" $NETWORK $DUMMY_SECRETS $NO_DISKO \"$VAR_PATH\" \"$DATA_PATH\" $RW_STORE $FWD_PORT).config.microvm.declaredRunner"