diff --git a/hosts/web-2/configuration.nix b/hosts/web-2/configuration.nix index 5a7d560..74772a5 100644 --- a/hosts/web-2/configuration.nix +++ b/hosts/web-2/configuration.nix @@ -14,6 +14,7 @@ ./public.nix ./radicale.nix ./reichartstrasse.nix + ./wetter.nix ./znc.nix ]; diff --git a/hosts/web-2/wetter.nix b/hosts/web-2/wetter.nix new file mode 100644 index 0000000..19a5335 --- /dev/null +++ b/hosts/web-2/wetter.nix @@ -0,0 +1,79 @@ +{ pkgs, ... }: + +let + configFile = pkgs.writeText "wetter.cfg" '' + SQLALCHEMY_DATABASE_URI="postgresql://wetter_web@/wetter?host=/run/postgresql" + ''; + +in { + users.users.wetter = { + description = "Wetter Service"; + group = "wetter"; + home = "/var/lib/wetter/"; + useDefaultShell = true; + isSystemUser = true; + }; + users.groups.wetter = {}; + + users.users.wetter_web = { + description = "Wetter Web Service"; + group = "wetter_web"; + home = "/var/lib/wetter/"; + useDefaultShell = true; + isSystemUser = true; + }; + users.groups.wetter_web = {}; + + services.postgresql = { + ensureDatabases = [ "wetter" ]; + ensureUsers = [ + { + name = "wetter"; + ensurePermissions = { + "DATABASE wetter" = "ALL PRIVILEGES"; + }; + } + { + name = "wetter_scraper"; + ensurePermissions = { + "DATABASE wetter" = "CONNECT"; + "SCHEMA public" = "USAGE"; + "ALL TABLES IN SCHEMA public" = "ALL PRIVILEGES"; + }; + } + { + name = "wetter_web"; + ensurePermissions = { + "DATABASE wetter" = "CONNECT"; + "SCHEMA public" = "USAGE"; + "ALL TABLES IN SCHEMA public" = "SELECT"; + }; + } + ]; + }; + + systemd.services.wetter = { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + RuntimeDirectory = "wetter"; + StateDirectory = "wetter"; + User = "wetter_web"; + Group = "wetter_web"; + }; + environment = { + WETTER_SETTINGS = "${configFile}"; + }; + script = "gunicorn -w 4 -b [::1]:8234 wetter:app"; + path = with pkgs; [ (python38.withPackages (ps: [ ps.gunicorn wetter ])) ]; + }; + + services.nginx.virtualHosts = { + "wetter.clerie.de" = { + enableACME = true; + forceSSL = true; + locations."/" = { + proxyPass = "http://[::1]:8234"; + }; + }; + }; +}