-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvolume-mount-empty-dir.nix
72 lines (71 loc) · 2.28 KB
/
volume-mount-empty-dir.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
topLevel@{ inputs, flake-parts-lib, ... }: {
imports = [
./devcontainer.nix
./kubernetes.nix
inputs.flake-parts.flakeModules.flakeModules
];
flake.flakeModules.volumeMountEmptyDir = {
imports = [
topLevel.config.flake.flakeModules.devcontainer
topLevel.config.flake.flakeModules.kubernetes
];
options.perSystem = flake-parts-lib.mkPerSystemOption (perSystem@{ lib, config, pkgs, ... }: {
ml-ops.common = {
options.volumeMounts.emptyDir = lib.mkOption {
default = { };
type = lib.types.attrsOf (lib.types.submoduleWith {
modules = [{
options.medium = lib.mkOption {
type = lib.types.nullOr (lib.types.enum [ "Memory" ]);
default = null;
};
}];
});
};
};
ml-ops.runtime = {
options.volumeMounts.emptyDir = lib.mkOption {
type = lib.types.attrsOf (lib.types.submoduleWith {
modules = [
({ config, ... }: {
options.kubernetesVolume = lib.mkOption {
default = {
emptyDir = {
medium = config.medium;
};
};
};
})
];
});
};
};
ml-ops.devcontainer = {
options.volumeMounts.emptyDir = lib.mkOption {
type = lib.types.attrsOf (lib.types.submoduleWith {
modules = [
({ config, ... }: {
options.mountScript = lib.mkOption {
type = lib.types.lines;
default =
if config.medium == null then
lib.strings.escapeShellArgs [
"mkdir"
"-p"
config._module.args.name
]
else if config.medium == "Memory" then
''
ln -s -f -T "$(mktemp -d -p /dev/shm)" \
${lib.strings.escapeShellArg config._module.args.name}
''
else builtins.throw "Unsupported medium: ${config.medium}";
};
})
];
});
};
};
});
};
}