nix-files/hosts/modules/gui/sxmo/default.nix

333 lines
12 KiB
Nix
Raw Normal View History

2023-05-16 11:09:57 +00:00
# this work derives from noneucat's sxmo service/packages, found via NUR
# - <repo:nix-community/nur-combined:repos/noneucat/modules/pinephone/sxmo.nix>
2023-05-17 06:58:37 +00:00
# other nix works:
# - <https://github.com/wentam/sxmo-nix>
2023-05-17 10:18:11 +00:00
# - implements sxmo atop tinydm (also packaged by wentam)
# - wentam cleans up sxmo-utils to be sealed. also patches to use systemd poweroff, etc
# - packages a handful of anjan and proycon utilities
# - packages <https://gitlab.com/kop316/mmsd/>
# - packages <https://gitlab.com/kop316/vvmd/>
2023-05-17 06:58:37 +00:00
# - <https://github.com/chuangzhu/nixpkgs-sxmo>
2023-05-17 10:18:11 +00:00
# - implements sxmo as a direct systemd service -- apparently no DM
# - packages sxmo-utils
# - injects PATH into each script
# - perhaps sxmo-utils is best packaged via the `resholve` shell solver?
#
# sxmo documentation:
# - <repo:anjan/sxmo-docs-next>
#
# sxmo technical overview:
# - inputs
# - dwm: handles vol/power buttons; hardcoded in config.h
# - lisgd: handles gestures
# - startup
# - daemon based (lisgsd, idle_locker, statusbar_periodics)
# - auto-started at login
# - managable by `sxmo_daemons.sh`
# - list available daemons: `sxmo_daemons.sh list`
# - query if a daemon is active: `sxmo_daemons.sh running <my-daemon>`
# - start daemon: `sxmo_daemons.sh start <my-daemon>`
2023-05-17 06:58:37 +00:00
# - managable by `superctl`
# - `superctl status`
# - user hooks:
# - live in ~/.config/sxmo/hooks/
# - logs:
# - live in ~/.local/state/sxmo.log
2023-05-17 06:58:37 +00:00
# - ~/.local/state/superd.log
# - ~/.local/state/superd/logs/<daemon>.log
# - `journalctl --user --boot` (lightm redirects the sxmo session stdout => systemd)
#
# - default components:
# - DE: sway (if wayland), dwm (if X)
# - menus: bemenu (if wayland), dmenu (if X)
# - gestures: lisgd
# - on-screen keyboard: wvkbd (if wayland), svkbd (if X)
#
2023-07-13 00:40:52 +00:00
{ config, lib, pkgs, sane-lib, ... }:
2023-05-16 11:09:57 +00:00
let
2023-05-17 06:58:37 +00:00
cfg = config.sane.gui.sxmo;
knownKeyboards = {
# map keyboard package name -> name of binary to invoke
wvkbd = "wvkbd-mobintl";
svkbd = "svkbd-mobile-intl";
};
knownTerminals = {
vte = "vte-2.91";
};
2023-05-16 11:09:57 +00:00
in
{
options = with lib; {
2023-05-16 11:09:57 +00:00
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.
'';
};
2023-06-23 08:38:23 +00:00
sane.gui.sxmo.package = mkOption {
type = types.package;
default = pkgs.sxmo-utils;
2023-05-17 06:58:37 +00:00
description = ''
sxmo base scripts and hooks collection.
consider overriding the outputs under /share/sxmo/default_hooks
to insert your own user scripts.
2023-05-17 06:58:37 +00:00
'';
};
sane.gui.sxmo.terminal = mkOption {
2023-05-18 11:10:28 +00:00
# type = types.nullOr (types.enum [ "foot" "st" "vte" ]);
type = types.nullOr types.str;
default = "foot";
2023-05-17 06:58:37 +00:00
description = ''
2023-05-18 11:10:28 +00:00
name of terminal to use for sxmo_terminal.sh.
foot, st, and vte have special integrations in sxmo, but any will work.
2023-05-17 06:58:37 +00:00
'';
};
2023-05-24 06:06:16 +00:00
sane.gui.sxmo.keyboard = mkOption {
# type = types.nullOr (types.enum ["wvkbd"])
type = types.nullOr types.str;
2023-05-24 06:06:16 +00:00
default = "wvkbd";
description = ''
name of on-screen-keyboard to use for sxmo_keyboard.sh.
this sets the KEYBOARD environment variable.
see also: KEYBOARD_ARGS.
'';
};
sane.gui.sxmo.settings = mkOption {
description = ''
environment variables used to configure sxmo.
e.g. SXMO_UNLOCK_IDLE_TIME or SXMO_VOLUME_BUTTON.
'';
type = types.submodule {
freeformType = types.attrsOf types.str;
options =
let
mkSettingsOpt = default: description: mkOption {
inherit default description;
type = types.nullOr types.str;
};
in {
SXMO_BAR_SHOW_BAT_PER = mkSettingsOpt "1" "show battery percentage in statusbar";
SXMO_UNLOCK_IDLE_TIME = mkSettingsOpt "300" "how many seconds of inactivity before locking the screen"; # lock -> screenoff happens 8s later, not configurable
};
};
default = {};
};
sane.gui.sxmo.noidle = mkOption {
type = types.bool;
default = false;
description = "inhibit lock-on-idle and screenoff-on-idle";
};
2023-05-16 11:09:57 +00:00
};
config = lib.mkMerge [
2023-05-16 11:09:57 +00:00
{
sane.programs.sxmoApps = {
package = null;
suggestedPrograms = [
"guiApps"
"sfeed" # want this here so that the user's ~/.sfeed/sfeedrc gets created
2023-07-13 01:33:05 +00:00
"superd" # make superctl (used by sxmo) be on PATH
2023-05-16 11:09:57 +00:00
];
persist.cryptClearOnBoot = [
# builds to be 10's of MB per day
".local/state/superd/logs"
];
2023-05-16 11:09:57 +00:00
};
}
{
# TODO: lift to option declaration
sane.gui.sxmo.settings.TERMCMD = lib.mkIf (cfg.terminal != null)
(lib.mkDefault (knownTerminals."${cfg.terminal}" or cfg.terminal));
sane.gui.sxmo.settings.KEYBOARD = lib.mkIf (cfg.keyboard != null)
(lib.mkDefault (knownKeyboards."${cfg.keyboard}" or cfg.keyboard));
}
(lib.mkIf cfg.enable (lib.mkMerge [
{
sane.programs.sxmoApps.enableFor.user.colin = true;
sane.gui.gtk.enable = lib.mkDefault true;
2023-05-16 11:09:57 +00:00
# some programs (e.g. fractal/nheko) **require** a "Secret Service Provider"
services.gnome.gnome-keyring.enable = true;
networking.useDHCP = false;
networking.networkmanager.enable = true;
networking.wireless.enable = lib.mkForce false;
2023-05-16 11:09:57 +00:00
hardware.bluetooth.enable = true;
services.blueman.enable = true;
2023-05-16 11:09:57 +00:00
# sxmo internally uses doas instead of sudo
security.doas.enable = true;
security.doas.wheelNeedsPassword = false;
# TODO: nerdfonts is 4GB. it accepts an option to ship only some fonts: probably want to use that.
fonts.fonts = [ pkgs.nerdfonts ];
# 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" ];
2023-05-19 08:04:05 +00:00
# TODO: could use `displayManager.sessionPackages`?
environment.systemPackages = [
cfg.package
] ++ lib.optionals (cfg.terminal != null) [ pkgs."${cfg.terminal}" ]
++ lib.optionals (cfg.keyboard != null) [ pkgs."${cfg.keyboard}" ];
2023-05-19 08:03:51 +00:00
environment.sessionVariables = {
XDG_DATA_DIRS = [
# TODO: only need the share/sxmo directly linked
"${cfg.package}/share"
];
};
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" ];
};
2023-07-12 10:03:58 +00:00
# lightdm-mobile-greeter: "The name org.a11y.Bus was not provided by any .service files"
services.gnome.at-spi2-core.enable = true;
2023-07-12 10:03:58 +00:00
sane.user.fs.".cache/sxmo/sxmo.noidle" = lib.mkIf cfg.noidle (sane-lib.fs.wantedText "");
sane.user.fs.".config/sxmo/profile".symlink.text = let
mkKeyValue = key: value: ''export ${key}="${value}"'';
userConfig = lib.generators.toKeyValue { inherit mkKeyValue; } cfg.settings;
in ''
# configversion: 4284f96d91e9550ff8f3b25823e402ad
# ^ upstream adds new options every now and then, expects user config file
# to include the md5sum of the template it's based on.
# see `setup_config_version.sh`
${userConfig}
'';
2023-07-12 10:03:58 +00:00
sane.user.fs.".config/sxmo/sway".symlink.target = pkgs.substituteAll {
src = ./sway-config;
waybar = "${pkgs.waybar}/bin/waybar";
2023-07-13 00:40:52 +00:00
};
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;
# sane.user.fs.".config/waybar/style.css".symlink.text =
# builtins.readFile ./waybar-style.css;
sane.user.fs.".config/sxmo/conky.conf".symlink.target = let
battery_estimate = pkgs.static-nix-shell.mkBash {
pname = "battery_estimate";
src = ./.;
};
in pkgs.substituteAll {
src = ./conky-config;
bat = "${battery_estimate}/bin/battery_estimate";
};
}
(lib.mkIf (cfg.greeter == "lightdm-mobile") {
sane.persist.sys.plaintext = [
# this takes up 4-5 MB of fontconfig and mesa shader caches.
# it could optionally be cleared on boot.
{ path = "/var/lib/lightdm"; user = "lightdm"; group = "lightdm"; mode = "0770"; }
];
services.xserver = {
enable = true;
displayManager.lightdm.enable = true;
displayManager.lightdm.greeters.mobile.enable = true;
displayManager.lightdm.extraSeatDefaults = ''
user-session = swmo
'';
displayManager.sessionPackages = with pkgs; [
cfg.package # this gets share/wayland-sessions/swmo.desktop linked
];
# 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
'';
};
})
(lib.mkIf (cfg.greeter == "sway") {
services.greetd = {
enable = true;
# borrowed from gui/sway
settings.default_session.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 sxmo_winit.sh
'';
in "${sway-as-greeter}/bin/sway-as-greeter";
};
sane.fs."/var/log/sway" = {
dir.acl.mode = "0777";
wantedBeforeBy = [ "greetd.service" "display-manager.service" ];
};
})
# old, greeterless options:
# services.xserver.windowManager.session = [{
# name = "sxmo";
# desktopNames = [ "sxmo" ];
# start = ''
2023-06-23 08:38:23 +00:00
# ${cfg.package}/bin/sxmo_xinit.sh &
# waitPID=$!
# '';
# }];
# services.xserver.enable = true;
# services.greetd = {
# enable = true;
# settings = {
# default_session = {
2023-06-23 08:38:23 +00:00
# command = "${cfg.package}/bin/sxmo_winit.sh";
# user = "colin";
# };
# };
# };
]))
2023-05-16 11:09:57 +00:00
];
}