modules/cluster/deployment: init

This commit is contained in:
Astro 2022-11-06 13:27:53 +01:00
parent c29d474192
commit cfeb74ee54
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
{ config, lib, ... }:
let
inherit (config.networking) hostName;
inherit (config.system.build.skyflake-deployment) user repo vmName;
generateMacAddress = net:
let
hash = builtins.hashString "md5" "1-${net}-${hostName}";
c = off: builtins.substring off 2 hash;
in
"${builtins.substring 0 1 hash}2:${c 2}:${c 4}:${c 6}:${c 8}:${c 10}";
withoutLeadingSlash = s:
let s' = lib.removePrefix "/" s; in
if s' == s
then s
else withoutLeadingSlash s';
in
{
config.microvm = {
hypervisor = "cloud-hypervisor";
vcpu = config.deployment.vcpu;
mem = config.deployment.mem;
shares = [ {
proto = "virtiofs";
tag = "ro-store";
source = "/nix/store";
mountPoint = "/nix/.ro-store";
} ] ++ map (mountPoint: {
proto = "virtiofs";
tag = builtins.replaceStrings [ "/" ] [ "-" ] (
withoutLeadingSlash mountPoint
);
source = "/storage/glusterfs/microvms/${user}/${repo}/${vmName}/${withoutLeadingSlash mountPoint}";
inherit mountPoint;
}) config.deployment.persistedShares;
# volumes = [ {
# image = "/storage/glusterfs/microvms/${user}/${repo}/${vmName}/overlay.img";
# mountPoint = "/";
# size = 8 * 1024;
# } ];
# writableStoreOverlay = "/nix/.rw-store";
interfaces = map (net: {
type = "tap";
id = builtins.substring 0 15 "${net}-${hostName}";
mac = generateMacAddress net;
}) config.deployment.networks;
};
}