2024-12-12 14:41:43 +01:00
|
|
|
# SPDX-FileCopyrightText: 2024 Maurice Debray <maurice.debray@dgnum.eu>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
2024-07-23 20:47:25 +02:00
|
|
|
{ pkgs, config, ... }:
|
|
|
|
let
|
|
|
|
|
2024-10-06 23:54:00 +02:00
|
|
|
# How to add a cache:
|
|
|
|
# - Add the relevant services (likely only a pathinfoservice) to the
|
|
|
|
# composition config (store-config.composition).
|
|
|
|
# - Add an endpoint (store-config.endpoints).
|
|
|
|
# - Append a proxy configuration to nginx in order to make the store
|
|
|
|
# accessible.
|
|
|
|
# - Update cache-info.nix so users can add the cache to their configuration
|
2024-07-23 20:47:25 +02:00
|
|
|
store-config = {
|
|
|
|
composition = {
|
|
|
|
blobservices.default = {
|
|
|
|
type = "objectstore";
|
|
|
|
object_store_url = "file://${dataDir}/blob.objectstore";
|
|
|
|
object_store_options = { };
|
|
|
|
};
|
|
|
|
directoryservices = {
|
2024-09-23 00:40:06 +02:00
|
|
|
redb = {
|
|
|
|
type = "redb";
|
2024-07-23 20:47:25 +02:00
|
|
|
is_temporary = false;
|
2024-09-23 00:40:06 +02:00
|
|
|
path = "${dataDir}/directory.redb";
|
2024-07-23 20:47:25 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
pathinfoservices = {
|
|
|
|
infra = {
|
2024-09-23 00:40:06 +02:00
|
|
|
type = "redb";
|
2024-07-23 20:47:25 +02:00
|
|
|
is_temporary = false;
|
2024-09-23 00:40:06 +02:00
|
|
|
path = "${dataDir}/pathinfo.redb";
|
2024-07-23 20:47:25 +02:00
|
|
|
};
|
|
|
|
infra-signing = {
|
|
|
|
type = "keyfile-signing";
|
|
|
|
inner = "infra";
|
|
|
|
keyfile = config.age.secrets."tvix-store-infra-signing-key".path;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
endpoints = {
|
|
|
|
"127.0.0.1:8056" = {
|
|
|
|
endpoint_type = "Http";
|
|
|
|
blob_service = "default";
|
2024-09-23 00:40:06 +02:00
|
|
|
directory_service = "redb";
|
2024-07-23 20:47:25 +02:00
|
|
|
path_info_service = "infra";
|
|
|
|
};
|
|
|
|
"127.0.0.1:8058" = {
|
|
|
|
endpoint_type = "Http";
|
|
|
|
blob_service = "default";
|
2024-09-23 00:40:06 +02:00
|
|
|
directory_service = "redb";
|
2024-07-23 20:47:25 +02:00
|
|
|
path_info_service = "infra-signing";
|
|
|
|
};
|
|
|
|
# Add grpc for management and because it is nice
|
|
|
|
"127.0.0.1:8057" = {
|
|
|
|
endpoint_type = "Grpc";
|
|
|
|
blob_service = "default";
|
2024-09-23 00:40:06 +02:00
|
|
|
directory_service = "redb";
|
2024-07-23 20:47:25 +02:00
|
|
|
path_info_service = "infra";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-10-06 23:54:00 +02:00
|
|
|
|
|
|
|
settingsFormat = pkgs.formats.toml { };
|
|
|
|
|
|
|
|
webHost = "tvix-store.dgnum.eu";
|
|
|
|
|
|
|
|
dataDir = "/data/slow/tvix-store";
|
|
|
|
|
2024-07-23 20:47:25 +02: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-10-06 23:54:00 +02:00
|
|
|
|
2024-07-23 20:47:25 +02:00
|
|
|
toml = {
|
|
|
|
composition = settingsFormat.generate "composition.toml" store-config.composition;
|
|
|
|
endpoints = settingsFormat.generate "endpoints.toml" store-config.endpoints;
|
|
|
|
};
|
2024-10-06 23:54:00 +02:00
|
|
|
|
2024-07-23 20:47:25 +02:00
|
|
|
package = pkgs.callPackage ./package { };
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
age-secrets.autoMatch = [
|
|
|
|
"tvix-store"
|
|
|
|
"nginx"
|
|
|
|
];
|
|
|
|
|
2024-10-06 23:54:00 +02:00
|
|
|
services.nginx.virtualHosts.${webHost} = {
|
2024-07-23 20:47:25 +02:00
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations = {
|
|
|
|
"/infra/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:8056/";
|
|
|
|
extraConfig = ''
|
|
|
|
client_max_body_size 50G;
|
|
|
|
limit_except GET {
|
|
|
|
auth_basic "Password required";
|
|
|
|
auth_basic_user_file ${config.age.secrets."nginx-tvix-store-password".path};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
"/infra-signing/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:8058/";
|
|
|
|
extraConfig = ''
|
|
|
|
client_max_body_size 50G;
|
|
|
|
auth_basic "Password required";
|
|
|
|
auth_basic_user_file ${config.age.secrets."nginx-tvix-store-password-ci".path};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-10-06 23:54:00 +02:00
|
|
|
|
2024-07-23 20:47:25 +02:00
|
|
|
# TODO add tvix-store cli here
|
|
|
|
# environment.systemPackages = [ ];
|
2024-10-06 23:54:00 +02:00
|
|
|
|
2024-07-23 20:47:25 +02:00
|
|
|
users.users.tvix-store = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "tvix-store";
|
|
|
|
};
|
|
|
|
users.groups.tvix-store = { };
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [ "d ${dataDir} 770 tvix-castore tvix-castore -" ];
|
|
|
|
|
|
|
|
systemd.services."tvix-store" = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment = {
|
2024-11-09 19:11:10 +01:00
|
|
|
RUST_LOG = "info";
|
2024-07-23 20:47:25 +02:00
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
UMask = "007";
|
2024-11-09 19:11:10 +01:00
|
|
|
LimitNOFILE = 1048576;
|
2024-07-23 20:47:25 +02:00
|
|
|
ExecStart = "${package}/bin/multitier-tvix-cache --endpoints-config ${toml.endpoints} --store-composition ${toml.composition}";
|
|
|
|
StateDirectory = "tvix-store";
|
|
|
|
RuntimeDirectory = "tvix-store";
|
|
|
|
User = "tvix-store";
|
|
|
|
Group = "tvix-store";
|
|
|
|
ReadWritePaths = [ dataDir ];
|
|
|
|
} // systemdHardening;
|
|
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
80
|
|
|
|
443
|
|
|
|
];
|
|
|
|
}
|