fix host_builder.nix tabs
This commit is contained in:
@@ -105,135 +105,135 @@ rec {
|
|||||||
inputsMod = inputs // { malobeo = self; };
|
inputsMod = inputs // { malobeo = self; };
|
||||||
|
|
||||||
|
|
||||||
vmMicroVMOverwrites = hostname: options: {
|
vmMicroVMOverwrites = hostname: options: {
|
||||||
microvm = rec {
|
microvm = rec {
|
||||||
mem = pkgs.lib.mkForce 4096;
|
mem = pkgs.lib.mkForce 4096;
|
||||||
hypervisor = pkgs.lib.mkForce "qemu";
|
hypervisor = pkgs.lib.mkForce "qemu";
|
||||||
socket = pkgs.lib.mkForce null;
|
socket = pkgs.lib.mkForce null;
|
||||||
|
|
||||||
|
|
||||||
#needed for hosts that deploy imperative microvms (for example fanny)
|
#needed for hosts that deploy imperative microvms (for example fanny)
|
||||||
writableStoreOverlay = pkgs.lib.mkIf options.writableStore "/nix/.rw-store";
|
writableStoreOverlay = pkgs.lib.mkIf options.writableStore "/nix/.rw-store";
|
||||||
volumes = pkgs.lib.mkIf options.writableStore [ {
|
volumes = pkgs.lib.mkIf options.writableStore [ {
|
||||||
image = "nix-store-overlay.img";
|
image = "nix-store-overlay.img";
|
||||||
mountPoint = writableStoreOverlay;
|
mountPoint = writableStoreOverlay;
|
||||||
size = 2048;
|
size = 2048;
|
||||||
} ];
|
} ];
|
||||||
|
|
||||||
shares = pkgs.lib.mkForce (pkgs.lib.optionals (!options.writableStore) [
|
shares = pkgs.lib.mkForce (pkgs.lib.optionals (!options.writableStore) [
|
||||||
{
|
{
|
||||||
tag = "ro-store";
|
tag = "ro-store";
|
||||||
source = "/nix/store";
|
source = "/nix/store";
|
||||||
mountPoint = "/nix/.ro-store";
|
mountPoint = "/nix/.ro-store";
|
||||||
}
|
}
|
||||||
] ++ pkgs.lib.optionals (options.varPath != "") [
|
] ++ pkgs.lib.optionals (options.varPath != "") [
|
||||||
{
|
{
|
||||||
source = "${options.varPath}";
|
source = "${options.varPath}";
|
||||||
securityModel = "mapped";
|
securityModel = "mapped";
|
||||||
mountPoint = "/var";
|
mountPoint = "/var";
|
||||||
tag = "var";
|
tag = "var";
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
interfaces = pkgs.lib.mkIf (!options.withNetworking) (pkgs.lib.mkForce [{
|
interfaces = pkgs.lib.mkIf (!options.withNetworking) (pkgs.lib.mkForce [{
|
||||||
type = "user";
|
type = "user";
|
||||||
id = "eth0";
|
id = "eth0";
|
||||||
mac = "02:23:de:ad:be:ef";
|
mac = "02:23:de:ad:be:ef";
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
#if networking is disabled forward port 80 to still have access to webservices
|
#if networking is disabled forward port 80 to still have access to webservices
|
||||||
forwardPorts = pkgs.lib.mkIf (!options.withNetworking && options.fwdPort != 0) (pkgs.lib.mkForce [
|
forwardPorts = pkgs.lib.mkIf (!options.withNetworking && options.fwdPort != 0) (pkgs.lib.mkForce [
|
||||||
{ from = "host"; host.port = options.fwdPort; guest.port = 80; }
|
{ from = "host"; host.port = options.fwdPort; guest.port = 80; }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
fileSystems = {
|
|
||||||
"/".fsType = pkgs.lib.mkForce "tmpfs";
|
|
||||||
|
|
||||||
# prometheus uses a memory mapped file which doesnt seem supported by 9p shares
|
|
||||||
# therefore we mount a tmpfs inside the datadir
|
|
||||||
"/var/lib/prometheus2/data" = pkgs.lib.mkIf (hostname == "overwatch" && options.varPath != "") (pkgs.lib.mkForce {
|
|
||||||
fsType = pkgs.lib.mkForce "tmpfs";
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
boot.isContainer = pkgs.lib.mkForce false;
|
|
||||||
services.timesyncd.enable = false;
|
|
||||||
users.users.root.password = "";
|
|
||||||
services.getty.helpLine = ''
|
|
||||||
Log in as "root" with an empty password.
|
|
||||||
Use "reboot" to shut qemu down.
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
vmDiskoOverwrites = {
|
fileSystems = {
|
||||||
boot.initrd = {
|
"/".fsType = pkgs.lib.mkForce "tmpfs";
|
||||||
secrets = pkgs.lib.mkForce {};
|
|
||||||
network.ssh.enable = pkgs.lib.mkForce false;
|
|
||||||
};
|
|
||||||
|
|
||||||
malobeo.disks.enable = pkgs.lib.mkForce false;
|
# prometheus uses a memory mapped file which doesnt seem supported by 9p shares
|
||||||
networking.hostId = "a3c3101f";
|
# therefore we mount a tmpfs inside the datadir
|
||||||
};
|
"/var/lib/prometheus2/data" = pkgs.lib.mkIf (hostname == "overwatch" && options.varPath != "") (pkgs.lib.mkForce {
|
||||||
|
fsType = pkgs.lib.mkForce "tmpfs";
|
||||||
vmSopsOverwrites = host: {
|
|
||||||
sops.defaultSopsFile = pkgs.lib.mkForce ../${host}/dummy.yaml;
|
|
||||||
|
|
||||||
environment.etc = {
|
|
||||||
devHostKey = {
|
|
||||||
source = ../secrets/devkey_ed25519;
|
|
||||||
mode = "0600";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
services.openssh.hostKeys = [{
|
|
||||||
path = "/etc/devHostKey";
|
|
||||||
type = "ed25519";
|
|
||||||
}];
|
|
||||||
};
|
|
||||||
|
|
||||||
vmNestedMicroVMOverwrites = host: sopsDummy: {
|
|
||||||
|
|
||||||
services.malobeo.microvm.deployHosts = pkgs.lib.mkForce [];
|
|
||||||
microvm.vms =
|
|
||||||
let
|
|
||||||
# Map the values to each hostname to then generate an Attrset using listToAttrs
|
|
||||||
mapperFunc = name: { inherit name; value = {
|
|
||||||
specialArgs.inputs = inputsMod;
|
|
||||||
specialArgs.self = self;
|
|
||||||
config = {
|
|
||||||
imports = (makeMicroVM "${name}"
|
|
||||||
"${hosts.malobeo.hosts.${name}.network.address}"
|
|
||||||
"${hosts.malobeo.hosts.${name}.network.mac}" [
|
|
||||||
../${name}/configuration.nix
|
|
||||||
(vmMicroVMOverwrites name {
|
|
||||||
withNetworking = true;
|
|
||||||
varPath = "";
|
|
||||||
writableStore = false; })
|
|
||||||
(if sopsDummy then (vmSopsOverwrites name) else {})
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
}; };
|
|
||||||
in
|
|
||||||
builtins.listToAttrs (map mapperFunc self.nixosConfigurations.${host}.config.services.malobeo.microvm.deployHosts);
|
|
||||||
};
|
|
||||||
|
|
||||||
buildVM = host: networking: sopsDummy: disableDisko: varPath: writableStore: fwdPort: (self.nixosConfigurations.${host}.extendModules {
|
|
||||||
modules = [
|
|
||||||
(vmMicroVMOverwrites host {
|
|
||||||
withNetworking = networking;
|
|
||||||
varPath = "${varPath}";
|
|
||||||
writableStore = writableStore;
|
|
||||||
fwdPort = fwdPort; })
|
|
||||||
(if sopsDummy then (vmSopsOverwrites host) else {})
|
|
||||||
(if disableDisko then vmDiskoOverwrites else {})
|
|
||||||
] ++ pkgs.lib.optionals (hosts.malobeo.hosts.${host}.type != "microvm") [
|
|
||||||
inputs.microvm.nixosModules.microvm
|
|
||||||
] ++ pkgs.lib.optionals (self.nixosConfigurations.${host}.config ? services.malobeo.microvm.deployHosts) [
|
|
||||||
(vmNestedMicroVMOverwrites host sopsDummy)
|
|
||||||
];
|
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
boot.isContainer = pkgs.lib.mkForce false;
|
||||||
|
services.timesyncd.enable = false;
|
||||||
|
users.users.root.password = "";
|
||||||
|
services.getty.helpLine = ''
|
||||||
|
Log in as "root" with an empty password.
|
||||||
|
Use "reboot" to shut qemu down.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
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: {
|
||||||
|
sops.defaultSopsFile = pkgs.lib.mkForce ../${host}/dummy.yaml;
|
||||||
|
|
||||||
|
environment.etc = {
|
||||||
|
devHostKey = {
|
||||||
|
source = ../secrets/devkey_ed25519;
|
||||||
|
mode = "0600";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
services.openssh.hostKeys = [{
|
||||||
|
path = "/etc/devHostKey";
|
||||||
|
type = "ed25519";
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
vmNestedMicroVMOverwrites = host: sopsDummy: {
|
||||||
|
|
||||||
|
services.malobeo.microvm.deployHosts = pkgs.lib.mkForce [];
|
||||||
|
microvm.vms =
|
||||||
|
let
|
||||||
|
# Map the values to each hostname to then generate an Attrset using listToAttrs
|
||||||
|
mapperFunc = name: { inherit name; value = {
|
||||||
|
specialArgs.inputs = inputsMod;
|
||||||
|
specialArgs.self = self;
|
||||||
|
config = {
|
||||||
|
imports = (makeMicroVM "${name}"
|
||||||
|
"${hosts.malobeo.hosts.${name}.network.address}"
|
||||||
|
"${hosts.malobeo.hosts.${name}.network.mac}" [
|
||||||
|
../${name}/configuration.nix
|
||||||
|
(vmMicroVMOverwrites name {
|
||||||
|
withNetworking = true;
|
||||||
|
varPath = "";
|
||||||
|
writableStore = false; })
|
||||||
|
(if sopsDummy then (vmSopsOverwrites name) else {})
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
}; };
|
||||||
|
in
|
||||||
|
builtins.listToAttrs (map mapperFunc self.nixosConfigurations.${host}.config.services.malobeo.microvm.deployHosts);
|
||||||
|
};
|
||||||
|
|
||||||
|
buildVM = host: networking: sopsDummy: disableDisko: varPath: writableStore: fwdPort: (self.nixosConfigurations.${host}.extendModules {
|
||||||
|
modules = [
|
||||||
|
(vmMicroVMOverwrites host {
|
||||||
|
withNetworking = networking;
|
||||||
|
varPath = "${varPath}";
|
||||||
|
writableStore = writableStore;
|
||||||
|
fwdPort = fwdPort; })
|
||||||
|
(if sopsDummy then (vmSopsOverwrites host) else {})
|
||||||
|
(if disableDisko then vmDiskoOverwrites else {})
|
||||||
|
] ++ pkgs.lib.optionals (hosts.malobeo.hosts.${host}.type != "microvm") [
|
||||||
|
inputs.microvm.nixosModules.microvm
|
||||||
|
] ++ pkgs.lib.optionals (self.nixosConfigurations.${host}.config ? services.malobeo.microvm.deployHosts) [
|
||||||
|
(vmNestedMicroVMOverwrites host sopsDummy)
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
buildHost = hosts: (builtins.mapAttrs (host: settings: nixosSystem {
|
buildHost = hosts: (builtins.mapAttrs (host: settings: nixosSystem {
|
||||||
system = if (settings.type == "rpi") then "aarch64-linux" else "x86_64-linux";
|
system = if (settings.type == "rpi") then "aarch64-linux" else "x86_64-linux";
|
||||||
|
|||||||
Reference in New Issue
Block a user