2020-02-19 20:43:48 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.cage;
|
|
|
|
in {
|
2024-04-13 14:54:15 +02:00
|
|
|
options.services.cage.enable = mkEnableOption "cage kiosk service";
|
2020-02-19 20:43:48 +01:00
|
|
|
|
|
|
|
options.services.cage.user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "demo";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2020-02-19 20:43:48 +01:00
|
|
|
User to log-in as.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
options.services.cage.extraArguments = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression "[]";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "Additional command line arguments to pass to Cage.";
|
2020-02-19 20:43:48 +01:00
|
|
|
example = ["-d"];
|
|
|
|
};
|
|
|
|
|
2023-05-28 19:10:56 +02:00
|
|
|
options.services.cage.environment = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
|
|
|
example = {
|
|
|
|
WLR_LIBINPUT_NO_DEVICES = "1";
|
|
|
|
};
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "Additional environment variables to pass to Cage.";
|
2023-05-28 19:10:56 +02:00
|
|
|
};
|
|
|
|
|
2020-02-19 20:43:48 +01:00
|
|
|
options.services.cage.program = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "${pkgs.xterm}/bin/xterm";
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression ''"''${pkgs.xterm}/bin/xterm"'';
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2020-02-19 20:43:48 +01:00
|
|
|
Program to run in cage.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
# The service is partially based off of the one provided in the
|
|
|
|
# cage wiki at
|
|
|
|
# https://github.com/Hjdskes/cage/wiki/Starting-Cage-on-boot-with-systemd.
|
|
|
|
systemd.services."cage-tty1" = {
|
|
|
|
enable = true;
|
|
|
|
after = [
|
|
|
|
"systemd-user-sessions.service"
|
|
|
|
"plymouth-start.service"
|
|
|
|
"plymouth-quit.service"
|
|
|
|
"systemd-logind.service"
|
|
|
|
"getty@tty1.service"
|
|
|
|
];
|
|
|
|
before = [ "graphical.target" ];
|
|
|
|
wants = [ "dbus.socket" "systemd-logind.service" "plymouth-quit.service"];
|
|
|
|
wantedBy = [ "graphical.target" ];
|
|
|
|
conflicts = [ "getty@tty1.service" ];
|
|
|
|
|
|
|
|
restartIfChanged = false;
|
2020-03-09 00:47:49 +01:00
|
|
|
unitConfig.ConditionPathExists = "/dev/tty1";
|
2020-02-19 20:43:48 +01:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.cage}/bin/cage \
|
|
|
|
${escapeShellArgs cfg.extraArguments} \
|
|
|
|
-- ${cfg.program}
|
|
|
|
'';
|
|
|
|
User = cfg.user;
|
|
|
|
|
|
|
|
IgnoreSIGPIPE = "no";
|
|
|
|
|
|
|
|
# Log this user with utmp, letting it show up with commands 'w' and
|
|
|
|
# 'who'. This is needed since we replace (a)getty.
|
|
|
|
UtmpIdentifier = "%n";
|
|
|
|
UtmpMode = "user";
|
|
|
|
# A virtual terminal is needed.
|
|
|
|
TTYPath = "/dev/tty1";
|
|
|
|
TTYReset = "yes";
|
|
|
|
TTYVHangup = "yes";
|
|
|
|
TTYVTDisallocate = "yes";
|
|
|
|
# Fail to start if not controlling the virtual terminal.
|
|
|
|
StandardInput = "tty-fail";
|
2021-12-16 18:50:42 +01:00
|
|
|
StandardOutput = "journal";
|
|
|
|
StandardError = "journal";
|
2020-02-19 20:43:48 +01:00
|
|
|
# Set up a full (custom) user session for the user, required by Cage.
|
|
|
|
PAMName = "cage";
|
|
|
|
};
|
2023-05-28 19:10:56 +02:00
|
|
|
environment = cfg.environment;
|
2020-02-19 20:43:48 +01:00
|
|
|
};
|
|
|
|
|
2022-01-26 23:04:24 +01:00
|
|
|
security.polkit.enable = true;
|
|
|
|
|
2020-02-19 20:43:48 +01:00
|
|
|
security.pam.services.cage.text = ''
|
|
|
|
auth required pam_unix.so nullok
|
|
|
|
account required pam_unix.so
|
|
|
|
session required pam_unix.so
|
2021-07-28 06:28:25 +02:00
|
|
|
session required pam_env.so conffile=/etc/pam/environment readenv=0
|
2022-05-05 13:23:32 +02:00
|
|
|
session required ${config.systemd.package}/lib/security/pam_systemd.so
|
2020-02-19 20:43:48 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
hardware.opengl.enable = mkDefault true;
|
|
|
|
|
|
|
|
systemd.targets.graphical.wants = [ "cage-tty1.service" ];
|
|
|
|
|
|
|
|
systemd.defaultUnit = "graphical.target";
|
|
|
|
};
|
|
|
|
|
2021-04-29 18:07:13 +02:00
|
|
|
meta.maintainers = with lib.maintainers; [ matthewbauer ];
|
2020-02-19 20:43:48 +01:00
|
|
|
|
|
|
|
}
|