Home : Add temporary fsight services.

This commit is contained in:
Dmitry Voronin 2024-07-03 01:59:28 +03:00
parent aa4f59308d
commit 458125b697
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
6 changed files with 252 additions and 14 deletions

199
container/Fsight.nix Normal file
View file

@ -0,0 +1,199 @@
{ container, pkgs, config, lib, util, ... }: with lib; let
cfg = config.container.module.fsight;
hostConfig = config;
in {
options = {
container.module.fsight = {
enable = mkEnableOption "Fsight temporary servers.";
address = mkOption {
default = "10.1.0.29";
type = types.str;
};
# port = mkOption {
# default = 3000;
# type = types.int;
# };
# domain = mkOption {
# default = "git.${config.container.domain}";
# type = types.str;
# };
storage = mkOption {
default = "${config.container.storage}/fsight";
type = types.str;
};
};
};
config = mkIf cfg.enable {
systemd.tmpfiles.rules = container.mkContainerDir cfg [
"git"
"cloud"
"postgres"
];
containers.fsight = container.mkContainer cfg {
bindMounts = {
"/var/lib/gitea" = {
hostPath = "${cfg.storage}/git";
isReadOnly = false;
};
"/var/lib/postgresql" = {
hostPath = "${cfg.storage}/postgres";
isReadOnly = false;
};
"/var/lib/nextcloud" = {
hostPath = "${cfg.storage}/cloud";
isReadOnly = false;
};
};
config = { config, ... }: container.mkContainerConfig cfg {
environment.systemPackages = with pkgs; [ gitea postgresql ];
services.gitea = let
domain = "fmp-git.${hostConfig.container.domain}";
in {
enable = true;
stateDir = "/var/lib/gitea";
database = {
type = "postgres";
# host = postgre.address;
# port = postgre.port;
user = "gitea";
name = "gitea";
createDatabase = true;
};
settings = let
gcArgs = "--aggressive --no-cruft --prune=now";
gcTimeout = 600;
in {
"service".DISABLE_REGISTRATION = true;
"log".LEVEL = "Error";
"server" = {
DISABLE_SSH = true;
DOMAIN = domain;
HTTP_ADDR = cfg.address;
ROOT_URL = "https://${domain}";
};
"ui" = {
AMBIGUOUS_UNICODE_DETECTION = false;
};
"service.explore" = {
REQUIRE_SIGNIN_VIEW = true;
};
"repository" = {
DEFAULT_PRIVATE = "private";
DEFAULT_PUSH_CREATE_PRIVATE = true;
};
"repository.pull-request".DEFAULT_MERGE_STYLE = "rebase";
"repository.issue".MAX_PINNED = 99999;
"cron" = {
ENABLED = true;
RUN_AT_START = true;
};
"repo-archive".ENABLED = false;
"cron.update_mirrors".SCHEDULE = "@midnight";
"cron.cleanup_actions".ENABLED = true;
"cron.git_gc_repos" = {
ENABLED = true;
SCHEDULE = "@midnight";
TIMEOUT = gcTimeout;
ARGS = gcArgs;
};
"git" = {
GC_ARGS = gcArgs;
};
"git.timeout".GC = gcTimeout;
};
};
services.nextcloud = let
domain = "fmp-cloud.${hostConfig.container.domain}";
in {
enable = true;
# package = pkgs.nextcloud29;
hostName = domain;
# phpOptions = {
# memory_limit = lib.mkForce "20G";
# };
config = {
adminuser = "root";
adminpassFile = "${pkgs.writeText "NextcloudPassword" "root"}";
# dbhost = postgres.address;
dbname = "nextcloud";
dbpassFile = "${pkgs.writeText "NextcloudDbPassword" "nextcloud"}";
dbtype = "pgsql";
dbuser = "nextcloud";
};
extraApps = {
inherit (config.services.nextcloud.package.packages.apps) deck notes onlyoffice;
};
extraAppsEnable = true;
settings = {
trusted_domains = [ domain ];
trusted_proxies = [ hostConfig.container.module.proxy.address ];
allow_local_remote_servers = true;
};
};
services.postgresql = let
authentication = util.trimTabs ''
local all all trust
host all all 0.0.0.0/0 trust
'';
ensureDatabases = [
"root"
"gitea"
"nextcloud"
];
ensureUsers = [
{
name = "root";
ensureClauses = {
superuser = true;
createrole = true;
createdb = true;
};
ensureDBOwnership = true;
} {
name = "gitea";
ensureClauses = {
createrole = true;
createdb = true;
};
ensureDBOwnership = true;
} {
name = "nextcloud";
ensureClauses = {
createrole = true;
createdb = true;
};
ensureDBOwnership = true;
}
];
in {
inherit authentication ensureDatabases ensureUsers;
enable = true;
package = pkgs.postgresql_16;
dataDir = "/var/lib/postgresql/data/16";
enableTCPIP = true;
# NOTE: Debug mode.
# settings = {
# log_connections = true;
# log_destination = lib.mkForce "syslog";
# log_disconnections = true;
# log_statement = "all";
# logging_collector = true;
# };
};
};
};
};
}

View file

@ -50,6 +50,7 @@ in {
host = postgre.address; host = postgre.address;
port = postgre.port; port = postgre.port;
user = "gitea"; user = "gitea";
name = "gitea";
createDatabase = false; createDatabase = false;
}; };

View file

@ -71,6 +71,7 @@ in {
enable = true; enable = true;
recommendedOptimisation = true; recommendedOptimisation = true;
recommendedProxySettings = true; recommendedProxySettings = true;
clientMaxBodySize = "1024m";
appendConfig = util.trimTabs '' appendConfig = util.trimTabs ''
worker_processes 4; worker_processes 4;
''; '';

View file

@ -0,0 +1,50 @@
{ util, config, container, ... }: let
domain = config.container.domain;
address = "10.1.0.29";
in {
"fmp-cloud.${domain}" = container.mkServer {
extraConfig = util.trimTabs ''
listen 443 ssl;
set $fmpnextcloud ${address}:80;
location ~ ^/(settings/admin|settings/users|settings/apps|api) {
allow ${config.container.localAccess};
allow ${config.container.module.vpn.address};
deny all;
proxy_pass http://$fmpnextcloud$request_uri;
}
location / {
proxy_pass http://$fmpnextcloud$request_uri;
}
ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem;
include /etc/letsencrypt/conf/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem;
'';
};
"fmp-git.${domain}" = container.mkServer {
extraConfig = util.trimTabs ''
listen 443 ssl;
set $fmpgitea ${address}:3000;
location ~ ^/(admin|api) {
allow ${config.container.localAccess};
allow ${config.container.module.vpn.address};
deny all;
proxy_pass http://$fmpgitea$request_uri;
}
location / {
proxy_pass http://$fmpgitea$request_uri;
}
ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem;
include /etc/letsencrypt/conf/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem;
'';
};
}

View file

@ -14,20 +14,6 @@ in {
proxy_pass http://''$${name}$request_uri; proxy_pass http://''$${name}$request_uri;
} }
location /markdown {
allow ${config.container.localAccess};
allow ${config.container.module.vpn.address};
deny all;
proxy_set_header Content-Type "application/json";
proxy_set_header Authorization "Basic dm9yb25pbmQ6QUxwWHZoRlRNYmpIazY3OVBkZDhCTjZNS0hyWjZ4aGU=";
proxy_pass_header Content-Type;
proxy_pass_header Authorization;
proxy_pass http://''$${name}/api/v1/markdown/raw;
}
location / { location / {
# allow ${config.container.localAccess}; # allow ${config.container.localAccess};
# allow ${config.container.module.status.address}; # allow ${config.container.module.status.address};

View file

@ -8,6 +8,7 @@
ddns.enable = true; ddns.enable = true;
dns.enable = true; dns.enable = true;
download.enable = true; download.enable = true;
fsight.enable = true;
git.enable = true; git.enable = true;
# ISSUE: hdd.enable = true; # ISSUE: hdd.enable = true;
home.enable = true; home.enable = true;