summary refs log tree commit diff
path: root/nixos/modules/services/x11/desktop-managers/surf-display.nix
blob: 4b5a04f988ba984b12ac8156b221fbc4c93408a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.xserver.desktopManager.surf-display;

  surfDisplayConf = ''
    # Surf Kiosk Display: Wrap around surf browser and turn your
    # system into a browser screen in KIOSK-mode.

    # default download URI for all display screens if not configured individually
    DEFAULT_WWW_URI="${cfg.defaultWwwUri}"

    # Enforce fixed resolution for all displays (default: not set):
    #DEFAULT_RESOLUTION="1920x1080"

    # HTTP proxy URL, if needed (default: not set).
    #HTTP_PROXY_URL="http://webcache:3128"

    # Setting for internal inactivity timer to restart surf-display
    # if the user goes inactive/idle.
    INACTIVITY_INTERVAL="${builtins.toString cfg.inactivityInterval}"

    # log to syslog instead of .xsession-errors
    LOG_TO_SYSLOG="yes"

    # Launch pulseaudio daemon if not already running.
    WITH_PULSEAUDIO="yes"

    # screensaver settings, see "man 1 xset" for possible options
    SCREENSAVER_SETTINGS="${cfg.screensaverSettings}"

    # disable right and middle pointer device click in browser sessions while keeping
    # scrolling wheels' functionality intact... (consider "pointer" subcommand on
    # xmodmap man page for details).
    POINTER_BUTTON_MAP="${cfg.pointerButtonMap}"

    # Hide idle mouse pointer.
    HIDE_IDLE_POINTER="${cfg.hideIdlePointer}"

    ${cfg.extraConfig}
  '';

in {
  options = {
    services.xserver.desktopManager.surf-display = {
      enable = mkEnableOption "surf-display as a kiosk browser session";

      defaultWwwUri = mkOption {
        type = types.str;
        default = "${pkgs.surf-display}/share/surf-display/empty-page.html";
        defaultText = literalExpression ''"''${pkgs.surf-display}/share/surf-display/empty-page.html"'';
        example = "https://www.example.com/";
        description = "Default URI to display.";
      };

      inactivityInterval = mkOption {
        type = types.int;
        default = 300;
        example = 0;
        description = ''
          Setting for internal inactivity timer to restart surf-display if the
          user goes inactive/idle to get a fresh session for the next user of
          the kiosk.

          If this value is set to zero, the whole feature of restarting due to
          inactivity is disabled.
        '';
      };

      screensaverSettings = mkOption {
        type = types.separatedString " ";
        default = "";
        description = ''
          Screensaver settings, see <literal>man 1 xset</literal> for possible options.
        '';
      };

      pointerButtonMap = mkOption {
        type = types.str;
        default = "1 0 0 4 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0";
        description = ''
          Disable right and middle pointer device click in browser sessions
          while keeping scrolling wheels' functionality intact. See pointer
          subcommand on <literal>man xmodmap</literal> for details.
        '';
      };

      hideIdlePointer = mkOption {
        type = types.str;
        default = "yes";
        example = "no";
        description = "Hide idle mouse pointer.";
      };

      extraConfig = mkOption {
        type = types.lines;
        default = "";
        example = ''
          # Enforce fixed resolution for all displays (default: not set):
          DEFAULT_RESOLUTION="1920x1080"

          # HTTP proxy URL, if needed (default: not set).
          HTTP_PROXY_URL="http://webcache:3128"

          # Configure individual display screens with host specific parameters:
          DISPLAYS['display-host-0']="www_uri=https://www.displayserver.comany.net/display-1/index.html"
          DISPLAYS['display-host-1']="www_uri=https://www.displayserver.comany.net/display-2/index.html"
          DISPLAYS['display-host-2']="www_uri=https://www.displayserver.comany.net/display-3/index.html|res=1920x1280"
          DISPLAYS['display-host-3']="www_uri=https://www.displayserver.comany.net/display-4/index.html"|res=1280x1024"
          DISPLAYS['display-host-local-file']="www_uri=file:///usr/share/doc/surf-display/empty-page.html"
        '';
        description = ''
          Extra configuration options to append to <literal>/etc/default/surf-display</literal>.
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    services.xserver.displayManager.sessionPackages = [
      pkgs.surf-display
    ];

    environment.etc."default/surf-display".text = surfDisplayConf;
  };
}