2024-06-29 15:53:57 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.services.tvix-binary-cache;
|
2024-07-08 17:35:59 +00:00
|
|
|
systemdHardening = {
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
UMask = "0077";
|
|
|
|
RuntimeDirectoryMode = "0750";
|
|
|
|
StateDirectoryMode = "0750";
|
|
|
|
};
|
2024-06-29 15:53:57 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.tvix-binary-cache = {
|
|
|
|
enable = lib.mkEnableOption "BinaryCache using tvix ca-store";
|
2024-07-08 17:35:59 +00:00
|
|
|
blob-service-addr = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "objectstore+file://%S/tvix-castore/blobs.object-store";
|
|
|
|
description = ''
|
|
|
|
`blob-service-addr` option for the castore (please read tvix source/docs to learn more).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
directory-service-addr = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "sled://%S/tvix-castore/directories.sled";
|
|
|
|
description = ''
|
|
|
|
`directory-service-addr` option for the castore (please read tvix source/docs to learn more).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
caches = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf (
|
|
|
|
lib.types.submodule (
|
|
|
|
{ name, ... }:
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
|
|
|
default = 9000;
|
|
|
|
};
|
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Name of the cache";
|
|
|
|
default = name;
|
|
|
|
defaultText = lib.literalMD "Defaults to attribute name in services.tvix-binary-cache.caches";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2024-06-29 15:53:57 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-08 17:35:59 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2024-06-29 15:53:57 +00:00
|
|
|
|
2024-07-08 17:35:59 +00:00
|
|
|
systemd.services = lib.mkMerge (
|
|
|
|
(lib.singleton {
|
|
|
|
tvix-castore = {
|
|
|
|
wants = [ "tvix-castore.service" ];
|
|
|
|
after = [ "tvix-castore.service" ];
|
2024-06-29 15:53:57 +00:00
|
|
|
environment = {
|
2024-07-08 17:35:59 +00:00
|
|
|
BLOB_SERVICE_ADDR = cfg.blob-service-addr;
|
|
|
|
DIRECTORY_SERVICE_ADDR = cfg.directory-service-addr;
|
|
|
|
PATH_INFO_SERVICE_ADDR = "sled://%S/tvix-castore/pathinfo.sled"; # Unused but probably needed
|
2024-06-29 15:53:57 +00:00
|
|
|
};
|
|
|
|
serviceConfig = {
|
2024-07-08 17:35:59 +00:00
|
|
|
ExecStart = "${pkgs.tvix-store}/bin/tvix-store --otlp=false daemon --listen-address=\"%t/tvix-castore/socket\"";
|
2024-06-29 15:53:57 +00:00
|
|
|
DynamicUser = true;
|
|
|
|
User = "tvix-binary-cache";
|
2024-07-08 17:35:59 +00:00
|
|
|
StateDirectory = "tvix-castore";
|
|
|
|
RuntimeDirectory = "tvix-castore";
|
|
|
|
} // systemdHardening;
|
2024-06-29 15:53:57 +00:00
|
|
|
|
2024-07-08 17:35:59 +00:00
|
|
|
};
|
|
|
|
})
|
|
|
|
++ (lib.mapAttrsToList (
|
|
|
|
name: cfg:
|
|
|
|
let
|
|
|
|
stateDir = "tvix-binary-cache-${cfg.name}";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
"nar-bridge-${cfg.name}" = {
|
|
|
|
wants = [ "tvix-store-${cfg.name}.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "tvix-store-${cfg.name}.service" ];
|
|
|
|
serviceConfig = rec {
|
|
|
|
ExecStart = "${lib.getExe pkgs.nar-bridge-go} --otlp=false --listen-addr=\"[::1]:${builtins.toString cfg.port}\" --store-addr=\"unix://%t/${stateDir}/socket\"";
|
2024-06-29 15:53:57 +00:00
|
|
|
|
2024-07-08 17:35:59 +00:00
|
|
|
DynamicUser = true;
|
|
|
|
User = "tvix-binary-cache";
|
|
|
|
} // systemdHardening;
|
2024-06-29 15:53:57 +00:00
|
|
|
};
|
2024-07-08 17:35:59 +00:00
|
|
|
"tvix-store-${cfg.name}" = {
|
|
|
|
wants = [ "tvix-castore.service" ];
|
|
|
|
after = [ "tvix-castore.service" ];
|
|
|
|
environment = {
|
|
|
|
BLOB_SERVICE_ADDR = "grpc+unix://%t/tvix-castore/socket";
|
|
|
|
DIRECTORY_SERVICE_ADDR = "grpc+unix://%t/tvix-castore/socket";
|
|
|
|
PATH_INFO_SERVICE_ADDR = "sled://%S/${stateDir}/pathinfo.sled";
|
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.tvix-store}/bin/tvix-store --otlp=false daemon --listen-address=\"%t/${stateDir}/socket\"";
|
2024-06-29 15:53:57 +00:00
|
|
|
|
2024-07-08 17:35:59 +00:00
|
|
|
DynamicUser = true;
|
|
|
|
User = "tvix-binary-cache";
|
|
|
|
StateDirectory = stateDir;
|
|
|
|
RuntimeDirectory = stateDir;
|
|
|
|
} // systemdHardening;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
) cfg.caches)
|
|
|
|
);
|
2024-06-29 15:53:57 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|