2021-05-03 20:48:10 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2022-05-18 14:49:53 +00:00
|
|
|
cfg = config.services.xserver.desktopManager.phosh;
|
2021-05-03 20:48:10 +00:00
|
|
|
|
|
|
|
# Based on https://source.puri.sm/Librem5/librem5-base/-/blob/4596c1056dd75ac7f043aede07887990fd46f572/default/sm.puri.OSK0.desktop
|
|
|
|
oskItem = pkgs.makeDesktopItem {
|
|
|
|
name = "sm.puri.OSK0";
|
|
|
|
desktopName = "On-screen keyboard";
|
|
|
|
exec = "${pkgs.squeekboard}/bin/squeekboard";
|
2022-03-05 16:20:37 +00:00
|
|
|
categories = [ "GNOME" "Core" ];
|
|
|
|
onlyShowIn = [ "GNOME" ];
|
|
|
|
noDisplay = true;
|
|
|
|
extraConfig = {
|
|
|
|
X-GNOME-Autostart-Phase = "Panel";
|
|
|
|
X-GNOME-Provides = "inputmethod";
|
|
|
|
X-GNOME-Autostart-Notify = "true";
|
|
|
|
X-GNOME-AutoRestart = "true";
|
|
|
|
};
|
2021-05-03 20:48:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
phocConfigType = types.submodule {
|
|
|
|
options = {
|
|
|
|
xwayland = mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-05-03 20:48:10 +00:00
|
|
|
Whether to enable XWayland support.
|
|
|
|
|
|
|
|
To start XWayland immediately, use `immediate`.
|
|
|
|
'';
|
|
|
|
type = types.enum [ "true" "false" "immediate" ];
|
|
|
|
default = "false";
|
|
|
|
};
|
|
|
|
cursorTheme = mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-05-03 20:48:10 +00:00
|
|
|
Cursor theme to use in Phosh.
|
|
|
|
'';
|
|
|
|
type = types.str;
|
|
|
|
default = "default";
|
|
|
|
};
|
|
|
|
outputs = mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-05-03 20:48:10 +00:00
|
|
|
Output configurations.
|
|
|
|
'';
|
|
|
|
type = types.attrsOf phocOutputType;
|
|
|
|
default = {
|
|
|
|
DSI-1 = {
|
|
|
|
scale = 2;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
phocOutputType = types.submodule {
|
|
|
|
options = {
|
|
|
|
modeline = mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-05-03 20:48:10 +00:00
|
|
|
One or more modelines.
|
|
|
|
'';
|
|
|
|
type = types.either types.str (types.listOf types.str);
|
|
|
|
default = [];
|
|
|
|
example = [
|
|
|
|
"87.25 720 776 848 976 1440 1443 1453 1493 -hsync +vsync"
|
|
|
|
"65.13 768 816 896 1024 1024 1025 1028 1060 -HSync +VSync"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
mode = mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-05-03 20:48:10 +00:00
|
|
|
Default video mode.
|
|
|
|
'';
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "768x1024";
|
|
|
|
};
|
|
|
|
scale = mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-05-03 20:48:10 +00:00
|
|
|
Display scaling factor.
|
|
|
|
'';
|
2022-06-16 17:23:12 +00:00
|
|
|
type = types.nullOr (
|
|
|
|
types.addCheck
|
|
|
|
(types.either types.int types.float)
|
|
|
|
(x : x > 0)
|
|
|
|
) // {
|
|
|
|
description = "null or positive integer or float";
|
|
|
|
};
|
2021-05-03 20:48:10 +00:00
|
|
|
default = null;
|
|
|
|
example = 2;
|
|
|
|
};
|
|
|
|
rotate = mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-05-03 20:48:10 +00:00
|
|
|
Screen transformation.
|
|
|
|
'';
|
|
|
|
type = types.enum [
|
|
|
|
"90" "180" "270" "flipped" "flipped-90" "flipped-180" "flipped-270" null
|
|
|
|
];
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
optionalKV = k: v: optionalString (v != null) "${k} = ${builtins.toString v}";
|
2021-05-03 20:48:10 +00:00
|
|
|
|
|
|
|
renderPhocOutput = name: output: let
|
|
|
|
modelines = if builtins.isList output.modeline
|
|
|
|
then output.modeline
|
|
|
|
else [ output.modeline ];
|
|
|
|
renderModeline = l: "modeline = ${l}";
|
|
|
|
in ''
|
|
|
|
[output:${name}]
|
|
|
|
${concatStringsSep "\n" (map renderModeline modelines)}
|
|
|
|
${optionalKV "mode" output.mode}
|
|
|
|
${optionalKV "scale" output.scale}
|
|
|
|
${optionalKV "rotate" output.rotate}
|
|
|
|
'';
|
|
|
|
|
|
|
|
renderPhocConfig = phoc: let
|
|
|
|
outputs = mapAttrsToList renderPhocOutput phoc.outputs;
|
|
|
|
in ''
|
|
|
|
[core]
|
|
|
|
xwayland = ${phoc.xwayland}
|
|
|
|
${concatStringsSep "\n" outputs}
|
|
|
|
[cursor]
|
|
|
|
theme = ${phoc.cursorTheme}
|
|
|
|
'';
|
2022-05-18 14:49:53 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2021-05-03 20:48:10 +00:00
|
|
|
options = {
|
2022-05-18 14:49:53 +00:00
|
|
|
services.xserver.desktopManager.phosh = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Enable the Phone Shell.";
|
2022-05-18 14:49:53 +00:00
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "phosh" { };
|
2022-05-18 14:49:53 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "The user to run the Phosh service.";
|
2022-05-18 14:49:53 +00:00
|
|
|
type = types.str;
|
|
|
|
example = "alice";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "The group to run the Phosh service.";
|
2022-05-18 14:49:53 +00:00
|
|
|
type = types.str;
|
|
|
|
example = "users";
|
|
|
|
};
|
|
|
|
|
2021-05-03 20:48:10 +00:00
|
|
|
phocConfig = mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-05-03 20:48:10 +00:00
|
|
|
Configurations for the Phoc compositor.
|
|
|
|
'';
|
|
|
|
type = types.oneOf [ types.lines types.path phocConfigType ];
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2022-05-18 14:49:53 +00:00
|
|
|
systemd.defaultUnit = "graphical.target";
|
|
|
|
# Inspired by https://gitlab.gnome.org/World/Phosh/phosh/-/blob/main/data/phosh.service
|
|
|
|
systemd.services.phosh = {
|
|
|
|
wantedBy = [ "graphical.target" ];
|
|
|
|
serviceConfig = {
|
2023-03-15 16:39:30 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/phosh-session";
|
2022-05-18 14:49:53 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
PAMName = "login";
|
|
|
|
WorkingDirectory = "~";
|
|
|
|
Restart = "always";
|
|
|
|
|
|
|
|
TTYPath = "/dev/tty7";
|
|
|
|
TTYReset = "yes";
|
|
|
|
TTYVHangup = "yes";
|
|
|
|
TTYVTDisallocate = "yes";
|
|
|
|
|
|
|
|
# Fail to start if not controlling the tty.
|
|
|
|
StandardInput = "tty-fail";
|
|
|
|
StandardOutput = "journal";
|
|
|
|
StandardError = "journal";
|
|
|
|
|
|
|
|
# Log this user with utmp, letting it show up with commands 'w' and 'who'.
|
|
|
|
UtmpIdentifier = "tty7";
|
|
|
|
UtmpMode = "user";
|
|
|
|
};
|
2024-02-29 20:09:43 +00:00
|
|
|
environment = {
|
|
|
|
# We are running without a display manager, so need to provide
|
|
|
|
# a value for XDG_CURRENT_DESKTOP.
|
|
|
|
#
|
|
|
|
# Among other things, this variable influences:
|
|
|
|
# - visibility of desktop entries with "OnlyShowIn=Phosh;"
|
|
|
|
# https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.5.html#key-onlyshowin
|
|
|
|
# - the chosen xdg-desktop-portal configuration.
|
|
|
|
# https://flatpak.github.io/xdg-desktop-portal/docs/portals.conf.html
|
|
|
|
XDG_CURRENT_DESKTOP = "Phosh:GNOME";
|
|
|
|
# pam_systemd uses these to identify the session in logind.
|
|
|
|
# https://www.freedesktop.org/software/systemd/man/latest/pam_systemd.html#desktop=
|
|
|
|
XDG_SESSION_DESKTOP = "phosh";
|
|
|
|
XDG_SESSION_TYPE = "wayland";
|
|
|
|
};
|
2022-05-18 14:49:53 +00:00
|
|
|
};
|
|
|
|
|
2021-05-03 20:48:10 +00:00
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.phoc
|
2022-05-18 14:49:53 +00:00
|
|
|
cfg.package
|
2021-05-03 20:48:10 +00:00
|
|
|
pkgs.squeekboard
|
|
|
|
oskItem
|
|
|
|
];
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
systemd.packages = [ cfg.package ];
|
2021-06-28 23:13:55 +00:00
|
|
|
|
2021-05-03 20:48:10 +00:00
|
|
|
programs.feedbackd.enable = true;
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
security.pam.services.phosh = {};
|
2021-05-03 20:48:10 +00:00
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
hardware.graphics.enable = mkDefault true;
|
2021-06-28 23:13:55 +00:00
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
services.gnome.core-shell.enable = true;
|
|
|
|
services.gnome.core-os-services.enable = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
services.displayManager.sessionPackages = [ cfg.package ];
|
2021-05-03 20:48:10 +00:00
|
|
|
|
|
|
|
environment.etc."phosh/phoc.ini".source =
|
|
|
|
if builtins.isPath cfg.phocConfig then cfg.phocConfig
|
|
|
|
else if builtins.isString cfg.phocConfig then pkgs.writeText "phoc.ini" cfg.phocConfig
|
|
|
|
else pkgs.writeText "phoc.ini" (renderPhocConfig cfg.phocConfig);
|
|
|
|
};
|
|
|
|
}
|