more webapp stuff

This commit is contained in:
atagen 2024-05-02 13:55:15 +10:00
parent 9bc61077d5
commit 533f88f4cd
4 changed files with 34 additions and 15 deletions

View file

@ -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.";
};
};