[run-vm] mv to /scripts
All checks were successful
Check flake syntax / flake-check (push) Successful in 4m11s
All checks were successful
Check flake syntax / flake-check (push) Successful in 4m11s
This commit was merged in pull request #73.
This commit is contained in:
59
outputs.nix
59
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 <hostname> [--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 = {
|
||||
|
||||
56
scripts/run-vm.sh
Normal file
56
scripts/run-vm.sh
Normal file
@@ -0,0 +1,56 @@
|
||||
usage() {
|
||||
echo "Usage: run-vm <hostname> [--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"
|
||||
Reference in New Issue
Block a user