[nix] output vm packages for each host
this now runs any host as microvm. it removes shared directories for microvms so no manuall setup is needed (expect you want persistence). i took it from c3d2, thanks guys for the inspiration <3 https://gitea.c3d2.de/c3d2/nix-config/src/branch/master/packages.nix
This commit is contained in:
41
outputs.nix
41
outputs.nix
@@ -56,7 +56,46 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
|
|||||||
cp -r ./book/* $dest
|
cp -r ./book/* $dest
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
} //
|
||||||
|
|
||||||
|
builtins.foldl'
|
||||||
|
(result: host:
|
||||||
|
let
|
||||||
|
inherit (self.nixosConfigurations.${host}) config;
|
||||||
|
in
|
||||||
|
result // {
|
||||||
|
# boot any machine in a microvm
|
||||||
|
"${host}-vm" = (self.nixosConfigurations.${host}.extendModules {
|
||||||
|
modules = [{
|
||||||
|
microvm = {
|
||||||
|
mem = pkgs.lib.mkForce 4096;
|
||||||
|
hypervisor = pkgs.lib.mkForce "qemu";
|
||||||
|
socket = pkgs.lib.mkForce null;
|
||||||
|
shares = pkgs.lib.mkForce [{
|
||||||
|
tag = "ro-store";
|
||||||
|
source = "/nix/store";
|
||||||
|
mountPoint = "/nix/.ro-store";
|
||||||
|
}];
|
||||||
|
interfaces = pkgs.lib.mkForce [{
|
||||||
|
type = "user";
|
||||||
|
id = "eth0";
|
||||||
|
mac = "02:23:de:ad:be:ef";
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
boot.isContainer = pkgs.lib.mkForce false;
|
||||||
|
users.users.root.password = "";
|
||||||
|
fileSystems."/".fsType = pkgs.lib.mkForce "tmpfs";
|
||||||
|
services.getty.helpLine = ''
|
||||||
|
Log in as "root" with an empty password.
|
||||||
|
Use "reboot" to shut qemu down.
|
||||||
|
'';
|
||||||
|
}] ++ pkgs.lib.optionals (! config ? microvm) [
|
||||||
|
microvm.nixosModules.microvm
|
||||||
|
];
|
||||||
|
}).config.microvm.declaredRunner;
|
||||||
|
})
|
||||||
|
{ }
|
||||||
|
(builtins.attrNames self.nixosConfigurations);
|
||||||
|
|
||||||
apps = {
|
apps = {
|
||||||
docs = {
|
docs = {
|
||||||
|
|||||||
Reference in New Issue
Block a user