diff --git a/home/bolt.nix b/home/bolt.nix index 57b6ae0..200ffd9 100644 --- a/home/bolt.nix +++ b/home/bolt.nix @@ -21,7 +21,8 @@ localWebApps = { stable-diffusion = { - name = "ComfyUI (Stable Diffusion)"; + name = "Stable Diffusion (ComfyUI)"; + genericName = "Stable Diffusion"; icon = ./icons/comfyui.png; id = 5; port = 7860; @@ -32,7 +33,8 @@ }; openwebui = rec { - name = "OpenWebUI (Ollama)"; + name = "Ollama (OpenWebUI)"; + genericName = "Ollama"; icon = ./icons/openwebui.png; id = 6; port = 3021; @@ -40,9 +42,17 @@ docker = lib.getExe pkgs.docker; in { Type = "exec"; - ExecStartPre = "-${docker} create -e PORT=${builtins.toString port} --network host --gpus all -v ollama:/root/.ollama -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:ollama"; - ExecStart = "${docker} start open-webui"; - ExecStop = "${docker} stop open-webui"; + ExecStartPre = "${pkgs.writeShellScript "openwebui-check" '' + set -euo pipefail + echo Checking for container existence.. + if [[ $(${docker} inspect openwebui &> /dev/null; printf $?) -ne 0 ]]; then + echo Not found. Creating OpenWebUI/Ollama container.. + ${docker} create -e PORT=${builtins.toString port} --network host --gpus all -v ollama:/root/.ollama -v open-webui:/app/backend/data --name openwebui --restart always ghcr.io/open-webui/open-webui:ollama + fi + echo Check complete. + ''}"; + ExecStart = "${docker} start -a openwebui"; + ExecStop = "${docker} stop openwebui"; }; }; }; diff --git a/home/home.nix b/home/home.nix index c425497..7ea523c 100644 --- a/home/home.nix +++ b/home/home.nix @@ -128,12 +128,12 @@ in { name = "Facebook Messenger"; icon = ./icons/fb_msg.png; }; - "ChatGPT" = { - url = "https://chat.openai.com"; + "Syncthing" = { + url = "http://127.0.0.1:8384"; id = 3; extraSettings = config.programs.firefox.profiles.default.settings; - name = "ChatGPT"; - icon = ./icons/ChatGPT.png; + name = "Syncthing"; + icon = ./icons/syncthing.png; }; "StudyTAFE" = { url = "https://www.studytafensw.edu.au"; diff --git a/home/icons/syncthing.png b/home/icons/syncthing.png new file mode 100644 index 0000000..cce2b8e Binary files /dev/null and b/home/icons/syncthing.png differ diff --git a/home/util/local-webapp.nix b/home/util/local-webapp.nix index cb597ad..53ce9c0 100644 --- a/home/util/local-webapp.nix +++ b/home/util/local-webapp.nix @@ -6,6 +6,7 @@ }: let inherit (lib) mkOption; inherit (lib.attrsets) mapAttrs mapAttrs' nameValuePair; + # make a firefox webapp entry for the client app make-firefox = cfg: mapAttrs' ( name: cfg: @@ -18,6 +19,7 @@ } ) cfg; + # make a systemd service for running the backend make-systemd = cfg: mapAttrs ( name: cfg: { @@ -26,12 +28,12 @@ } ) cfg; + # make desktop shortcuts and a script which will handle starting both the above make-xdg = cfg: mapAttrs ( name: cfg: { - name = cfg.name; + inherit (cfg) name icon genericName; type = "Application"; - icon = cfg.icon; exec = "${let notify-send = "${lib.getExe' pkgs.libnotify "notify-send"} -a \"${cfg.name}\""; systemctl = "${lib.getExe' pkgs.systemd "systemctl"}"; @@ -40,13 +42,14 @@ in pkgs.writeShellScript "${name}" '' + set -euo pipefail ${notify-send} "Launching backend.." "Please be patient." ${systemctl} --user start ${name} attempts=0 success=false while [[ $attempts -lt $((20*9)) ]]; do - if [[ $(${curl} http://127.0.0.1:${builtins.toString cfg.port}) ]]; then + if [[ $(${curl} -sf http://127.0.0.1:${builtins.toString cfg.port} --output /dev/null; printf $?) -eq 0 ]]; then ${notify-send} "Backend up." "Launching client.." success=true break @@ -85,10 +88,16 @@ in { description = "Display name of the webapp."; }; + genericName = mkOption { + type = nullOr str; + description = "Generic name of the webapp."; + default = null; + }; + icon = mkOption { - type = either str path; + type = nullOr (either str path); description = "Path to a file to use for application icon."; - default = ""; + default = null; }; id = mkOption { @@ -102,7 +111,7 @@ in { }; service = mkOption { - type = attrsOf string; + type = attrsOf str; description = "The service settings for systemd user service. Requires at least ExecStart."; }; };