From c8aa6a057f42fc5d1d95a12f568af3b203e6896e Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 19 May 2023 10:18:26 +0000 Subject: [PATCH] sxmo: make configurable if it launches on sway v.s. lightdm-mobile-greeter --- hosts/by-name/lappy/polyfill.nix | 49 +++++++------ hosts/modules/gui/sxmo.nix | 116 ++++++++++++++++++++++--------- 2 files changed, 109 insertions(+), 56 deletions(-) diff --git a/hosts/by-name/lappy/polyfill.nix b/hosts/by-name/lappy/polyfill.nix index c0164be3..914fbd6c 100644 --- a/hosts/by-name/lappy/polyfill.nix +++ b/hosts/by-name/lappy/polyfill.nix @@ -2,28 +2,31 @@ # but sets up any modules such that if they *were* enabled, they'll act as expected. { ... }: { - sane.gui.sxmo.settings = { - # XXX: make sure the user is part of the `input` group! - SXMO_LISGD_INPUT_DEVICE = "/dev/input/by-id/usb-Wacom_Co._Ltd._Pen_and_multitouch_sensor-event-if00"; - # these identifiers are from `swaymsg -t get_inputs` - SXMO_VOLUME_BUTTON = "1:1:AT_Translated_Set_2_keyboard"; - # SXMO_VOLUME_BUTTON = "none"; - SXMO_POWER_BUTTON = "0:1:Power_Button"; - # SXMO_POWER_BUTTON = "none"; - SXMO_DISABLE_LEDS = "1"; - SXMO_UNLOCK_IDLE_TIME = "120"; # default - # sxmo tries to determine device type from /proc/device-tree/compatible, - # but that doesn't seem to exist on NixOS? (or maybe it just doesn't exist - # on non-aarch64 builds). - # the device type informs (at least): - # - SXMO_WIFI_MODULE - # - SXMO_RTW_SCAN_INTERVAL - # - SXMO_SYS_FILES - # - SXMO_TOUCHSCREEN_ID - # - SXMO_MONITOR - # - SXMO_ALSA_CONTROL_NAME - # - SXMO_SWAY_SCALE - # see - # SXMO_DEVICE_NAME = "pine64,pinephone-1.2"; + sane.gui.sxmo = { + greeter = "sway"; + settings = { + # XXX: make sure the user is part of the `input` group! + SXMO_LISGD_INPUT_DEVICE = "/dev/input/by-id/usb-Wacom_Co._Ltd._Pen_and_multitouch_sensor-event-if00"; + # these identifiers are from `swaymsg -t get_inputs` + SXMO_VOLUME_BUTTON = "1:1:AT_Translated_Set_2_keyboard"; + # SXMO_VOLUME_BUTTON = "none"; + SXMO_POWER_BUTTON = "0:1:Power_Button"; + # SXMO_POWER_BUTTON = "none"; + SXMO_DISABLE_LEDS = "1"; + SXMO_UNLOCK_IDLE_TIME = "120"; # default + # sxmo tries to determine device type from /proc/device-tree/compatible, + # but that doesn't seem to exist on NixOS? (or maybe it just doesn't exist + # on non-aarch64 builds). + # the device type informs (at least): + # - SXMO_WIFI_MODULE + # - SXMO_RTW_SCAN_INTERVAL + # - SXMO_SYS_FILES + # - SXMO_TOUCHSCREEN_ID + # - SXMO_MONITOR + # - SXMO_ALSA_CONTROL_NAME + # - SXMO_SWAY_SCALE + # see + # SXMO_DEVICE_NAME = "pine64,pinephone-1.2"; + }; }; } diff --git a/hosts/modules/gui/sxmo.nix b/hosts/modules/gui/sxmo.nix index ce051a55..43a75b0f 100644 --- a/hosts/modules/gui/sxmo.nix +++ b/hosts/modules/gui/sxmo.nix @@ -45,16 +45,24 @@ # { lib, config, pkgs, sane-lib, ... }: -with lib; let cfg = config.sane.gui.sxmo; in { - options = { + options = with lib; { sane.gui.sxmo.enable = mkOption { default = false; type = types.bool; }; + sane.gui.sxmo.greeter = mkOption { + type = types.enum [ "lightdm-mobile" "sway" ]; + default = "lightdm-mobile"; + description = '' + which greeter to use. + "lightdm-mobile" => keypad style greeter. can only enter digits 0-9 as password. + "sway" => layered sway greeter. behaves as if you booted to swaylock. + ''; + }; sane.gui.sxmo.hooks = mkOption { type = types.package; default = pkgs.runCommand "sxmo-hooks" { } '' @@ -67,7 +75,7 @@ in which is called by sxmo at key moments to proide user programmability. ''; }; - sane.gui.sxmo.deviceHooks.package = mkOption { + sane.gui.sxmo.deviceHooks = mkOption { type = types.package; default = pkgs.runCommand "sxmo-device-hooks" { } '' mkdir -p $out @@ -99,7 +107,7 @@ in }; }; - config = mkMerge [ + config = lib.mkMerge [ { sane.programs.sxmoApps = { package = null; @@ -109,7 +117,7 @@ in }; } - (mkIf cfg.enable { + (lib.mkIf cfg.enable { sane.programs.sxmoApps.enableFor.user.colin = true; # TODO: probably need to enable pipewire @@ -125,34 +133,6 @@ in security.doas.enable = true; security.doas.wheelNeedsPassword = false; - # services.xserver.windowManager.session = [{ - # name = "sxmo"; - # desktopNames = [ "sxmo" ]; - # start = '' - # ${pkgs.sxmo-utils}/bin/sxmo_xinit.sh & - # waitPID=$! - # ''; - # }]; - # services.xserver.enable = true; - - # services.greetd = { - # enable = true; - # settings = { - # default_session = { - # command = "${pkgs.sxmo-utils}/bin/sxmo_winit.sh"; - # user = "colin"; - # }; - # }; - # }; - - services.xserver.enable = true; - services.xserver.displayManager.lightdm.enable = true; - services.xserver.displayManager.lightdm.greeters.gtk.enable = true; - services.xserver.displayManager.lightdm.extraSeatDefaults = '' - user-session = swmo - ''; - services.xserver.displayManager.sessionPackages = [ pkgs.sxmo-utils ]; - # TODO: not all of these fonts seem to be mapped to the correct icon fonts.fonts = [ pkgs.nerdfonts ]; @@ -166,6 +146,7 @@ in }; systemd.user.services."pipewire".wantedBy = [ "graphical-session.target" ]; + # TODO: could use `displayManager.sessionPackages`? environment.systemPackages = with pkgs; [ bc bemenu @@ -201,6 +182,75 @@ in } // cfg.settings; sane.user.fs.".cache/sxmo/sxmo.noidle" = sane-lib.fs.wantedText ""; + + + ## greeter + + services.xserver = lib.mkIf (cfg.greeter == "lightdm-mobile") { + enable = true; + + displayManager.lightdm.enable = true; + displayManager.lightdm.greeters.mobile.enable = true; + displayManager.lightdm.extraSeatDefaults = '' + user-session = swmo + ''; + + # taken from gui/phosh: + # NB: setting defaultSession has the critical side-effect that it lets org.freedesktop.AccountsService + # know that our user exists. this ensures lightdm succeeds when calling /org/freedesktop/AccountsServices ListCachedUsers + # lightdm greeters get the login users from lightdm which gets it from org.freedesktop.Accounts.ListCachedUsers. + # this requires the user we want to login as to be cached. + displayManager.job.preStart = '' + ${pkgs.systemd}/bin/busctl call org.freedesktop.Accounts /org/freedesktop/Accounts org.freedesktop.Accounts CacheUser s colin + ''; + }; + + services.greetd = lib.mkIf (cfg.greeter == "sway") { + enable = true; + # borrowed from gui/sway + settings.default_settings.command = + let + # start sway and have it construct the gtkgreeter + sway-as-greeter = pkgs.writeShellScriptBin "sway-as-greeter" '' + ${pkgs.sway}/bin/sway --debug --config ${sway-config-into-gtkgreet} > /var/log/sway/sway-as-greeter.log 2>&1 + ''; + # (config file for the above) + sway-config-into-gtkgreet = pkgs.writeText "greetd-sway-config" '' + exec "${gtkgreet-launcher}" + ''; + # gtkgreet which launches a layered sway instance + gtkgreet-launcher = pkgs.writeShellScript "gtkgreet-launcher" '' + # NB: the "command" field here is run in the user's shell. + # so that command must exist on the specific user's path who is logging in. it doesn't need to exist system-wide. + ${pkgs.greetd.gtkgreet}/bin/gtkgreet --layer-shell --command sway-launcher + ''; + in "${sway-as-greeter}/bin/sway-as-greeter"; + }; + + sane.fs."/var/log/sway" = lib.mkIf (cfg.greeter == "sway") { + dir.acl.mode = "0777"; + wantedBeforeBy = [ "greetd.service" "display-manager.service" ]; + }; + + # services.xserver.windowManager.session = [{ + # name = "sxmo"; + # desktopNames = [ "sxmo" ]; + # start = '' + # ${pkgs.sxmo-utils}/bin/sxmo_xinit.sh & + # waitPID=$! + # ''; + # }]; + # services.xserver.enable = true; + + # services.greetd = { + # enable = true; + # settings = { + # default_session = { + # command = "${pkgs.sxmo-utils}/bin/sxmo_winit.sh"; + # user = "colin"; + # }; + # }; + # }; }) ]; }