nixos-servers/kubenix-modules/attic.nix

181 lines
4.8 KiB
Nix

{ pkgs, ... }: {
kubernetes.resources =
let
atticSettings = {
database.url = "ref+sops://secrets/sops.yaml#attic/databaseURL";
storage = {
type = "local";
path = "/var/lib/atticd/storage";
};
listen = "[::]:8080";
# Data chunking
#
# Warning: If you change any of the values here, it will be
# difficult to reuse existing chunks for newly-uploaded NARs
# since the cutpoints will be different. As a result, the
# deduplication ratio will suffer for a while after the change.
chunking = {
# The minimum NAR size to trigger chunking
#
# If 0, chunking is disabled entirely for newly-uploaded NARs.
# If 1, all NARs are chunked.
nar-size-threshold = 64 * 1024; # 64 KiB
# The preferred minimum size of a chunk, in bytes
min-size = 16 * 1024; # 16 KiB
# The preferred average size of a chunk, in bytes
avg-size = 64 * 1024; # 64 KiB
# The preferred maximum size of a chunk, in bytes
max-size = 256 * 1024; # 256 KiB
};
};
generatedConfig = (pkgs.formats.toml { }).generate "attic.toml" atticSettings;
in
{
configMaps = {
attic-env.data.ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64 = "ref+sops://secrets/sops.yaml#attic/jwtToken";
attic-config.data.config = builtins.readFile generatedConfig;
attic-db-env.data = {
POSTGRES_DB = "attic";
POSTGRES_USER = "attic";
POSTGRES_PASSWORD = "ref+sops://secrets/sops.yaml#/attic/databasePassword";
PGDATA = "/pgdata/data";
};
};
deployments = {
attic = {
metadata.labels = {
app = "attic";
component = "website";
};
spec = {
selector.matchLabels = {
app = "attic";
component = "website";
};
template = {
metadata.labels = {
app = "attic";
component = "website";
};
spec = {
containers.attic = {
image = "git.kun.is/home/atticd:fd910d91c2143295e959d2c903e9ea25cf94ba27";
envFrom = [{ configMapRef.name = "attic-env"; }];
ports.web.containerPort = 8080;
args = [ "-f" "/etc/atticd/config.toml" ];
volumeMounts = [
{
name = "data";
mountPath = "/var/lib/atticd/storage";
}
{
name = "config";
mountPath = "/etc/atticd/config.toml";
subPath = "config";
}
];
};
volumes = {
data.persistentVolumeClaim.claimName = "attic";
config.configMap.name = "attic-config";
};
securityContext = {
fsGroup = 0;
fsGroupChangePolicy = "OnRootMismatch";
};
};
};
};
};
attic-db = {
metadata.labels = {
app = "attic";
component = "database";
};
spec = {
selector.matchLabels = {
app = "attic";
component = "database";
};
template = {
metadata.labels = {
app = "attic";
component = "database";
};
spec = {
containers.postgres = {
image = "postgres:15";
imagePullPolicy = "IfNotPresent";
ports.postgres.containerPort = 5432;
envFrom = [{ configMapRef.name = "attic-db-env"; }];
volumeMounts = [{
name = "data";
mountPath = "/pgdata";
}];
};
volumes.data.persistentVolumeClaim.claimName = "attic-db";
};
};
};
};
};
services = {
attic.spec = {
selector = {
app = "attic";
component = "website";
};
ports.web = {
port = 80;
targetPort = "web";
};
};
attic-db.spec = {
selector = {
app = "attic";
component = "database";
};
ports.postgres = {
port = 5432;
targetPort = "postgres";
};
};
};
};
lab = {
ingresses.attic = {
host = "attic.kun.is";
# entrypoint = "localsecure";
service = {
name = "attic";
portName = "web";
};
};
};
}