From cc12ab5bbaf9ed05b425ba2af35a3965453b3ff3 Mon Sep 17 00:00:00 2001 From: oqyude Date: Mon, 10 Aug 2026 03:10:35 +0300 Subject: [PATCH] refactoring --- modules/server/calibre-web.nix | 21 ++++++---- modules/server/default.nix | 10 +++-- modules/server/homebox.nix | 42 ++++++++++--------- modules/server/miniflux.nix | 1 - modules/server/n8n.nix | 32 ++++++++------- modules/server/navidrome.nix | 9 ++-- modules/server/nginx.nix | 75 ++++++---------------------------- modules/server/node-red.nix | 21 ---------- modules/server/onlyoffice.nix | 10 ++--- modules/server/postgresql.nix | 31 ++++++++------ modules/server/samba.nix | 34 ++++++++------- modules/server/step-ca.nix | 22 +++++----- modules/server/syncthing.nix | 1 - modules/server/trilium.nix | 7 +++- modules/server/uptime-kuma.nix | 8 +++- modules/vds/default.nix | 3 +- 16 files changed, 144 insertions(+), 183 deletions(-) delete mode 100644 modules/server/node-red.nix diff --git a/modules/server/calibre-web.nix b/modules/server/calibre-web.nix index 09b2bf9..0581c72 100644 --- a/modules/server/calibre-web.nix +++ b/modules/server/calibre-web.nix @@ -6,9 +6,12 @@ ... }: let - stable = import inputs.nixpkgs-previous { - system = "x86_64-linux"; - }; + # stable = import inputs.nixpkgs-previous { + # system = "x86_64-linux"; + # }; + libraryDir = "${xlib.dirs.services-mnt-folder}/calibre-web-library"; + sourceDir = "${xlib.dirs.services-mnt-folder}/calibre-web"; + targetDir = "/var/lib/calibre-web"; in { services = { @@ -17,7 +20,7 @@ in enable = true; # dataDir = "${xlib.dirs.services-mnt-folder}/calibre-web"; options = { - calibreLibrary = "${xlib.dirs.services-mnt-folder}/calibre-web-library"; + calibreLibrary = "${libraryDir}"; enableBookUploading = true; enableKepubify = true; enableBookConversion = false; @@ -40,13 +43,15 @@ in }; systemd.tmpfiles.rules = [ - "d ${xlib.dirs.services-mnt-folder}/calibre-web 0755 calibre-web calibre-web -" - "d ${xlib.dirs.services-mnt-folder}/calibre-web-library 0755 calibre-web calibre-web -" + "d ${libraryDir} 0755 calibre-web calibre-web -" + "d ${sourceDir} 0755 calibre-web calibre-web -" + "Z ${libraryDir} 0755 calibre-web calibre-web -" + "Z ${sourceDir} 0755 calibre-web calibre-web -" ]; fileSystems = { - "/var/lib/calibre-web" = { - device = "${xlib.dirs.services-mnt-folder}/calibre-web"; + "${targetDir}" = { + device = "${sourceDir}"; fsType = "none"; options = [ "bind" diff --git a/modules/server/default.nix b/modules/server/default.nix index 6d3f083..ba0f0e2 100644 --- a/modules/server/default.nix +++ b/modules/server/default.nix @@ -1,5 +1,6 @@ { lib, + xlib, ... }: { @@ -26,7 +27,7 @@ ./samba.nix ./syncthing.nix ./systemd.nix - # ./step-ca.nix + ./uptime-kuma.nix # ../containers/remnawave.nix # ./coturn.nix # ./mealie.nix @@ -34,13 +35,16 @@ # ./n8n.nix # ./netdata.nix # ./nfs.nix - # ./node-red.nix # ./open-webui.nix # ./rsync.nix + # ./step-ca.nix # ./stirling-pdf.nix # ./transmission.nix # ./trilium.nix - # ./uptime-kuma.nix # ./zerotier.nix ]; + systemd.tmpfiles.rules = [ + "d /mnt 0755 root root -" + "d ${xlib.dirs.services-mnt-folder} 0755 root root -" + ]; } diff --git a/modules/server/homebox.nix b/modules/server/homebox.nix index 32102b6..9d2cd7f 100644 --- a/modules/server/homebox.nix +++ b/modules/server/homebox.nix @@ -5,8 +5,8 @@ ... }: let - configDir = "${xlib.dirs.services-mnt-folder}/homebox"; - varDir = "/var/lib/homebox"; + sourceDir = "${xlib.dirs.services-mnt-folder}/homebox"; + targetDir = "/var/lib/homebox"; in { services.homebox = { @@ -14,31 +14,33 @@ in settings = { HBOX_WEB_HOST = "0.0.0.0"; HBOX_WEB_PORT = "7745"; - HBOX_STORAGE_CONN_STRING = "file://${varDir}"; + HBOX_STORAGE_CONN_STRING = "file://${targetDir}"; HBOX_STORAGE_PREFIX_PATH = "data"; HBOX_DATABASE_DRIVER = "sqlite3"; - HBOX_DATABASE_SQLITE_PATH = "${varDir}/data/homebox.db?_pragma=busy_timeout=999&_pragma=journal_mode=WAL&_fk=1"; + HBOX_DATABASE_SQLITE_PATH = "${targetDir}/data/homebox.db?_pragma=busy_timeout=999&_pragma=journal_mode=WAL&_fk=1"; HBOX_OPTIONS_ALLOW_REGISTRATION = "true"; HBOX_OPTIONS_GITHUB_RELEASE_CHECK = "false"; HBOX_MODE = "production"; - HOME = "${varDir}"; - TMPDIR = "${varDir}/tmp"; + HOME = "${targetDir}"; + TMPDIR = "${targetDir}/tmp"; }; }; - systemd.tmpfiles.rules = [ - "d ${configDir} 0755 homebox homebox -" - "z ${configDir} 0755 homebox homebox -" - ]; - - fileSystems = { - "${varDir}" = { - device = "${configDir}"; - fsType = "none"; - options = [ - "bind" - "nofail" - ]; - }; + systemd = { + tmpfiles.rules = [ + "d ${sourceDir} 0755 homebox homebox -" + "z ${sourceDir} 0755 homebox homebox -" + ]; + mounts = [ + { + enable = true; + options = "bind,x-systemd.automount,nofail"; + requires = [ "local-fs.target" ]; + type = "none"; + wantedBy = [ "multi-user.target" ]; + what = "${sourceDir}"; + where = "${targetDir}"; + } + ]; }; } diff --git a/modules/server/miniflux.nix b/modules/server/miniflux.nix index 67103cb..0792f9d 100644 --- a/modules/server/miniflux.nix +++ b/modules/server/miniflux.nix @@ -12,7 +12,6 @@ CLEANUP_FREQUENCY = 48; LISTEN_ADDR = "0.0.0.0:6061"; }; - # adminCredentialsFile = "${inputs.zeroq-credentials}/services/miniflux/admin-pass.txt"; adminCredentialsFile = config.sops.secrets.minifluxenv.path; }; diff --git a/modules/server/n8n.nix b/modules/server/n8n.nix index 5cb055f..757d5eb 100644 --- a/modules/server/n8n.nix +++ b/modules/server/n8n.nix @@ -7,31 +7,35 @@ ... }: let - configDir = "${xlib.dirs.services-mnt-folder}/n8n"; - varDir = "/var/lib/n8n"; + sourceDir = "${xlib.dirs.services-mnt-folder}/n8n"; + targetDir = "/var/lib/n8n"; in { services.n8n = { enable = false; environment = { - # N8N_USER_FOLDER = lib.mkForce "${configDir}"; + # N8N_USER_FOLDER = lib.mkForce "${sourceDir}"; N8N_SECURE_COOKIE = "false"; N8N_PORT = 5678; }; openFirewall = true; }; - systemd.tmpfiles.rules = [ - "d ${configDir} 0755 nobody nogroup -" - "z ${configDir} 0755 nobody nogroup -" - ]; - - fileSystems.${varDir} = { - device = "${configDir}"; - fsType = "none"; - options = [ - "bind" - "nofail" + systemd = { + tmpfiles.rules = [ + "d ${sourceDir} 0755 nobody nogroup -" + "z ${sourceDir} 0755 nobody nogroup -" + ]; + mounts = [ + { + enable = true; + options = "bind,x-systemd.automount,nofail"; + requires = [ "local-fs.target" ]; + type = "none"; + wantedBy = [ "multi-user.target" ]; + what = "${sourceDir}"; + where = "${targetDir}"; + } ]; }; } diff --git a/modules/server/navidrome.nix b/modules/server/navidrome.nix index aa1110a..e72f933 100644 --- a/modules/server/navidrome.nix +++ b/modules/server/navidrome.nix @@ -7,7 +7,8 @@ ... }: let - navidromeDir = "/var/lib/services/navidrome-point"; + pointDir = "/var/lib/services/navidrome-point"; + libraryDir = "${xlib.dirs.server-home}/Music"; in { services = { @@ -18,7 +19,7 @@ in settings = { Address = "0.0.0.0"; Port = 4533; - MusicFolder = "${navidromeDir}"; + MusicFolder = "${pointDir}"; }; }; }; @@ -29,8 +30,8 @@ in requires = [ "local-fs.target" ]; type = "none"; wantedBy = [ "multi-user.target" ]; - what = "${xlib.dirs.server-home}/Music"; - where = "${navidromeDir}"; + what = "${libraryDir}"; + where = "${pointDir}"; } ]; } diff --git a/modules/server/nginx.nix b/modules/server/nginx.nix index 7305405..6f1644a 100644 --- a/modules/server/nginx.nix +++ b/modules/server/nginx.nix @@ -86,47 +86,7 @@ in }; }; }; - # "pdf.home.arpa" = { - # forceSSL = true; - # enableACME = true; - # locations = { - # "/" = { - # proxyPass = "http://127.0.0.1:8446"; - # proxyWebsockets = true; - # }; - # }; - # extraConfig = '' - # client_max_body_size 5G; - # ''; - # }; - # "homebox.home.arpa" = { - # forceSSL = true; - # enableACME = true; - # locations = { - # "/" = { - # proxyPass = "http://127.0.0.1:7745"; - # proxyWebsockets = true; - # }; - # }; - # }; - # "nextcloud.home.arpa" = { - # forceSSL = true; - # enableACME = true; - # locations = { - # "/" = { - # proxyPass = "http://127.0.0.1:10000"; - # proxyWebsockets = true; - # }; - # "/whiteboard" = { - # proxyPass = "http://127.0.0.1:3002"; - # proxyWebsockets = true; - # }; - # }; - # extraConfig = '' - # client_max_body_size 5G; - # ''; - # }; - # "talk.home.arpa" = { + # "talk.zeroq.su" = { # forceSSL = true; # enableACME = true; # # locations = { @@ -139,7 +99,7 @@ in # client_max_body_size 5G; # ''; # }; - # "turn.home.arpa" = { + # "turn.zeroq.su" = { # forceSSL = true; # enableACME = true; # locations = { @@ -152,7 +112,7 @@ in # client_max_body_size 5G; # ''; # }; - # "ca.zeroq.su" = { + # "ca.home.arpa" = { # forceSSL = true; # enableACME = true; # locations."/" = { @@ -163,18 +123,7 @@ in # client_max_body_size 5G; # ''; # }; - # "git.home.arpa" = { - # forceSSL = true; - # enableACME = true; - # locations."/" = { - # proxyPass = "http://127.0.0.1:3000"; - # proxyWebsockets = true; - # }; - # extraConfig = '' - # client_max_body_size 5G; - # ''; - # }; - # "n8n.home.arpa" = { + # "n8n.zeroq.su" = { # forceSSL = true; # enableACME = true; # locations."/" = { @@ -339,14 +288,14 @@ in proxyWebsockets = true; }; }; - "n8n.zeroq.su" = { - forceSSL = true; - enableACME = true; - locations."/" = { - proxyPass = "http://${server}:5678"; - proxyWebsockets = true; - }; - }; + # "n8n.zeroq.su" = { + # forceSSL = true; + # enableACME = true; + # locations."/" = { + # proxyPass = "http://${server}:5678"; + # proxyWebsockets = true; + # }; + # }; # "office.zeroq.su" = { # enableACME = true; # forceSSL = true; diff --git a/modules/server/node-red.nix b/modules/server/node-red.nix deleted file mode 100644 index 4a4ddb8..0000000 --- a/modules/server/node-red.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ - config, - lib, - pkgs, - xlib, - inputs, - ... -}: -{ - services.node-red = { - enable = false; - port = 1880; - openFirewall = true; - userDir = "${xlib.dirs.services-mnt-folder}/node-red"; - configFile = "${inputs.zeroq-credentials}/configs/node-red/settings.js"; - }; - - systemd.tmpfiles.rules = [ - "z ${config.services.node-red.userDir} 0750 node-red node-red -" - ]; -} diff --git a/modules/server/onlyoffice.nix b/modules/server/onlyoffice.nix index 4e29817..ab33f29 100644 --- a/modules/server/onlyoffice.nix +++ b/modules/server/onlyoffice.nix @@ -7,11 +7,11 @@ ... }: let - previous = import inputs.nixpkgs-master { - system = "x86_64-linux"; - config.allowUnfree = true; - config.allowUnfreePredicate = true; - }; + # previous = import inputs.nixpkgs-master { + # system = "x86_64-linux"; + # config.allowUnfree = true; + # config.allowUnfreePredicate = true; + # }; in { services.onlyoffice = { diff --git a/modules/server/postgresql.nix b/modules/server/postgresql.nix index 4eb6517..303c3c9 100644 --- a/modules/server/postgresql.nix +++ b/modules/server/postgresql.nix @@ -6,27 +6,34 @@ xlib, ... }: +let + sourceDir = "${xlib.dirs.services-mnt-folder}/postgresql"; + targetDir = "/var/lib/postgresql"; +in { services = { postgresql = { enable = true; package = pkgs.postgresql_17; - # dataDir = "${xlib.dirs.services-mnt-folder}/postgresql"; }; # postgresqlBackup.enable = true; }; - fileSystems."/var/lib/postgresql" = { - device = "${xlib.dirs.services-mnt-folder}/postgresql"; - fsType = "none"; - options = [ - "bind" - "nofail" + systemd = { + tmpfiles.rules = [ + "d ${sourceDir} 0760 postgres postgres -" + "z ${sourceDir} 0760 postgres postgres -" + ]; + mounts = [ + { + enable = true; + options = "bind,x-systemd.automount,nofail"; + requires = [ "local-fs.target" ]; + type = "none"; + wantedBy = [ "multi-user.target" ]; + what = "${sourceDir}"; + where = "${targetDir}"; + } ]; }; - - systemd.tmpfiles.rules = [ - "z ${xlib.dirs.services-mnt-folder}/postgresql 0760 postgres postgres -" - # "z ${config.services.postgresql.dataDir} 0760 postgres postgres -" - ]; } diff --git a/modules/server/samba.nix b/modules/server/samba.nix index 58031fb..6490769 100644 --- a/modules/server/samba.nix +++ b/modules/server/samba.nix @@ -5,6 +5,10 @@ xlib, ... }: +let + sourceDir = "${xlib.dirs.services-mnt-folder}/samba"; + targetDir = "/var/lib/samba"; +in { services = { samba-wsdd = { @@ -65,19 +69,21 @@ }; }; - systemd.tmpfiles.rules = [ - "d ${xlib.dirs.services-mnt-folder}/samba 0755 root root -" - "z ${xlib.dirs.services-mnt-folder}/samba 0755 root root -" - ]; - - fileSystems = { - "/var/lib/samba" = { - device = "${xlib.dirs.services-mnt-folder}/samba"; - fsType = "none"; - options = [ - "bind" - "nofail" - ]; - }; + systemd = { + tmpfiles.rules = [ + "d ${sourceDir} 0755 root root -" + "z ${sourceDir} 0755 root root -" + ]; + mounts = [ + { + enable = true; + options = "bind,x-systemd.automount,nofail"; + requires = [ "local-fs.target" ]; + type = "none"; + wantedBy = [ "multi-user.target" ]; + what = "${sourceDir}"; + where = "${targetDir}"; + } + ]; }; } diff --git a/modules/server/step-ca.nix b/modules/server/step-ca.nix index 914d0b1..32fa68a 100644 --- a/modules/server/step-ca.nix +++ b/modules/server/step-ca.nix @@ -6,8 +6,8 @@ ... }: let - configDir = "${xlib.dirs.services-mnt-folder}/step-ca"; - varDir = "/var/lib/step-ca"; + sourceDir = "${xlib.dirs.services-mnt-folder}/step-ca"; + targetDir = "/var/lib/step-ca"; in { services.step-ca = { @@ -17,9 +17,9 @@ in openFirewall = true; intermediatePasswordFile = config.sops.secrets.intermediate-password.path; settings = { - root = "${varDir}/certs/root_ca.crt"; - crt = "${varDir}/certs/intermediate_ca.crt"; - key = "${varDir}/secrets/intermediate_ca_key"; + root = "${targetDir}/certs/root_ca.crt"; + crt = "${targetDir}/certs/intermediate_ca.crt"; + key = "${targetDir}/secrets/intermediate_ca_key"; # address = "0.0.0.0:9000"; dnsNames = [ "*.zeroq.su" @@ -28,7 +28,7 @@ in ]; db = { type = "badgerv2"; - dataSource = "${varDir}/db"; + dataSource = "${targetDir}/db"; }; authority = { claims = { @@ -69,8 +69,8 @@ in }; }; - fileSystems."${varDir}" = { - device = "${configDir}"; + fileSystems."${targetDir}" = { + device = "${sourceDir}"; fsType = "none"; options = [ "bind" @@ -85,9 +85,9 @@ in }; systemd.tmpfiles.rules = [ - "d ${configDir} 0755 nobody nogroup -" - "z ${configDir} 0755 nobody nogroup -" - "Z ${configDir}/ 0700 nobody nogroup -" + "d ${sourceDir} 0755 nobody nogroup -" + "z ${sourceDir} 0755 nobody nogroup -" + "Z ${sourceDir}/ 0700 nobody nogroup -" ]; sops.secrets = { diff --git a/modules/server/syncthing.nix b/modules/server/syncthing.nix index f4cec03..c8989e7 100644 --- a/modules/server/syncthing.nix +++ b/modules/server/syncthing.nix @@ -7,7 +7,6 @@ { services.syncthing = { enable = true; - # package = master.syncthing; systemService = true; guiAddress = "0.0.0.0:8384"; configDir = "${xlib.dirs.storage}/persist/Syncthing/${xlib.device.hostname}"; diff --git a/modules/server/trilium.nix b/modules/server/trilium.nix index 490ffea..0e7fdfc 100644 --- a/modules/server/trilium.nix +++ b/modules/server/trilium.nix @@ -3,6 +3,9 @@ xlib, ... }: +let + sourceDir = "${xlib.dirs.services-mnt-folder}/trilium"; +in { services.trilium-server = { enable = false; @@ -11,10 +14,10 @@ hostName = "trilium"; }; host = "0.0.0.0"; - dataDir = "/mnt/services/trilium"; + dataDir = "${sourceDir}"; }; systemd.tmpfiles.rules = [ - "z /mnt/services/trilium 0750 trilium trilium -" + "z ${sourceDir} 0750 trilium trilium -" ]; } diff --git a/modules/server/uptime-kuma.nix b/modules/server/uptime-kuma.nix index 3529318..2d2ec4d 100644 --- a/modules/server/uptime-kuma.nix +++ b/modules/server/uptime-kuma.nix @@ -6,9 +6,13 @@ inputs, ... }: +let + targetDir = "/var/lib/private/uptime-kuma"; + sourceDir = "${xlib.dirs.services-mnt-folder}/uptime-kuma"; +in { services.uptime-kuma = { - enable = false; + enable = true; settings = { PORT = "4001"; HOST = "0.0.0.0"; @@ -19,7 +23,7 @@ "z ${xlib.dirs.services-mnt-folder}/uptime-kuma 0755 nobody nogroup -" ]; - fileSystems."/var/lib/private/uptime-kuma" = { + fileSystems."${targetDir}" = { device = "${xlib.dirs.services-mnt-folder}/uptime-kuma"; fsType = "none"; options = [ diff --git a/modules/vds/default.nix b/modules/vds/default.nix index 7b76310..f2bf66e 100644 --- a/modules/vds/default.nix +++ b/modules/vds/default.nix @@ -14,7 +14,6 @@ ]; systemd.tmpfiles.rules = [ "d /mnt 0755 root root -" - "d /mnt/services 0755 root root -" - "d /mnt/services/containers 0755 root root -" + "d ${xlib.dirs.services-mnt-folder} 0755 root root -" ]; }