diff --git a/outputs.nix b/outputs.nix index a846a48..c8dac17 100644 --- a/outputs.nix +++ b/outputs.nix @@ -72,64 +72,7 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems ''; }; - run-vm = pkgs.writeShellScriptBin "run-vm" '' - usage() { - echo "Usage: run-vm [--networking] [--dummy-secrets] [--no-disko]" - echo "ATTENTION: This script must be run from the flakes root directory" - echo "--networking setup interfaces. requires root and hostbridge enabled on the host" - echo "--dummy-secrets run vm with dummy sops secrets" - 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" - exit 1 - } - - # check at least one arg was given - if [ "$#" -lt 1 ]; then - usage - fi - - HOSTNAME=$1 - - # Optionale Argumente - NETWORK=false - DUMMY_SECRETS=false - NO_DISKO=false - RW_STORE=false - VAR_PATH="" - - # check argws - shift - while [[ "$#" -gt 0 ]]; do - case $1 in - --networking) NETWORK=true ;; - --dummy-secrets) DUMMY_SECRETS=true ;; - --no-disko) NO_DISKO=true ;; - --writable-store) RW_STORE=true ;; - --var) - if [[ -n "$2" && ! "$2" =~ ^- ]]; then - VAR_PATH="$2" - shift - else - echo "Error: --var requires a non-empty string argument." - usage - fi - ;; - *) echo "Unknown argument: $1"; usage ;; - esac - shift - done - echo "starting host $HOSTNAME" - echo "enable networking: $NETWORK" - echo "deploy dummy secrets: $DUMMY_SECRETS" - echo "disable disko and initrd secrets: $NO_DISKO" - echo "use writable store: $RW_STORE" - if [ -n "$VAR_PATH" ]; then - echo "sharing var directory: $VAR_PATH" - fi - - ${pkgs.nix}/bin/nix run --show-trace --impure --expr "((builtins.getFlake \"$(pwd)\").vmBuilder.x86_64-linux \"$HOSTNAME\" $NETWORK $DUMMY_SECRETS $NO_DISKO \"$VAR_PATH\" $RW_STORE).config.microvm.declaredRunner" - ''; + run-vm = pkgs.writeShellScriptBin "run-vm" (builtins.readFile ./scripts/run-vm.sh); }; apps = { diff --git a/scripts/run-vm.sh b/scripts/run-vm.sh new file mode 100644 index 0000000..c9eee2a --- /dev/null +++ b/scripts/run-vm.sh @@ -0,0 +1,56 @@ +usage() { + echo "Usage: run-vm [--networking] [--dummy-secrets] [--no-disko]" + echo "ATTENTION: This script must be run from the flakes root directory" + echo "--networking setup interfaces. requires root and hostbridge enabled on the host" + echo "--dummy-secrets run vm with dummy sops secrets" + 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" + exit 1 +} + +# check at least one arg was given +if [ "$#" -lt 1 ]; then + usage +fi + +HOSTNAME=$1 + +# Optionale Argumente +NETWORK=false +DUMMY_SECRETS=false +NO_DISKO=false +RW_STORE=false +VAR_PATH="" + +# check argws +shift +while [[ "$#" -gt 0 ]]; do + case $1 in + --networking) NETWORK=true ;; + --dummy-secrets) DUMMY_SECRETS=true ;; + --no-disko) NO_DISKO=true ;; + --writable-store) RW_STORE=true ;; + --var) + if [[ -n "$2" && ! "$2" =~ ^- ]]; then + VAR_PATH="$2" + shift + else + echo "Error: --var requires a non-empty string argument." + usage + fi + ;; + *) echo "Unknown argument: $1"; usage ;; + esac + shift +done +echo "starting host $HOSTNAME" +echo "enable networking: $NETWORK" +echo "deploy dummy secrets: $DUMMY_SECRETS" +echo "disable disko and initrd secrets: $NO_DISKO" +echo "use writable store: $RW_STORE" +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).config.microvm.declaredRunner"