nix-config/modules/cluster/deployment.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.5 KiB
Nix
Raw Normal View History

2022-11-06 13:27:53 +01:00
{ 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;
};
}