Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sweenu committed Feb 5, 2024
1 parent 430b7b4 commit f4b983b
Showing 1 changed file with 50 additions and 46 deletions.
96 changes: 50 additions & 46 deletions hosts/najdorf/nextcloud.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,9 @@ in
resticNextcloudPassword.file = "${self}/secrets/restic/nextcloud.age";
};

services.restic = {
backups.nextcloud = {
initialize = true;
repository = "sftp:root@grunfeld:/data/backups/nextcloud";
paths = [ nextcloudDir ];
pruneOpts = [ "--keep-last 36" "--keep-daily 14" "--keep-weekly 12" ];
timerConfig = {
OnCalendar = "*-*-* *:00:00"; # every hour
RandomizedDelaySec = "5m";
};
passwordFile = config.age.secrets.resticNextcloudPassword.path;
backupPrepareCommand =
let
servicesSettings = config.virtualisation.arion.projects.nextcloud.settings.services;
dbContainerName = servicesSettings.db.service.container_name;
postgresUser = servicesSettings.db.service.environment.POSTGRES_USER;
postgresDatabase = servicesSettings.nextcloud.service.environment.POSTGRES_DB;
in
''
${pkgs.docker}/bin/docker exec ${dbContainerName} \
pg_dump -U ${postgresUser} -d ${postgresDatabase} > \
${nextcloudDir}/db.dump
'';
backupCleanupCommand = "${pkgs.curl}/bin/curl https://hc-ping.com/3e004d53-809a-4386-bb45-a36fc919120a";
};
};

virtualisation.arion.projects.nextcloud.settings = let version = "28"; in {
networks.traefik.external = true;

services = rec {
nextcloud.service = {
image = "nextcloud:${version}";
Expand All @@ -58,23 +32,23 @@ in
networks = [ "default" config.virtualisation.arion.projects.traefik.settings.networks.traefik.name ];
volumes = nextcloudVolumes;
environment = {
"POSTGRES_HOST" = "db";
"POSTGRES_DB" = "nextcloud";
"POSTGRES_USER" = db.service.environment."POSTGRES_USER";
"POSTGRES_PASSWORD_FILE" = db.service.environment."POSTGRES_PASSWORD_FILE";
"NEXTCLOUD_ADMIN_USER_FILE" = config.age.secrets."nextcloud/adminUser".path;
"NEXTCLOUD_ADMIN_PASSWORD_FILE" = config.age.secrets."nextcloud/adminPassword".path;
"NEXTCLOUD_TRUSTED_DOMAINS" = "nextcloud.${config.vars.domainName}";
"TRUSTED_PROXIES" = "172.16.0.0/12";
"OVERWRITEPROTOCOL" = "https";
"SMTP_HOST" = config.vars.smtpHost;
"SMTP_PORT" = config.vars.smtpPort;
"SMTP_NAME" = config.vars.smtpUsername;
"SMTP_SECURE" = "tls";
"MAIL_FROM_ADDRESS" = config.vars.email;
"MAIL_DOMAIN" = builtins.elemAt (lib.strings.splitString "@" config.vars.email) 1;
"PHP_UPLOAD_LIMIT" = "16G";
"APACHE_BODY_LIMIT" = "0";
POSTGRES_HOST = "db";
POSTGRES_DB = "nextcloud";
POSTGRES_USER = db.service.environment."POSTGRES_USER";
POSTGRES_PASSWORD_FILE = db.service.environment."POSTGRES_PASSWORD_FILE";
NEXTCLOUD_ADMIN_USER_FILE = config.age.secrets."nextcloud/adminUser".path;
NEXTCLOUD_ADMIN_PASSWORD_FILE = config.age.secrets."nextcloud/adminPassword".path;
NEXTCLOUD_TRUSTED_DOMAINS = "nextcloud.${config.vars.domainName}";
TRUSTED_PROXIES = "172.16.0.0/12";
OVERWRITEPROTOCOL = "https";
SMTP_HOST = config.vars.smtpHost;
SMTP_PORT = config.vars.smtpPort;
SMTP_NAME = config.vars.smtpUsername;
SMTP_SECURE = "tls";
MAIL_FROM_ADDRESS = config.vars.email;
MAIL_DOMAIN = builtins.elemAt (lib.strings.splitString "@" config.vars.email) 1;
PHP_UPLOAD_LIMIT = "16G";
APACHE_BODY_LIMIT = "0";
};
env_file = [ config.age.secrets."nextcloud/envFile".path ];
labels = {
Expand All @@ -85,30 +59,60 @@ in
"traefik.http.middlewares.nextcloud-redirectregex.redirectregex.replacement" = "https://\$\${1}/remote.php/dav/";
};
};

db.service = {
image = "postgres:11";
container_name = "nextcloud_db";
networks = [ "default" ];
environment = {
"POSTGRES_USER" = "postgres";
"POSTGRES_PASSWORD_FILE" = config.age.secrets."nextcloud/dbPassword".path;
POSTGRES_USER = "postgres";
POSTGRES_PASSWORD_FILE = config.age.secrets."nextcloud/dbPassword".path;
};
volumes = [
"nextcloud_db:/var/lib/postgresql/data"
"${nextcloudSecretsDir}:${nextcloudSecretsDir}:ro"
];
};

cron.service = {
image = "nextcloud:${version}";
volumes = nextcloudVolumes;
entrypoint = "/cron.sh";
depends_on = [ "db" ];
};
};

docker-compose.volumes = {
nextcloud = { };
nextcloud_db = { };
};
};

services.restic = {
backups.nextcloud = {
initialize = true;
repository = "sftp:root@grunfeld:/data/backups/nextcloud";
paths = [ nextcloudDir ];
pruneOpts = [ "--keep-last 36" "--keep-daily 14" "--keep-weekly 12" ];
timerConfig = {
OnCalendar = "*-*-* *:00:00"; # every hour
RandomizedDelaySec = "5m";
};
passwordFile = config.age.secrets.resticNextcloudPassword.path;
backupPrepareCommand =
let
servicesSettings = config.virtualisation.arion.projects.nextcloud.settings.services;
dbContainerName = servicesSettings.db.service.container_name;
postgresUser = servicesSettings.db.service.environment.POSTGRES_USER;
postgresDatabase = servicesSettings.nextcloud.service.environment.POSTGRES_DB;
in
''
${pkgs.docker}/bin/docker exec ${dbContainerName} \
pg_dump -U ${postgresUser} -d ${postgresDatabase} > \
${nextcloudDir}/db.dump
'';
backupCleanupCommand = "${pkgs.curl}/bin/curl https://hc-ping.com/3e004d53-809a-4386-bb45-a36fc919120a";
};
};
}

0 comments on commit f4b983b

Please sign in to comment.