1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9
10 cfg = config.programs.mosh;
11
12in
13{
14 options.programs.mosh = {
15 enable = lib.mkEnableOption "mosh";
16 package = lib.mkPackageOption pkgs "mosh" { };
17 openFirewall = lib.mkEnableOption "" // {
18 description = "Whether to automatically open the necessary ports in the firewall.";
19 default = true;
20 };
21 withUtempter = lib.mkEnableOption "" // {
22 description = ''
23 Whether to enable libutempter for mosh.
24
25 This is required so that mosh can write to /var/run/utmp (which can be queried with `who` to display currently connected user sessions).
26 Note, this will add a guid wrapper for the group utmp!
27 '';
28 default = true;
29 };
30 };
31
32 config = lib.mkIf cfg.enable {
33 environment.systemPackages = [ cfg.package ];
34 networking.firewall.allowedUDPPortRanges = lib.optional cfg.openFirewall {
35 from = 60000;
36 to = 61000;
37 };
38 security.wrappers = lib.mkIf cfg.withUtempter {
39 utempter = {
40 source = "${pkgs.libutempter}/lib/utempter/utempter";
41 owner = "root";
42 group = "utmp";
43 setuid = false;
44 setgid = true;
45 };
46 };
47 };
48}