[run-vim] allow setting data share
All checks were successful
Check flake syntax / flake-check (push) Successful in 4m27s

This commit is contained in:
2025-04-13 15:24:06 +02:00
parent 00f4b7c2b1
commit da12a73334
2 changed files with 26 additions and 2 deletions

View File

@@ -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 {})

View File

@@ -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"