[run-vm] add flag to disable disko

needed to run fanny as vm
This commit is contained in:
2025-01-20 03:06:58 +01:00
parent eea5d6924d
commit c47e93170f

View File

@@ -34,7 +34,6 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
}]); }]);
}; };
boot.initrd.network.ssh.enable = pkgs.lib.mkForce false;
boot.isContainer = pkgs.lib.mkForce false; boot.isContainer = pkgs.lib.mkForce false;
users.users.root.password = ""; users.users.root.password = "";
fileSystems."/".fsType = pkgs.lib.mkForce "tmpfs"; fileSystems."/".fsType = pkgs.lib.mkForce "tmpfs";
@@ -44,6 +43,16 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
''; '';
}; };
vmDiskoOverwrites = {
boot.initrd = {
secrets = pkgs.lib.mkForce {};
network.ssh.enable = pkgs.lib.mkForce false;
};
malobeo.disks.enable = pkgs.lib.mkForce false;
networking.hostId = "a3c3101f";
};
vmSopsOverwrites = host: { vmSopsOverwrites = host: {
sops.defaultSopsFile = pkgs.lib.mkForce ./machines/${host}/dummy.yaml; sops.defaultSopsFile = pkgs.lib.mkForce ./machines/${host}/dummy.yaml;
@@ -60,10 +69,11 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
}]; }];
}; };
buildVM = host: networking: sopsDummy: (self.nixosConfigurations.${host}.extendModules { buildVM = host: networking: sopsDummy: disableDisko: (self.nixosConfigurations.${host}.extendModules {
modules = [ modules = [
(vmMicroVMOverwrites { withNetworking = networking; }) (vmMicroVMOverwrites { withNetworking = networking; })
(if sopsDummy then (vmSopsOverwrites host) else {}) (if sopsDummy then (vmSopsOverwrites host) else {})
(if disableDisko then vmDiskoOverwrites else {})
] ++ pkgs.lib.optionals (! self.nixosConfigurations.${host}.config ? microvm) [ ] ++ pkgs.lib.optionals (! self.nixosConfigurations.${host}.config ? microvm) [
microvm.nixosModules.microvm microvm.nixosModules.microvm
]; ];
@@ -125,10 +135,11 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
run-vm = pkgs.writeShellScriptBin "run-vm" '' run-vm = pkgs.writeShellScriptBin "run-vm" ''
usage() { usage() {
echo "Usage: run-vm <hostname> [--networking] [--dummy-secrets]" echo "Usage: run-vm <hostname> [--networking] [--dummy-secrets] [--no-disko]"
echo "ATTENTION: This script must be run from the flakes root directory" 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 "--networking setup interfaces. requires root and hostbridge enabled on the host"
echo "--dummy-secrets deploy dummy sops secrets" echo "--dummy-secrets deploy dummy sops secrets"
echo "--no-disko disable disko and initrd secrets. needed for actual hosts like fanny"
exit 1 exit 1
} }
@@ -142,6 +153,7 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
# Optionale Argumente # Optionale Argumente
NETWORK=false NETWORK=false
DUMMY_SECRETS=false DUMMY_SECRETS=false
NO_DISKO=false
# check argws # check argws
shift shift
@@ -149,6 +161,7 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
case $1 in case $1 in
--networking) NETWORK=true ;; --networking) NETWORK=true ;;
--dummy-secrets) DUMMY_SECRETS=true ;; --dummy-secrets) DUMMY_SECRETS=true ;;
--no-disko) NO_DISKO=true ;;
*) echo "Unknown argument: $1"; usage ;; *) echo "Unknown argument: $1"; usage ;;
esac esac
shift shift
@@ -156,8 +169,9 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
echo "starting host $HOSTNAME" echo "starting host $HOSTNAME"
echo "enable networking: $NETWORK" echo "enable networking: $NETWORK"
echo "deploy dummy secrets: $DUMMY_SECRETS" echo "deploy dummy secrets: $DUMMY_SECRETS"
echo "disable disko and initrd secrets: $NO_DISKO"
${pkgs.nix}/bin/nix run --impure --expr "((builtins.getFlake \"$(pwd)\").vmBuilder.x86_64-linux \"$HOSTNAME\" $NETWORK $DUMMY_SECRETS)" ${pkgs.nix}/bin/nix run --impure --expr "((builtins.getFlake \"$(pwd)\").vmBuilder.x86_64-linux \"$HOSTNAME\" $NETWORK $DUMMY_SECRETS $NO_DISKO)"
''; '';
}; };