From d1741c60dc75880224b81fbd44ccd0b80a9cb9c1 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 5 Sep 2023 17:20:48 +0000 Subject: [PATCH] sxmo: clean up our hook injections --- hosts/by-name/moby/polyfill.nix | 10 +-- hosts/modules/gui/sxmo/default.nix | 51 ++++++----- .../modules/gui/sxmo/hooks/sxmo_hook_start.sh | 89 +++++++++++++++++++ 3 files changed, 122 insertions(+), 28 deletions(-) create mode 100755 hosts/modules/gui/sxmo/hooks/sxmo_hook_start.sh diff --git a/hosts/by-name/moby/polyfill.nix b/hosts/by-name/moby/polyfill.nix index 657041e4..38fc12a3 100644 --- a/hosts/by-name/moby/polyfill.nix +++ b/hosts/by-name/moby/polyfill.nix @@ -116,6 +116,8 @@ ]; DEFAULT_COUNTRY = "US"; + SXMO_AUTOROTATE = "1"; # enable auto-rotation at launch. has no meaning in stock/upstream sxmo-utils + # BEMENU lines (wayland DMENU): # - camera is 9th entry # - flashlight is 10th entry @@ -159,13 +161,5 @@ WVKBD_LANDSCAPE_LAYERS = "landscape,special,emoji"; WVKBD_LAYERS = "full,special,emoji"; }; - package = pkgs.sxmo-utils-latest.overrideAttrs (base: { - postPatch = (base.postPatch or "") + '' - cat <> ./configs/default_hooks/sxmo_hook_start.sh - # rotate UI based on physical display angle by default - sxmo_daemons.sh start autorotate sxmo_autorotate.sh - EOF - ''; - }); }; } diff --git a/hosts/modules/gui/sxmo/default.nix b/hosts/modules/gui/sxmo/default.nix index fefc7115..62dd49c8 100644 --- a/hosts/modules/gui/sxmo/default.nix +++ b/hosts/modules/gui/sxmo/default.nix @@ -46,13 +46,12 @@ # - on-screen keyboard: wvkbd (if wayland), svkbd (if X) # # TODO: -# - don't duplicate so much of hosts/modules/gui/sway -# - might help if i bring more under my control, and launch sxmo via sway instead of the opposite # - theme `mako` notifications { config, lib, pkgs, ... }: let cfg = config.sane.gui.sxmo; + package = cfg.package; knownKeyboards = { # map keyboard package name -> name of binary to invoke wvkbd = "wvkbd-mobintl"; @@ -67,14 +66,6 @@ let echo "launching ${identifier}..." | ${systemd-cat} --identifier=${identifier} ${cmd} 2>&1 | ${systemd-cat} --identifier=${identifier} ''; - - package = cfg.package.overrideAttrs (base: { - postPatch = (base.postPatch or "") + '' - # don't start conky via superd: i manage it myself - substituteInPlace ./configs/default_hooks/sxmo_hook_start.sh \ - --replace 'superctl start sxmo_conky' "" - ''; - }); in { options = with lib; { @@ -112,6 +103,15 @@ in to insert your own user scripts. ''; }; + sane.gui.sxmo.hooks = mkOption { + type = types.attrsOf types.path; + default = { + "sxmo_hook_init.sh" = ./hooks/sxmo_hook_init.sh; + }; + description = '' + extra hooks to add with higher priority than the builtins + ''; + }; sane.gui.sxmo.terminal = mkOption { # type = types.nullOr (types.enum [ "foot" "st" "vte" ]); type = types.nullOr types.str; @@ -339,16 +339,27 @@ in }; }; - sane.user.fs.".cache/sxmo/sxmo.noidle" = lib.mkIf cfg.noidle { - symlink.text = ""; - }; - sane.user.fs.".cache/sxmo/sxmo.nogesture" = lib.mkIf cfg.nogesture { - symlink.text = ""; - }; - sane.user.fs.".config/sxmo/profile".symlink.text = let - mkKeyValue = key: value: ''export ${key}="${value}"''; - in - lib.generators.toKeyValue { inherit mkKeyValue; } cfg.settings; + sane.user.fs = lib.mkMerge [ + { + ".cache/sxmo/sxmo.noidle" = lib.mkIf cfg.noidle { + symlink.text = ""; + }; + ".cache/sxmo/sxmo.nogesture" = lib.mkIf cfg.nogesture { + symlink.text = ""; + }; + ".config/sxmo/profile".symlink.text = let + mkKeyValue = key: value: ''export ${key}="${value}"''; + in + lib.generators.toKeyValue { inherit mkKeyValue; } cfg.settings; + } + (lib.mapAttrs' (name: value: { + # sxmo's `_sxmo_load_environments` adds to PATH: + # - ~/.config/sxmo/hooks/$SXMO_DEVICE_NAME + # - ~/.config/sxmo/hooks + name = ".config/sxmo/hooks/${name}"; + value.symlink.target = value; + }) cfg.hooks) + ]; } (lib.mkIf (cfg.greeter == "lightdm-mobile") { diff --git a/hosts/modules/gui/sxmo/hooks/sxmo_hook_start.sh b/hosts/modules/gui/sxmo/hooks/sxmo_hook_start.sh new file mode 100755 index 00000000..d91d2919 --- /dev/null +++ b/hosts/modules/gui/sxmo/hooks/sxmo_hook_start.sh @@ -0,0 +1,89 @@ +#!/bin/sh +# this is based on upstream sxmo-utils sxmo_hook_start.sh +# but modified for nixos integration and specialize a bit to my needs +. sxmo_common.sh + +# Create xdg user directories, such as ~/Pictures +xdg-user-dirs-update + +sxmo_daemons.sh start daemon_manager superd + +# let time to superd to start correctly +while ! superctl status > /dev/null 2>&1; do + sleep 0.5 +done + +# Periodically update some status bar components +sxmo_hook_statusbar.sh all +sxmo_daemons.sh start statusbar_periodics sxmo_run_aligned.sh 60 \ + sxmo_hook_statusbar.sh periodics + +superctl start mako +superctl start sxmo_wob +superctl start sxmo_menumode_toggler +superctl start bonsaid +# don't: sway background is managed externally +# swaymsg output '*' bg "$SXMO_BG_IMG" fill + +# To setup initial lock state +sxmo_hook_unlock.sh + +# Turn on auto-suspend +if [ -w "/sys/power/wakeup_count" ] && [ -f "/sys/power/wake_lock" ]; then + superctl start sxmo_autosuspend +fi + +# Turn on lisgd +if [ ! -e "$XDG_CACHE_HOME"/sxmo/sxmo.nogesture ]; then + superctl start sxmo_hook_lisgd +fi + +if [ "$(command -v ModemManager)" ]; then + # Turn on the dbus-monitors for modem-related tasks + superctl start sxmo_modemmonitor + + # place a wakelock for 120s to allow the modem to fully warm up (eg25 + + # elogind/systemd would do this for us, but we don't use those.) + sxmo_wakelock.sh lock sxmo_modem_warming_up 120s +fi + +# don't: conky is managed externally +# superctl start sxmo_conky + +# Monitor the battery +superctl start sxmo_battery_monitor + +# It watch network changes and update the status bar icon by example +superctl start sxmo_networkmonitor + +# The daemon that display notifications popup messages +superctl start sxmo_notificationmonitor + +# monitor for headphone for statusbar +superctl start sxmo_soundmonitor + +# rotate UI based on physical display angle by default +if [ -n "$SXMO_AUTOROTATE" ]; then + sxmo_daemons.sh start autorotate sxmo_autorotate.sh +fi + +# Play a funky startup tune if you want (disabled by default) +#mpv --quiet --no-video ~/welcome.ogg & + +# mmsd and vvmd +if [ -f "${SXMO_MMS_BASE_DIR:-"$HOME"/.mms/modemmanager}/mms" ]; then + superctl start mmsd-tng +fi + +if [ -f "${SXMO_VVM_BASE_DIR:-"$HOME"/.vvm/modemmanager}/vvm" ]; then + superctl start vvmd +fi + +# add some warnings if things are not setup correctly +if ! command -v "sxmo_deviceprofile_$SXMO_DEVICE_NAME.sh"; then + sxmo_notify_user.sh --urgency=critical \ + "No deviceprofile found $SXMO_DEVICE_NAME. See: https://sxmo.org/deviceprofile" +fi + +sxmo_migrate.sh state || sxmo_notify_user.sh --urgency=critical \ + "Config needs migration" "$? file(s) in your sxmo configuration are out of date and disabled - using defaults until you migrate (run sxmo_migrate.sh)"