summaryrefslogtreecommitdiff
path: root/Omni/Cloud/OpenWebui.nix
blob: fc662c2e7a2373c08eaf91e7e53d919204f910d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{
  config,
  pkgs,
  ...
}: let
  ports = import ./Ports.nix;
in {
  config.virtualisation.oci-containers.backend = "docker";

  config.virtualisation.oci-containers.containers.open-webui-aichat = {
    image = "ghcr.io/open-webui/open-webui:main";
    volumes = ["/var/lib/open-webui-aichat:/app/backend/data"];
    environment = {
      PORT = toString ports.open-webui-aichat;
    };
    extraOptions = ["--network=host"];
  };

  # Add a service that updates and restarts the container
  config.systemd.services."update-open-webui-aichat" = {
    description = "pulling new open-webui image and restarting the service";
    wantedBy = ["multi-user.target"];
    after = ["network-online.target"];
    serviceConfig = {
      Type = "oneshot";
      ExecStart = [
        # Pull the latest image
        "${pkgs.docker}/bin/docker pull ghcr.io/open-webui/open-webui:main"
        # Restart the container
        "${pkgs.systemd}/bin/systemctl stop docker-open-webui-aichat"
        "${pkgs.systemd}/bin/systemctl start docker-open-webui-aichat"
      ];
    };
  };

  # Add a timer that runs every Sunday at 3 AM
  config.systemd.timers."update-open-webui-aichat" = {
    wantedBy = ["timers.target"];
    timerConfig.OnCalendar = "Sun 03:00:00";
    timerConfig.Persistent = true;
    unitConfig.Description = "Weekly timer for pulling new open-webui image and restarting service.";
  };
}