From e89805cd17f7233d70a5ed85d0ed562432531c1d Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 4 Sep 2023 11:10:30 +0000 Subject: [PATCH] sxmo: have sway launch sxmo -- not the other way around this lets me treat sxmo as just some nice scripts which run atop an existing DE (sway), rather than the opposite can share more code with my desktop/laptop --- hosts/by-name/lappy/polyfill.nix | 3 + hosts/modules/gui/sway/default.nix | 28 +++++--- hosts/modules/gui/sxmo/default.nix | 110 ++++++++++++++--------------- hosts/modules/gui/sxmo/sway-config | 12 ++-- 4 files changed, 83 insertions(+), 70 deletions(-) diff --git a/hosts/by-name/lappy/polyfill.nix b/hosts/by-name/lappy/polyfill.nix index 06534dae..24b7c851 100644 --- a/hosts/by-name/lappy/polyfill.nix +++ b/hosts/by-name/lappy/polyfill.nix @@ -27,6 +27,9 @@ # - SXMO_SWAY_SCALE # see # SXMO_DEVICE_NAME = "pine64,pinephone-1.2"; + # if sxmo doesn't know the device, it can't decide whether to use one_button or three_button mode + # and so it just wouldn't handle any button inputs (sxmo_hook_inputhandler.sh not on path) + SXMO_DEVICE_NAME = "three_button_touchscreen"; }; package = pkgs.sxmo-utils-latest.overrideAttrs (base: { postPatch = (base.postPatch or "") + '' diff --git a/hosts/modules/gui/sway/default.nix b/hosts/modules/gui/sway/default.nix index df2c4e3d..79641714 100644 --- a/hosts/modules/gui/sway/default.nix +++ b/hosts/modules/gui/sway/default.nix @@ -19,6 +19,13 @@ in default = true; type = types.bool; }; + sane.gui.sway.installConfigs = mkOption { + default = true; + type = types.bool; + description = '' + populate ~/.config/sway/config & co with defaults provided by this module. + ''; + }; }; config = lib.mkMerge [ @@ -69,6 +76,7 @@ in enable = true; alsa.enable = true; alsa.support32Bit = true; # ?? + # emulate pulseaudio for legacy apps (e.g. sxmo-utils) pulse.enable = true; }; @@ -123,17 +131,19 @@ in }) ]; - sane.user.fs.".config/sway/config".symlink.text = - import ./sway-config.nix { inherit pkgs; }; + sane.user.fs = lib.mkIf cfg.installConfigs { + ".config/sway/config".symlink.text = + import ./sway-config.nix { inherit pkgs; }; - sane.user.fs.".config/waybar/config".symlink.target = - let - waybar-config = import ./waybar-config.nix { inherit pkgs; }; - in - (pkgs.formats.json {}).generate "waybar-config.json" waybar-config; + ".config/waybar/config".symlink.target = + let + waybar-config = import ./waybar-config.nix { inherit pkgs; }; + in + (pkgs.formats.json {}).generate "waybar-config.json" waybar-config; - sane.user.fs.".config/waybar/style.css".symlink.text = - builtins.readFile ./waybar-style.css; + ".config/waybar/style.css".symlink.text = + builtins.readFile ./waybar-style.css; + }; }) ]; } diff --git a/hosts/modules/gui/sxmo/default.nix b/hosts/modules/gui/sxmo/default.nix index fd1919cb..7b5bbf10 100644 --- a/hosts/modules/gui/sxmo/default.nix +++ b/hosts/modules/gui/sxmo/default.nix @@ -140,6 +140,7 @@ in SXMO_BAR_SHOW_BAT_PER = mkSettingsOpt "1" "show battery percentage in statusbar"; SXMO_DISABLE_CONFIGVERSION_CHECK = mkSettingsOpt "1" "allow omitting the configversion line from user-provided sxmo dotfiles"; SXMO_UNLOCK_IDLE_TIME = mkSettingsOpt "300" "how many seconds of inactivity before locking the screen"; # lock -> screenoff happens 8s later, not configurable + # SXMO_WM = mkSettingsOpt "sway" "sway or dwm. ordinarily initialized by sxmo_{x,w}init.sh"; }; }; default = {}; @@ -186,21 +187,19 @@ in (lib.mkIf cfg.enable (lib.mkMerge [ { + sane.gui.sway = { + enable = true; + # we manage these ourselves (TODO: merge these into sway config as well) + useGreeter = false; + installConfigs = false; + }; + sane.programs.sxmoApps.enableFor.user.colin = true; - sane.gui.gtk.enable = lib.mkDefault true; # sxmo internally uses doas instead of sudo security.doas.enable = true; security.doas.wheelNeedsPassword = false; - # TODO: move this further to the host-specific config? - networking.useDHCP = false; - networking.networkmanager.enable = true; - networking.wireless.enable = lib.mkForce false; - - hardware.bluetooth.enable = true; - services.blueman.enable = true; - hardware.opengl.enable = true; # TODO: nerdfonts is 4GB. it accepts an option to ship only some fonts: probably want to use that. @@ -209,54 +208,11 @@ in # lightdm-mobile-greeter: "The name org.a11y.Bus was not provided by any .service files" services.gnome.at-spi2-core.enable = true; - # sxmo has first-class support only for pulseaudio and alsa -- not pipewire. - # however, pipewire can emulate pulseaudio support via `services.pipewire.pulse.enable = true` - # after which the stock pulseaudio binaries magically work - # administer with pw-cli, pw-mon, pw-top commands - services.pipewire = { - enable = true; - alsa.enable = true; - alsa.support32Bit = true; # ?? - pulse.enable = true; - }; - systemd.user.services."pipewire".wantedBy = [ "graphical-session.target" ]; - - programs.sway = { - # provides xdg-desktop-portal-wlr, which exposes on dbus: - # - org.freedesktop.impl.portal.ScreenCast - # - org.freedesktop.impl.portal.Screenshot - enable = true; - extraPackages = []; # nixos adds swaylock, swayidle, foot, dmenu by default - # "wrapGAppsHook wrapper to execute sway with required environment variables for GTK applications." - wrapperFeatures.gtk = true; - }; - # provide portals for: - # - org.freedesktop.impl.portal.Access - # - org.freedesktop.impl.portal.Account - # - org.freedesktop.impl.portal.DynamicLauncher - # - org.freedesktop.impl.portal.Email - # - org.freedesktop.impl.portal.FileChooser - # - org.freedesktop.impl.portal.Inhibit - # - org.freedesktop.impl.portal.Notification - # - org.freedesktop.impl.portal.Print - # and conditionally (i.e. unless buildPortalsInGnome = false) for: - # - org.freedesktop.impl.portal.AppChooser (@appchooser_iface@) - # - org.freedesktop.impl.portal.Background (@background_iface@) - # - org.freedesktop.impl.portal.Lockdown (@lockdown_iface@) - # - org.freedesktop.impl.portal.RemoteDesktop (@remotedesktop_iface@) - # - org.freedesktop.impl.portal.ScreenCast (@screencast_iface@) - # - org.freedesktop.impl.portal.Screenshot (@screenshot_iface@) - # - org.freedesktop.impl.portal.Settings (@settings_iface@) - # - org.freedesktop.impl.portal.Wallpaper (@wallpaper_iface@) - xdg.portal.extraPortals = [ - (pkgs.xdg-desktop-portal-gtk.override { - buildPortalsInGnome = false; - }) - ]; # TODO: could use `displayManager.sessionPackages`? environment.systemPackages = [ cfg.package + pkgs.bonsai # sway (not sxmo) needs to exec `bonsaictl` by name (sxmo_swayinitconf.sh) ] ++ lib.optionals (cfg.terminal != null) [ pkgs."${cfg.terminal}" ] ++ lib.optionals (cfg.keyboard != null) [ pkgs."${cfg.keyboard}" ]; @@ -270,13 +226,20 @@ in cfg.settings ); + # sxmo puts in /share/sxmo: + # - profile.d/sxmo_init.sh + # - appcfg/ + # - default_hooks/ + # - and more + # environment.pathsToLink = [ "/share/sxmo" ]; + systemd.services."sxmo-set-permissions" = { description = "configure specific /sys and /dev nodes to be writable by sxmo scripts"; serviceConfig = { Type = "oneshot"; ExecStart = "${cfg.package}/bin/sxmo_setpermissions.sh"; }; - wantedBy = [ "display-manager.service" ]; + wantedBy = [ "multi-user.service" ]; }; # if superd fails to start a service within 100ms, it'll try to start again @@ -315,9 +278,40 @@ in in lib.generators.toKeyValue { inherit mkKeyValue; } cfg.settings; - sane.user.fs.".config/sxmo/sway".symlink.target = pkgs.substituteAll { + sane.user.fs.".config/sway/config".symlink.target = pkgs.substituteAll { src = ./sway-config; waybar = "${pkgs.waybar}/bin/waybar"; + bemenu_run = "${pkgs.bemenu}/bin/bemenu-run"; + term = "${pkgs.xdg-terminal-exec}/bin/xdg-terminal-exec"; + sxmo_init = pkgs.writeShellScript "sxmo_init.sh" '' + # perform the same behavior as sxmo_{x,w}init.sh -- but without actually launching wayland/X11 + # this amounts to: + # - setting env vars (e.g. getting the hooks onto PATH) + # - placing default configs in ~ for sxmo-launched services (sxmo_migrate.sh) + # - launching sxmo_hook_start.sh + source ${cfg.package}/etc/profile.d/sxmo_init.sh + # XXX: upstream sources `profile` later (after sxmo_migrate) + # but _sxmo_load_environments uses `SXMO_DEVICE_NAME`, + # and i ship that via the profile, so order it such + source "$XDG_CONFIG_HOME/sxmo/profile" + _sxmo_load_environments + _sxmo_prepare_dirs + sxmo_migrate.sh sync + + # kill anything leftover from the previous sxmo run. this way we can (try to) be reentrant + echo "sxmo_init: killing stale daemons (if active)" + sxmo_daemons.sh stop all + pkill bemenu + pkill wvkbd + pkill superd + + # configure vol/power-button input mapping (upstream SXMO has this in sway config) + sxmo_swayinitconf.sh + + echo "sxmo_init: invoking sxmo_hook_start.sh with:" + echo "PATH: $PATH" + sxmo_hook_start.sh + ''; }; sane.user.fs.".config/waybar/config".symlink.target = @@ -378,7 +372,8 @@ in sway.enable = true; sway.gtkgreet.enable = true; sway.gtkgreet.session.name = "sxmo-on-gtkgreet"; - sway.gtkgreet.session.command = "${cfg.package}/bin/sxmo_winit.sh"; + # sway.gtkgreet.session.command = "${cfg.package}/bin/sxmo_winit.sh"; + sway.gtkgreet.session.command = "${pkgs.sway}/bin/sway --debug"; }; }) @@ -406,7 +401,8 @@ in sane.gui.greetd = { enable = true; session.name = "sxmo"; - session.command = "${cfg.package}/bin/sxmo_winit.sh"; + # session.command = "${cfg.package}/bin/sxmo_winit.sh"; + session.command = "${pkgs.sway}/bin/sway --debug"; session.user = "colin"; }; }) diff --git a/hosts/modules/gui/sxmo/sway-config b/hosts/modules/gui/sxmo/sway-config index 6fa4c94c..48b8a733 100644 --- a/hosts/modules/gui/sxmo/sway-config +++ b/hosts/modules/gui/sxmo/sway-config @@ -14,11 +14,13 @@ set $down j set $up k set $right l # Your preferred terminal emulator -set $term sxmo_terminal.sh +# set $term sxmo_terminal.sh +set $term @term@ # Your preferred application launcher # Note: pass the final command to swaymsg so that the resulting window can be opened # on the original workspace that the command was run on. -set $menu bemenu-run +# N.B. bemenu-run relies on BEMENU_OPTS being set: without this it won't even be visible. +set $menu @bemenu_run@ # xwayland enable|disable|force # - enable: lazily launch xwayland on first client connection @@ -29,7 +31,9 @@ xwayland disable font "Sxmo 10" -exec_always sxmo_swayinitconf.sh +# configure vol/power-button input maps +# XXX: this references env vars like SXMO_VOLUME_BUTTON => needs to happen after sourcing profile +# exec_always sxmo_swayinitconf.sh exec_always dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP @@ -263,4 +267,4 @@ include /etc/sway/config.d/* exec 'printf %s "$SWAYSOCK" > "$XDG_RUNTIME_DIR"/sxmo.swaysock' -exec sxmo_hook_start.sh +exec_always @sxmo_init@