nixos-servers/nixos-modules/data-sharing.nix

104 lines
2.2 KiB
Nix
Raw Normal View History

{ pkgs, lib, config, ... }:
let
cfg = config.lab.data-sharing;
nfsShares = [
"/nextcloud/data"
"/radicale"
"/freshrss/data"
"/freshrss/extensions"
"/pihole/data"
"/pihole/dnsmasq"
"/hedgedoc/uploads"
"/traefik/acme"
"/forgejo/data"
"/forgejo/runner/data"
"/forgejo/runner/certs"
"/kitchenowl/data"
"/syncthing/config"
2024-01-15 20:34:25 +00:00
"/paperless-ngx/data"
"/paperless-ngx/redisdata"
"/media"
"/media/books"
"/media/movies"
"/media/music"
"/media/shows"
"/jellyfin/config"
"/transmission/config"
2024-02-15 08:27:08 +00:00
"/jellyseerr/config"
"/radarr/config"
"/prowlarr/config"
2024-02-18 17:19:39 +00:00
"/sonarr/config"
2024-02-24 20:45:29 +00:00
"/bazarr/config"
2024-04-13 20:21:26 +00:00
"/minecraft"
2024-04-27 18:53:32 +00:00
"/atticd"
"/longhorn-backup"
];
nfsExports = lib.strings.concatLines (
builtins.map
(share:
2024-03-22 21:19:44 +00:00
"${cfg.nfsRoot}${share} 192.168.30.0/16(rw,sync,no_subtree_check,no_root_squash)"
)
nfsShares
);
in
{
options.lab.data-sharing = {
enable = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Configure this server to serve our data using NFS and PostgreSQL.
'';
};
nfsRoot = lib.mkOption {
default = "/mnt/data/nfs";
type = lib.types.str;
description = ''
Root directory of NFS data.
'';
};
postgresDir = lib.mkOption {
default = "/mnt/data/postgresql/${config.services.postgresql.package.psqlSchema}";
type = lib.types.str;
description = ''
Postgresql data directory.
'';
};
};
config = lib.mkIf cfg.enable {
2024-03-22 21:19:44 +00:00
networking.firewall.allowedTCPPorts = [
2049 # NFS
5432 # PostgeSQL
111 # NFS
20048 # NFS
];
services = {
nfs.server = {
enable = true;
exports = nfsExports;
};
postgresql = {
enable = true;
package = pkgs.postgresql_15;
enableTCPIP = true;
dataDir = cfg.postgresDir;
authentication = ''
host nextcloud nextcloud all md5
host hedgedoc hedgedoc all md5
2024-01-15 20:34:25 +00:00
host paperless paperless all md5
2024-04-27 18:53:32 +00:00
host attic attic all md5
'';
};
};
};
}