nextcloud-container/nextcloud-container.nix

147 lines
4.1 KiB
Nix
Raw Normal View History

2023-08-31 14:48:31 -07:00
{ config, lib, pkgs, ... }@toplevel:
with lib;
let
cfg = config.services.nextcloudContainer;
hostname = config.instance.hostname;
2023-08-31 15:16:38 -07:00
hostSecrets = config.fudo.secrets.host-secrets."${hostname}";
2023-08-31 14:48:31 -07:00
mkEnvFile = envVars:
let
envLines =
mapAttrsToList (var: val: ''${var}="${toString val}"'') envVars;
in pkgs.writeText "envFile" (concatStringsSep "\n" envLines);
mkUserMap = uid: "${toString uid}:${toString uid}";
postgresPasswdFile =
pkgs.lib.passwd.stablerandom-passwd-file "nextcloud-postgres-passwd"
config.instance.build-seed;
in {
options.services.nextcloudContainer = with types; {
enable = mkEnableOption "Enable Nextcloud running in an Arion container.";
state-directory = mkOption {
type = str;
description = "Directory at which to store server state data.";
};
2023-09-04 10:44:01 -07:00
hostname = mkOption {
type = str;
description = "Hostname at which the server is available.";
};
package = mkOption {
type = package;
description = "NextCloud package to use.";
};
extra-apps = mkOption {
type = attrsOf package;
2023-09-04 10:44:01 -07:00
description = "List of other apps to enable.";
default = { };
2023-08-31 14:48:31 -07:00
};
uids = {
nextcloud = mkOption {
type = int;
default = 740;
};
2023-09-04 10:44:01 -07:00
2023-08-31 14:48:31 -07:00
postgres = mkOption {
type = int;
default = 741;
};
};
port = mkOption {
type = port;
description = "Intenal port on which to listen for requests.";
default = 6093;
};
timezone = mkOption {
type = str;
default = "America/Winnipeg";
};
};
config = mkIf cfg.enable {
systemd = {
tmpfiles.rules = [
2023-09-04 10:44:01 -07:00
"d ${cfg.state-directory}/home 0700 nextcloud root - -"
"d ${cfg.state-directory}/data 0700 nextcloud root - -"
"d ${cfg.state-directory}/postgres 0700 nextcloud root - -"
2023-08-31 14:48:31 -07:00
];
};
users.users = {
nextcloud = {
isSystemUser = true;
group = "nextcloud";
uid = cfg.uids.nextcloud;
};
};
fudo.secrets.host-secrets."${hostname}" = {
2023-09-04 10:44:01 -07:00
nextcloudAdminPasswd = {
source-file =
pkgs.lib.passwd.stablerandom-passwd-file "nextcloud-admin-passwd"
config.instance.build-seed;
target-file = "/run/nextcloud/admin.passwd";
2023-08-31 14:48:31 -07:00
};
};
2023-08-31 14:53:44 -07:00
virtualisation.arion.projects.nextcloud.settings = let
2023-08-31 14:48:31 -07:00
image = { ... }: {
project.name = "nextcloud";
services = {
2023-09-04 10:44:01 -07:00
nextcloud = { pkgs, lib, ... }: {
2023-08-31 14:48:31 -07:00
nixos = {
useSystemd = true;
configuration = {
boot.tmpOnTmpfs = true;
2023-08-31 15:24:24 -07:00
system.nssModules = lib.mkForce [ ];
2023-09-02 10:22:08 -07:00
services = {
nscd.enable = false;
2023-09-04 10:44:01 -07:00
postgresql.enable = true;
nextcloud = {
2023-09-02 10:22:08 -07:00
enable = true;
2023-09-04 10:44:01 -07:00
package = cfg.package;
hostName = cfg.hostname;
home = "/var/lib/nextcloud/home";
datadir = "/var/lib/nextcloud/data";
configureRedis = true;
extraAppsEnable = true;
extraApps = cfg.extra-apps;
enableBrokenCiphersForSSE = false;
database.createLocally = true;
config = {
dbtype = "pgsql";
adminpassFile = "/run/nextcloud/admin.passwd";
2023-08-31 14:48:31 -07:00
};
};
};
};
};
service = {
2023-09-04 10:44:01 -07:00
restart = "always";
volumes = [
"${cfg.state-directory}/home:/var/lib/nextcloud/home"
"${cfg.state-directory}/data:/var/lib/nextcloud/data"
"${hostSecrets.nextcloudAdminPasswd.target-file}:/run/nextcloud/admin.passwd:ro,Z"
"${cfg.state-directory}/postgres:/var/lib/postgresql/data"
];
2023-09-04 21:44:03 -07:00
user = mkUserMap cfg.uids.nextcloud;
2023-09-04 18:21:44 -07:00
ports = [ "${toString cfg.port}:80" ];
2023-08-31 14:48:31 -07:00
};
};
};
};
in { imports = [ image ]; };
};
}