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
|
|
|
|
{
|
2024-07-19 08:51:57 +00:00
|
|
|
imports = [ ./nginx.nix ];
|
2024-06-29 15:53:57 +00:00
|
|
|
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 = ''
|
2024-07-18 20:18:20 +00:00
|
|
|
`blob-service-addr` option for the mutualized content addressed storage.
|
2024-07-08 17:35:59 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
directory-service-addr = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "sled://%S/tvix-castore/directories.sled";
|
|
|
|
description = ''
|
2024-07-18 20:18:20 +00:00
|
|
|
`directory-service-addr` option for the mutualized content addressed storage.
|
2024-07-08 17:35:59 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
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-07-20 13:59:30 +00:00
|
|
|
path-info-service-addr = lib.mkOption {
|
|
|
|
type = with lib.types; str;
|
|
|
|
description = "Path info service path";
|
|
|
|
default = "sled://%S/%N/pathinfo.sled";
|
|
|
|
};
|
2024-07-18 20:21:03 +00:00
|
|
|
remote-path-info-service-addr = lib.mkOption {
|
|
|
|
type = with lib.types; nullOr str;
|
|
|
|
description = "Upstream cache to substitute from if nothing in ";
|
|
|
|
example = "nix+https://cache.nixos.org?trusted-public-keys=cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=";
|
|
|
|
default = null;
|
|
|
|
};
|
2024-07-18 20:21:54 +00:00
|
|
|
blob-service-addr = lib.mkOption {
|
|
|
|
type = with lib.types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Use a specific blob service and do not use the mutualized one.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
directory-service-addr = lib.mkOption {
|
|
|
|
type = with lib.types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Use a specific directory address and do not use the mutualized one.
|
|
|
|
'';
|
|
|
|
};
|
2024-07-08 17:35:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
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-18 14:57:05 +00:00
|
|
|
environment.systemPackages = [ pkgs.tvix-store ];
|
|
|
|
|
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
|
2024-07-20 13:59:30 +00:00
|
|
|
unitName = "tvix-store-${cfg.name}";
|
2024-07-08 17:35:59 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
"nar-bridge-${cfg.name}" = {
|
|
|
|
wants = [ "tvix-store-${cfg.name}.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "tvix-store-${cfg.name}.service" ];
|
|
|
|
serviceConfig = rec {
|
2024-07-20 13:59:30 +00:00
|
|
|
ExecStart = "${lib.getExe pkgs.nar-bridge-go} --otlp=false --listen-addr=\"[::1]:${builtins.toString cfg.port}\" --store-addr=\"unix://%t/${unitName}/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-20 13:59:30 +00:00
|
|
|
${unitName} = {
|
2024-07-08 17:35:59 +00:00
|
|
|
wants = [ "tvix-castore.service" ];
|
|
|
|
after = [ "tvix-castore.service" ];
|
|
|
|
environment = {
|
2024-07-18 20:21:54 +00:00
|
|
|
BLOB_SERVICE_ADDR =
|
|
|
|
if cfg.blob-service-addr != null then
|
|
|
|
cfg.blob-service-addr
|
|
|
|
else
|
|
|
|
"grpc+unix://%t/tvix-castore/socket";
|
|
|
|
DIRECTORY_SERVICE_ADDR =
|
|
|
|
if cfg.directory-service-addr != null then
|
|
|
|
cfg.directory-service-addr
|
|
|
|
else
|
|
|
|
"grpc+unix://%t/tvix-castore/socket";
|
2024-07-20 13:59:30 +00:00
|
|
|
PATH_INFO_SERVICE_ADDR = cfg.path-info-service-addr;
|
2024-07-18 20:21:03 +00:00
|
|
|
REMOTE_PATH_INFO_SERVICE_ADDR = lib.mkIf (
|
|
|
|
cfg.remote-path-info-service-addr != null
|
|
|
|
) cfg.remote-path-info-service-addr;
|
2024-07-08 17:35:59 +00:00
|
|
|
};
|
|
|
|
serviceConfig = {
|
2024-07-20 13:59:30 +00:00
|
|
|
ExecStart = "${pkgs.tvix-store}/bin/tvix-store --otlp=false daemon --listen-address=\"%t/${unitName}/socket\"";
|
2024-07-08 17:35:59 +00:00
|
|
|
DynamicUser = true;
|
|
|
|
User = "tvix-binary-cache";
|
2024-07-20 13:59:30 +00:00
|
|
|
StateDirectory = unitName;
|
|
|
|
RuntimeDirectory = unitName;
|
2024-07-08 17:35:59 +00:00
|
|
|
} // systemdHardening;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
) cfg.caches)
|
|
|
|
);
|
2024-06-29 15:53:57 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|