-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
default-customization.nix
82 lines (72 loc) · 1.95 KB
/
default-customization.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{ config, lib, ... }:
let
generateMacAddress = s:
let
hash = builtins.hashString "sha256" s;
c = off: builtins.substring off 2 hash;
in
"${builtins.substring 0 1 hash}2:${c 2}:${c 4}:${c 6}:${c 8}:${c 10}";
inherit (config.system.build.skyflake-deployment) user repo vmName;
in
{
# custom options
options.deployment = with lib; {
vcpu = mkOption {
type = types.int;
default = 2;
};
mem = mkOption {
type = types.int;
default = 256;
};
};
# some sensible defaults
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";
} ];
volumes = [ {
image = config.skyflake.deploy.rbds.root.path;
mountPoint = "/";
# don't let microvm.nix create an image file
autoCreate = false;
size = 0;
} ];
writableStoreOverlay = "/nix/.rw-store";
interfaces = [ {
type = "tap";
# Linux interface names cannot be longer than 15 bytes.
# Note that this scheme can lead to clashes between
# identical vmNames in separate user/repo.
id = builtins.substring 0 15 "${user}-${vmName}";
mac = generateMacAddress "${user}-${repo}-${vmName}";
} ];
};
config.skyflake.deploy.rbds.root = {
pool = "microvms";
namespace = user;
name = "${repo}-${vmName}-root";
size = 512;
};
# Simply attach to main bridge
config.skyflake.deploy.startTapScript = ''
ip link set dev "$IFACE" master br0
'';
# Constraint example
config.skyflake.nomadJob.constraints = [ {
attribute = "\${meta.example-deployment}";
operator = "=";
value = "yes";
} ];
config.skyflake.nomadJob.affinities = [ {
attribute = "\${meta.example-deployment}";
value = "yes";
} ];
config.fileSystems."/".fsType = lib.mkForce "ext4";
}