2f0d0b5e4c
Replaces the Helm/k3s setup with a declarative NixOS configuration targeting
a Raspberry Pi 4. Services run as podman containers under systemd, with data
on an external HD at /mnt/data. Key components:
- flake.nix: multi-host flake with pi-main (aarch64) and a placeholder for a
second machine
- modules/common.nix: shared system config (nix, podman, sops, SSH)
- modules/storage.nix: external HD mount with per-service subdirs
- modules/caddy.nix: Caddy with cloudflare DNS-01 ACME + authelia forward_auth
- modules/cloudflared.nix: Cloudflare tunnel for remote access
- modules/backup.nix: restic daily backups with NC maintenance mode pre-hook
- modules/services/{openldap,authelia,gitea,nextcloud,phpldapadmin}.nix: core services
- modules/services/{jellyfin,transmission}.nix: media services (disabled by default)
- secrets/: sops-nix scaffold with .sops.yaml age key config
- hosts/pi-main/: hardware config + service selection for the Pi
- PORTING.md: step-by-step migration guide (SD card → data restore → verify)
136 lines
4.5 KiB
Nix
136 lines
4.5 KiB
Nix
{ config, lib, pkgs, homeyConfig, ... }:
|
|
|
|
# Nextcloud + PostgreSQL.
|
|
#
|
|
# Two containers:
|
|
# nextcloud-postgres — PostgreSQL, bound to localhost:5432
|
|
# nextcloud — Nextcloud PHP-FPM + Apache, bound to localhost:8080
|
|
#
|
|
# Volume layout:
|
|
# <dataDir>/nextcloud/db/ → /var/lib/postgresql/data (postgres)
|
|
# <dataDir>/nextcloud/html/ → /var/www/html (nextcloud)
|
|
#
|
|
# Secrets consumed from sops:
|
|
# nextcloud/admin_password
|
|
# nextcloud/postgres_password
|
|
|
|
let
|
|
cfg = config.homey.nextcloud;
|
|
dataDir = config.homey.storage.mountPoint;
|
|
domain = homeyConfig.domain;
|
|
in
|
|
{
|
|
options.homey.nextcloud = {
|
|
enable = lib.mkEnableOption "Nextcloud file server";
|
|
|
|
image = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "docker.io/nextcloud:latest";
|
|
};
|
|
|
|
postgresImage = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "docker.io/postgres:16";
|
|
};
|
|
|
|
port = lib.mkOption {
|
|
type = lib.types.port;
|
|
default = 8080;
|
|
description = "Host port Nextcloud listens on (bound to 127.0.0.1).";
|
|
};
|
|
|
|
postgresPort = lib.mkOption {
|
|
type = lib.types.port;
|
|
default = 5432;
|
|
description = "Host port PostgreSQL listens on (bound to 127.0.0.1).";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
# -----------------------------------------------------------------------
|
|
# Secrets
|
|
# -----------------------------------------------------------------------
|
|
sops.secrets."nextcloud/admin_password" = { owner = "root"; };
|
|
sops.secrets."nextcloud/postgres_password" = { owner = "root"; };
|
|
|
|
# -----------------------------------------------------------------------
|
|
# PostgreSQL container
|
|
# -----------------------------------------------------------------------
|
|
virtualisation.oci-containers.containers.nextcloud-postgres = {
|
|
image = cfg.postgresImage;
|
|
ports = [ "127.0.0.1:${toString cfg.postgresPort}:5432" ];
|
|
|
|
environment = {
|
|
POSTGRES_DB = "nextcloud_db";
|
|
POSTGRES_USER = "postgres";
|
|
# Password injected via env file
|
|
};
|
|
|
|
volumes = [
|
|
"${dataDir}/nextcloud/db:/var/lib/postgresql/data"
|
|
];
|
|
|
|
extraOptions = [ "--network=host" ];
|
|
};
|
|
|
|
systemd.services."podman-nextcloud-postgres" = {
|
|
serviceConfig = {
|
|
ExecStartPre = [
|
|
(pkgs.writeShellScript "nc-postgres-secrets-env" ''
|
|
set -euo pipefail
|
|
install -m 600 /dev/null /run/nc-postgres-secrets.env
|
|
echo "POSTGRES_PASSWORD=$(cat ${config.sops.secrets."nextcloud/postgres_password".path})" \
|
|
>> /run/nc-postgres-secrets.env
|
|
'')
|
|
];
|
|
EnvironmentFile = "/run/nc-postgres-secrets.env";
|
|
};
|
|
postStop = "rm -f /run/nc-postgres-secrets.env";
|
|
after = lib.mkAfter [ "mnt-data.mount" ];
|
|
requires = lib.mkAfter [ "mnt-data.mount" ];
|
|
};
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Nextcloud container
|
|
# -----------------------------------------------------------------------
|
|
virtualisation.oci-containers.containers.nextcloud = {
|
|
image = cfg.image;
|
|
ports = [ "127.0.0.1:${toString cfg.port}:80" ];
|
|
|
|
environment = {
|
|
POSTGRES_HOST = "127.0.0.1";
|
|
POSTGRES_DB = "nextcloud_db";
|
|
POSTGRES_USER = "postgres";
|
|
NEXTCLOUD_ADMIN_USER = "admin";
|
|
NEXTCLOUD_TRUSTED_DOMAINS = "nextcloud.${domain}";
|
|
OVERWRITEPROTOCOL = "https";
|
|
OVERWRITECLIURL = "https://nextcloud.${domain}";
|
|
# Passwords injected via env file
|
|
};
|
|
|
|
volumes = [
|
|
"${dataDir}/nextcloud/html:/var/www/html"
|
|
];
|
|
|
|
extraOptions = [ "--network=host" ];
|
|
};
|
|
|
|
systemd.services."podman-nextcloud" = {
|
|
serviceConfig = {
|
|
ExecStartPre = [
|
|
(pkgs.writeShellScript "nc-secrets-env" ''
|
|
set -euo pipefail
|
|
install -m 600 /dev/null /run/nc-secrets.env
|
|
echo "POSTGRES_PASSWORD=$(cat ${config.sops.secrets."nextcloud/postgres_password".path})" >> /run/nc-secrets.env
|
|
echo "NEXTCLOUD_ADMIN_PASSWORD=$(cat ${config.sops.secrets."nextcloud/admin_password".path})" >> /run/nc-secrets.env
|
|
'')
|
|
];
|
|
EnvironmentFile = "/run/nc-secrets.env";
|
|
};
|
|
postStop = "rm -f /run/nc-secrets.env";
|
|
after = lib.mkAfter [ "mnt-data.mount" "podman-nextcloud-postgres.service" ];
|
|
requires = lib.mkAfter [ "mnt-data.mount" "podman-nextcloud-postgres.service" ];
|
|
};
|
|
};
|
|
}
|