2024-10-07 15:00:14 -06:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.myModules.railbird-k3s;
|
|
|
|
mount-path = "/var/lib/railbird/bucket";
|
|
|
|
bucket-name = "railbird-dev-videos";
|
2024-09-30 16:35:50 -06:00
|
|
|
in {
|
|
|
|
options = {
|
2024-09-30 16:42:58 -06:00
|
|
|
myModules.railbird-k3s = {
|
|
|
|
enable = mkEnableOption "railbird k3s";
|
|
|
|
serverAddr = mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "";
|
|
|
|
};
|
2024-09-30 16:35:50 -06:00
|
|
|
};
|
|
|
|
};
|
2024-09-30 16:42:58 -06:00
|
|
|
config = mkIf cfg.enable {
|
2024-09-30 16:35:50 -06:00
|
|
|
age.secrets."1896Folsom-k3s-token.age".file = ./secrets/1896Folsom-k3s-token.age;
|
2024-10-01 16:04:55 -06:00
|
|
|
age.secrets."k3s-registry.yaml.age".file = ./secrets/k3s-registry.yaml.age;
|
2024-10-07 15:00:14 -06:00
|
|
|
age.secrets.api-service-key = {
|
|
|
|
file = ./secrets/api_service_account_key.json.age;
|
|
|
|
owner = "railbird";
|
|
|
|
group = "users";
|
|
|
|
};
|
2024-10-02 14:32:21 -06:00
|
|
|
environment.etc."rancher/k3s/registries.yaml".source = config.age.secrets."k3s-registry.yaml.age".path;
|
2024-09-30 16:35:50 -06:00
|
|
|
services.dockerRegistry = {
|
|
|
|
enable = true;
|
|
|
|
listenAddress = "0.0.0.0";
|
|
|
|
port = 5279;
|
|
|
|
enableDelete = true;
|
|
|
|
enableGarbageCollect = true;
|
|
|
|
};
|
2024-10-07 15:00:14 -06:00
|
|
|
systemd.services.mount-railbird-bucket = {
|
|
|
|
after = ["agenix.service"];
|
|
|
|
description = "Mount railbird bucket";
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
ExecStartPre = [
|
2024-10-07 15:16:16 -06:00
|
|
|
"-${pkgs.util-linux}/bin/umount -f ${mount-path}"
|
|
|
|
"${pkgs.coreutils}/bin/mkdir -p ${mount-path}"
|
|
|
|
"${pkgs.coreutils}/bin/chown railbird:users ${mount-path}"
|
|
|
|
"${pkgs.coreutils}/bin/chmod 0775 ${mount-path}"
|
2024-10-07 15:00:14 -06:00
|
|
|
];
|
2024-10-07 15:16:16 -06:00
|
|
|
ExecStart = "${pkgs.gcsfuse}/bin/gcsfuse --implicit-dirs --key-file ${config.age.secrets.api-service-key.path} ${bucket-name} ${mount-path}";
|
|
|
|
User = "root";
|
2024-10-07 15:00:14 -06:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-09-30 16:35:50 -06:00
|
|
|
services.k3s = {
|
|
|
|
enable = true;
|
|
|
|
clusterInit = cfg.serverAddr == "";
|
|
|
|
serverAddr = cfg.serverAddr;
|
2024-10-02 18:54:27 -06:00
|
|
|
configPath = pkgs.writeTextFile {
|
|
|
|
name = "k3s-config.yaml";
|
|
|
|
text = ''
|
|
|
|
kubelet-arg:
|
|
|
|
- "eviction-hard=nodefs.available<2Gi"
|
|
|
|
- "eviction-soft=nodefs.available<5Gi"
|
|
|
|
- "eviction-soft-grace-period=nodefs.available=5m"
|
|
|
|
'';
|
|
|
|
};
|
2024-09-30 16:35:50 -06:00
|
|
|
tokenFile = config.age.secrets."1896Folsom-k3s-token.age".path;
|
2024-09-30 17:15:13 -06:00
|
|
|
extraFlags = [
|
2024-09-30 17:23:42 -06:00
|
|
|
"--tls-san ryzen-shine.local"
|
|
|
|
"--tls-san nixquick.local"
|
|
|
|
"--tls-san biskcomp.local"
|
|
|
|
"--tls-san jimi-hendnix.local"
|
2024-09-30 18:26:14 -06:00
|
|
|
"--tls-san dev.railbird.ai"
|
2024-10-02 16:24:02 -06:00
|
|
|
"--node-label nixos-nvidia-cdi=enabled"
|
2024-09-30 17:15:13 -06:00
|
|
|
];
|
2024-09-30 16:35:50 -06:00
|
|
|
containerdConfigTemplate = ''
|
|
|
|
{{ template "base" . }}
|
2024-09-30 00:05:50 -06:00
|
|
|
|
2024-10-02 18:54:27 -06:00
|
|
|
[plugins]
|
|
|
|
"io.containerd.grpc.v1.cri".enable_cdi = true
|
|
|
|
|
2024-09-30 16:35:50 -06:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.nvidia]
|
|
|
|
privileged_without_host_devices = false
|
|
|
|
runtime_engine = ""
|
|
|
|
runtime_root = ""
|
|
|
|
runtime_type = "io.containerd.runc.v2"
|
2024-09-30 00:05:50 -06:00
|
|
|
|
2024-09-30 16:35:50 -06:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.nvidia.options]
|
|
|
|
BinaryName = "/run/current-system/sw/bin/nvidia-container-runtime"
|
|
|
|
'';
|
|
|
|
gracefulNodeShutdown = {
|
|
|
|
enable = true;
|
|
|
|
};
|
2024-09-30 00:05:50 -06:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|